Protocol format:
Byte header (2 -) + function code (1 -) + byte length (1 -) + data bits (nbit) + parity bit (2) + word goeldi (2 -)
Byte header: C1 C2
Word goeldi: 0 a 0 d
Data bytes (1 -)=(nbit) + parity bit (2)
Check digit:
Calculation method: first the length byte header + function code + + data a cumulative sum, accumulate the value of the 16 bit high value added to the low 16 bits, that is the accumulation of highest carry to its lowest level, finally to invert,
Can make the output Settings: (check digit 2 byte) are shown in brackets
Issued by: C1 C2 08 04 xx aa (00 00 0 a 0 d (xx: 1:1-4 X 2: Y 3: Z axis 4: B axis aa: 0 output low level 1) output level
Returns: C1 C2 08 00 04 xx (00 00 0 a 0 d
Note: a command parsing failure: C9 C8 FF 02 (00 00 0 a 0 d
How do I write control according to the above these data can make switch function of the driver?
CodePudding user response:
Void CCard: : Off (short axis){
//C1 C2 08 04 xx aa (00 00 0 a 0 d (xx: 1:1-4 X 2: Y 3: Z axis 4: B axis aa: zero output low level 1 output high level)
Int a;
If (axis==1)
A=0 xc1c2080401000a0d;
Else if (axis==2)
A=0 xc1c2080402000a0d;
Else if (axis==3)
A=0 xc1c2080403000a0d;
Else if (axis==4)
A=0 xc1c2080404000a0d;
}
//the above I wrote to you, then how to do, do not know how to start
CodePudding user response:
Issued by: C1 C2 08 04 xx aa (00 00 0 a 0 d (xx: 1:1-4 X 2: Y 3: Z axis 4: B axis aa: 0 output low level 1) output levelReturns: C1 C2 08 00 04 xx (00 00 0 a 0 d
Issued, the returns are respectively in where? How do you use the check digit in the bracket? I then delete the check digit in the bracket above right?
CodePudding user response:
Are the corresponding bytes, you write directly to the corresponding inside, generally don't use such a variable to hold the, one is a package had 8 bytes, 16 bytes, another reason is some packet length,Unsigned char * package=new unsigned char [10].
Package [0]=0 xc1;
Package [1]=0 xc2;
Package [3]=0 x08;
.
.
.
CodePudding user response:
Then how come out 0 xc1c2080401000a0d this string of Numbers, and the check digit in the bracket, and returns the is how to return a responsibilityCodePudding user response:
It is as you say so?Unsigned char * package=new unsigned char [10].
Package [0]=0 xc1;
Package [1]=0 xc2;
Package [2]=0 x08;
Package [3]=0 x04;
Package [4]=0 x00;
Package [5]=0 x00 + axis;
Package [6]=0 x00;
Package [7]=0 x00;//check digit
Package [8]=0 x0a;
Package [9]=0 x0d;
Check digit is to also write in it?
CodePudding user response:
You carefully look at instructions, packet generally include: head, length, calibration, tail sign, you here at the end of which is to enter a new line, check should have is how to calculate, is the most simple xor check and CRCCodePudding user response:
The communication protocol assembled into an array of bytes to useDon't be so use 0 xc1c2080401000a0d computer or microcontroller can't represent special big number
CodePudding user response:
Data bytes (1 -)=(nbit) + parity bit (2) it should be a bit, and should be byte bytesCheck two bytes
CodePudding user response:
Calibration method of know, but I don't know how to use theCheck digit:
Calculation method: first the length byte header + function code + + data a cumulative sum, accumulate the value of the 16 bit high value added to the low 16 bits, that is the accumulation of highest carry to its lowest level, finally to invert,
This is a routine:
Under-16 checksum (u8 * buffer, under-16 size)
{
U32 cksum=0;
U8 I=0;
for(i=0; i
Cksum +=* buffer++;
}
Cksum=(cksum & gt;> 16) + (cksum & amp; 0 XFFFF);
Cksum +=(cksum & gt;> 16);
Return ~ cksum;
}
CodePudding user response: