求教vb串口通讯怎么使接收的数据存入到二维数组中?
具体就是从串口接收fpga传来的的数据,存入到n行6列的二维数组中(行数与接收数据多少有关)用一维数组储存的源程序如下PrivateSubSerialPort_DataR...
具体就是从串口接收fpga传来的的数据,存入到n行6列的二维数组中(行数与接收数据多少有关)用一维数组储存的源程序如下
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
'-----------十六进制显示------------
Dim inDataLen As Integer = SerialPort.BytesToRead()
If inDataLen > 0 Then
Dim inBytes(inDataLen - 1) As Byte, bytes As Byte
Dim strHex As String = ""
SerialPort.Read(inBytes, 0, inDataLen)
For Each bytes In inBytes
i += 1
If i Mod 5 <> 0 Then
strHex = strHex + [String].Format("{0:X2} ", bytes)
Else
strHex = strHex + [String].Format("{0:X2} ", bytes) + vbNewLine + vbNewLine
End If
Next
TextBoxRecieve.Invoke(RecieveRefresh, strHex)
BarCountRx.Text = (Val(BarCountRx.Text) + inDataLen).ToString '接收字节计数
End If
End Sub 展开
Private Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
'-----------十六进制显示------------
Dim inDataLen As Integer = SerialPort.BytesToRead()
If inDataLen > 0 Then
Dim inBytes(inDataLen - 1) As Byte, bytes As Byte
Dim strHex As String = ""
SerialPort.Read(inBytes, 0, inDataLen)
For Each bytes In inBytes
i += 1
If i Mod 5 <> 0 Then
strHex = strHex + [String].Format("{0:X2} ", bytes)
Else
strHex = strHex + [String].Format("{0:X2} ", bytes) + vbNewLine + vbNewLine
End If
Next
TextBoxRecieve.Invoke(RecieveRefresh, strHex)
BarCountRx.Text = (Val(BarCountRx.Text) + inDataLen).ToString '接收字节计数
End If
End Sub 展开
2个回答
展开全部
关键代码(手打):
Option base on 0
Dim data() as String
nDataRow = nDataRow + 1
Redim Preserve data(nDataRow - 1, 5)
。。。
Option base on 0
Dim data() as String
nDataRow = nDataRow + 1
Redim Preserve data(nDataRow - 1, 5)
。。。
追问
能不能具体一点呢?
追答
这还不具体吗?就是说
定义一个不定长数组Dim data() as String
记录当前数据个数nDataRow
有新记录时 nDataRow + 1
重新定义数组长度,并保留原数据
Redim Preserve data(nDataRow - 1, 5)
给新数据赋值
data(nDataRow - 1,0)=..
data(nDataRow - 1,1)=..
...
data(nDataRow - 1,4)=..
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询