Private Sub SendInstruction ()
Dim As Integer I
Dim j As Integer
Dim ByteHigh As Byte
Dim ByteLow As Byte
Dim High As Integer
Dim low As Integer
ByteHigh=& amp; HFF
ByteLow=& amp; HFF
For I=0 To 5
Xor ByteLow ByteLow=Instruction (I)
For j=1 To 8
Low=ByteLow And & amp; H1
If low=1 Then
High=ByteHigh And & amp; H1
If High=1 Then
ByteHigh=((ByteHigh - 1)/2) And & amp; H7F
ByteLow=((ByteLow - 1)/2) Or & amp; H80
The Else
ByteHigh=(ByteHigh/2) And & amp; H7F
ByteLow=((ByteLow - 1)/2) And & amp; H7F
End the If
ByteHigh=ByteHigh Xor & amp; HA0
ByteLow=ByteLow Xor & amp; H1
Else 'if check code low byte on the right side of the first bit of 0
High=ByteHigh And & amp; H1
If High=1 Then
ByteHigh=((ByteHigh - 1)/2) And & amp; H7F
ByteLow=(ByteLow/2) Or & amp; H80
The Else
ByteHigh=(ByteHigh/2) And & amp; H7F
ByteLow=(ByteLow/2) And & amp; H7F
End the If
End the If
Next j
Next I
Instruction (6) check code=ByteLow 'low byte
Instruction (7) check code=ByteHigh 'high byte
MSComm. OutBufferCount=0 'empty output register
MSComm. The Output to the Output buffer=Instruction 'Output Instruction
End Sub
CodePudding user response:
This should be the IP class check1, the checksum field is set to 0;
2, the IP header of every 16 bit binary sum;
3, if you don't to 0 and 16 bit high, will be 16 bit and 16 bit high and low together repeatedly, until the high and 16 bit is 0, thereby gaining a 16 bit value;
4, the 16 bit value will be taken against, deposited in the checksum field,
Serial port general check. Not very accurate check method, it is mainly used for serial communication.
CodePudding user response:
When receiving bag need to confirm the header, check whether the head is wrong, the algorithm step up 2, 3, and then judge whether the results of the invert is 0, is right, or wrong,