我采用的是SerialPort控件,但是在接受数据是遇到一点问题。就是关于串口上面介个同步异步委托的部分。我的通信是发送指令A后几秒返回测试结果,这样的代码可以么?
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Dim n As Integer
Dim rxdata(2) As Byte
SerialPort1.PortName = "COM9"
n = Me.SerialPort1.BytesToRead
If (n > 0) Then ReDim rxdata(n - 1)
Me.SerialPort1.Read(rxdata, 0, n)
SerialPort1.Close()
End Sub