| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 581 人关注过本帖
标题:vb与vb.net之间的端口连接转换
只看楼主 加入收藏
lccj2010
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-9-10
收藏
 问题点数:0 回复次数:0 
vb与vb.net之间的端口连接转换
我用vb写了一个应用程序可以与一台机器连接源代码:
Private Sub cmdEquipAddr_Click()
    Dim i As Integer
    i = Open_Port(cmbPort.ListIndex)
    i = Close_Port(cmbPort.ListIndex)
   
    i = Open_Port(cmbPort.ListIndex)
    i = ReadSerialNum(cmbPort.ListIndex, SerialNum)
    i = Close_Port(cmbPort.ListIndex)
    If SerialNum <> 0 Then
        txtEquipAddr.Text = SerialNum
        Identify_ID.Enabled = True
        Setpara.Enabled = True
        readpara.Enabled = True
        txtRcvDis.Text = txtRcvDis.Text & vbCrLf & "读取成功!"
    Else
        txtRcvDis.Text = txtRcvDis.Text & vbCrLf & "读取失败!"
    End If
End Sub
然后我想用实现编写代码为:
  Public Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
        Dim i As Integer
        i = Open_Port(listbox1.Text)
        i = Close_Port(listbox1.Text)

        i = Open_Port(listbox1.Text)
        i = ReadSerialNum(listbox1.Text, SerialNum)
        i = Close_Port(listbox1.Text)
        If SerialNum <> 0 Then
           
            TextBox1.Text = TextBox1.Text & vbCrLf & "读取成功!"
        Else
            TextBox1.Text = TextBox1.Text & vbCrLf & "读取失败!"
        End If
   
      
    End Sub
问题出现了   系统提示:  用户代码为处理 未将对象引用设置到对象的实例
附加内容:
一个调用的dll的源码:
 Public Declare Function Open_Port Lib ".\Comm.dll" _
     (ByVal serial_port As Byte) As Integer
    Public Declare Function Close_Port Lib ".\Comm.dll" _
    (ByVal serial_port As Byte) As Integer


    Public Declare Function Close_Port1 Lib ".\Comm.dll" _
    (ByVal serial_port As Long) As Integer
    Public Declare Function Send_Data Lib ".\Comm.dll" _
    (ByVal str As String, ByVal serial_port As Long) As Integer

    Public Declare Function Send_Data Lib ".\Comm.dll" _
    (ByVal serial_port As Byte, ByRef strbuf As Byte, ByVal serial_port As Long) As Integer
    Public Declare Function Recv_Data Lib ".\Comm.dll" _
    (ByVal str As String, ByVal serial_port As Long) As Integer


    Public Declare Function Recv_Data Lib ".\Comm.dll" _
    (ByVal serial_port As Byte, ByRef strbuf As Byte, ByVal serial_port As Long) As Integer
    Public Declare Function Trans_Data Lib ".\Comm.dll" _
    (ByVal serial_port As Byte, ByRef strbuf As Byte, ByVal serial_port As Long, ByVal serial_port1 As Long) As Integer
    Declare Function ReadSerialNum Lib ".\Comm.dll" ()
    Public Declare Function Close_Port1 Lib ".\Comm.dll" _
 (ByVal serial_port As Byte, ByRef SerialNum As Long) As Long

    Public Declare Function Identify_6B Lib ".\Comm.dll" _
        (ByVal serial_port As Byte, ByVal SerialNum As Long, ByRef strbuf As Byte) As Long

    Public Declare Function Read_6B Lib ".\Comm.dll" _
        (ByVal serial_port As Byte, ByVal SerialNum As Long, ByRef strbuf As Byte, ByVal dataaddr As Byte, ByVal datalen As Byte) As Long

    Public Declare Function Write_6B Lib ".\Comm.dll" _
        (ByVal serial_port As Byte, ByVal SerialNum As Long, ByRef strbuf As Byte, ByVal dataaddr As Byte, ByVal datalen As Byte, ByRef data As Byte) As Long

    Public Declare Function Identify_6C Lib ".\Comm.dll" _
        (ByVal serial_port As Byte, ByVal SerialNum As Long, ByRef strbuf As Byte) As Long

    Public Declare Function Read_6C Lib ".\Comm.dll" _
        (ByVal serial_port As Byte, ByVal SerialNum As Long, ByRef strbuf As Byte, ByVal datamem As Byte, ByVal dataaddr As Byte, ByVal datalen As Byte) As Long

    Public Declare Function Write_6C Lib ".\Comm.dll" _
        (ByVal serial_port As Byte, ByVal SerialNum As Long, ByRef strbuf As Byte, ByVal datamem As Byte, ByVal dataaddr As Byte, ByVal datalen As Byte, ByRef data As Byte) As Long

    Public Declare Function SettingPara Lib "Comm.dll" _
(ByVal serial_port As Byte, ByVal SerialNum As Long, ByRef strbuf As Byte, ByRef data As Byte, ByVal datalen As Byte) As Long

    Public Declare Function GettingPara Lib "Comm.dll" _
(ByVal serial_port As Byte, ByVal SerialNum As Long, ByRef strbuf As Byte) As Long
End Class
我想高手解决一下  请大家为我出谋划策!谢谢!
   
搜索更多相关主题的帖子: 端口 
2010-09-10 20:51
快速回复:vb与vb.net之间的端口连接转换
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017131 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved