初始值
This commit is contained in:
28
CommunicationProtocol/NT_CAM.vb
Normal file
28
CommunicationProtocol/NT_CAM.vb
Normal file
@@ -0,0 +1,28 @@
|
||||
Public Class NT_CAM
|
||||
'包头
|
||||
Public Shared HeadData As Byte() = {&H55, &HAA}
|
||||
'协议版本
|
||||
Public Shared protocolVersion As Byte = &H1
|
||||
|
||||
'数据组包
|
||||
Public Shared Function PackData(cmd As Byte, parbyf As Byte()) As Byte()
|
||||
Dim li As List(Of Byte) = New List(Of Byte)()
|
||||
li.AddRange(HeadData) '2
|
||||
li.Add(protocolVersion) '1
|
||||
li.Add(cmd) '1
|
||||
li.AddRange(SharedFunction.IntToByteLB(parbyf.Length)) '2
|
||||
li.AddRange(parbyf)
|
||||
li.Add(SharedFunction.GetCheckSumMod2(li.ToArray))
|
||||
Return li.ToArray
|
||||
End Function
|
||||
|
||||
'判断数据是否合法
|
||||
Public Shared Function IsDataValid(data As Byte()) As Boolean
|
||||
If data.Length < 7 Then Return False '数据长度小于7
|
||||
If data(0) <> HeadData(0) OrElse data(1) <> HeadData(1) Then Return False '包头不正确
|
||||
If data(data.Length - 1) <> SharedFunction.GetCheckSumMod(data) Then Return False '校验和不正确
|
||||
Return True
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user