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
我想高手解决一下 请大家为我出谋划策!谢谢!