作者dmlove (蓝瓶子)
看板Visual_Basic
标题[VB2005] RS232 抓二笔值问题
时间Tue Dec 30 00:32:13 2008
各位前辈好ㄚ
目前因为课业所需而接触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