[VB2005] RS232 抓二筆值問題
各位前輩好ㄚ
目前因為課業所需而接觸VB2005
但有些問題解決不了
希望能給予一些解答的方向
問題如下:
目前想透過RS232抓取經由單晶片所傳的兩筆值
此兩筆值原為單晶片中的一筆10bit拆成兩筆而來
所以傳至VB時需再將兩筆合併
才能顯示單晶片中的原數值
目前程式可接收一筆
但兩筆則不行
也不知該如何下手了
程式如下:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Dim InByte() As Byte, ReadCount As Integer
Dim i As Integer, countValue As Long, ValueHigh As Long, ValueLow As
Long
If Button1.Text = "暫停" Then
If SerialPort1.BytesToRead > 0 Then
ReDim InByte(SerialPort1.BytesToRead - 1) '宣告陣列空間
''呼叫Read方法()
ReadCount = SerialPort1.Read(InByte, 0,
SerialPort1.BytesToRead)
If ReadCount > 0 Then
For Each bData As Byte In InByte
If i = 0 Then
ValueHigh = bData
i = 1
End If
If i = 1 Then
ValueLow = bData
i = 0
countValue = ValueHigh * 256 + ValueLow
Label1.Text = countValue
End If
Next
End If
Timer1.Interval = 100
End If
End If
End Sub
希望能給予一些方向或指正 謝謝~~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.125.10.105