急???怎么测试SerialPort1_DataReceived得到数据?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SerialPort1.BaudRate = "9600" '波特率
SerialPort1.PortName = "COM1" '串口名称
SerialPort1.DataBits = 8 '数据位
SerialPort1.StopBits = IO.Ports.StopBits.One '停止位
SerialPort1.Parity = IO.Ports.Parity.None '校验位
SerialPort1.Open()
End Sub
'触发接收事件
Public Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
If SerialPort1.BytesToRead > 0 Then
Threading.Thread.Sleep(100) '添加的延时
strIncoming = SerialPort1.ReadExisting.ToString '读取缓冲区中的数据
SerialPort1.DiscardInBuffer()
test.Text = strIncoming
End If
End Sub
我是通过上面代码用串口想得到电子称上的数据...
我测试串口连接是已打开,当电子称上显示重量的时候,为什么不触发Public Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived 事件?
是不是串口中没有数据,该事件就不触发?
请问怎么来测试电子称上的数据是否已发送到串口中去啦?(数据连接先已测试没任何问题)
望指教? --------------------编程问答-------------------- 下载SSCOMM32.exe直接看看串口信息先。
补充:.NET技术 , VB.NET