我正在尝试创建vb.net程序,以便使用串口从秤中获取数据。
我不知道比例模型,只是显示模型:IND231。
问题是我得到了愚蠢的数据:
但是如果打开Putty我会得到这个:
正如你在腻子中看到的那样,每一秒只有一条线刷新,真正的重量是前两个00(中间),在我的情况下这条线不令人耳目一新,但是在5-10秒后做出一条巨大的线,我的程序崩溃了。
我的程序代码是:
Imports AxSerial
Public Class Form1
Dim Q As Queue(Of String) = New Queue(Of String)
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
For Each s In System.IO.Ports.SerialPort.GetPortNames()
lstPorts.Items.Add(s)
Next s
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnStart.Click
Try
If lstPorts.SelectedIndex = -1 Then
MsgBox("Please select a port")
Exit Sub
Else
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = 1
SerialPort1.RtsEnable = False
SerialPort1.PortName = lstPorts.SelectedItem.ToString
SerialPort1.Open()
Timer1.Start()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object,
ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
Handles SerialPort1.DataReceived
Q.Enqueue(SerialPort1.ReadExisting())
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Timer1.Tick
SyncLock Q
While Q.Count > 0
txtReceived.Text &= Q.Dequeue
End While
End SyncLock
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnStop.Click
SerialPort1.Close()
Timer1.Stop()
End Sub
End Class
这是IND321串行端口参数
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = IO.Ports.Parity.None
SerialPort1.StopBits = 1
SerialPort1.RtsEnable = False
我不确定RtsEnable,我认为这是FlowControl。
我需要纠正以获取像putty这样的数据吗?
答案 0 :(得分:0)
您的扩展/串行端口看起来像是以其他格式返回数据。 检查您的比例规格。它可能是e72或其他一些偶数/奇数/位/奇偶校验组合。