这可能吗?检查端口是否打开是可以的,但我不知道为什么我发送数据后无法接收数据/字符串。
主要表格:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
connect_btn.Enabled = False
With com1
.PortName = "COM2"
.BaudRate = 9600
.Parity = Parity.None
.StopBits = StopBits.One
.DataBits = 8
.Handshake = Handshake.RequestToSend
.RtsEnable = True
.DtrEnable = True
End With
com1.Open()
AddHandler RFID.DataReceived, SerialDataReceivedEventHandler1
End Sub
发送数据:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim response As String = TextBox1.Text
If RFID.IsOpen Then
RFID.WriteLine(response)
End If
End Sub
数据接收:
Private Sub com1_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs)
If com1.IsOpen = True Then
read()
End If
End Sub
Friend Sub DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
Dim newReceivedData As String
newReceivedData = RFID.ReadExisting
MessageBox.Show(newReceivedData)
End Sub
当我尝试运行它时,没有错误。
EDITED
使用PuTTY和VSPE工作来发送数据。