I need to send the value 115200
as a parameter over serial communication to an external device that which requires the parameter as a part of a byte array in the format: 0x00, 0x00, 0x00, 0x00
and I have no idea how to convert it into that format.
I am doing this in Processing so a Processing/java solution would be handy for the future but ATM I am very happy if I can just send the message with this specific variable.
Here is the byte array:
byte[] tx_cmd = { 0x55, -86, // packet header (-86 == 0xAA)
0x01, 0x00, // device ID
0x00, 0x00, 0x00, 0x00, // input parameter NEEDS TO BE 115200
0x04, 0x00, // command code
0x00, 0x01 }; // checksum
The parameter needs to be put in the 5th to the 8th position (byte[4] - byte[7]).
the message format is little endian this is the message structure:
0 0x55 BYTE Command start code1
1 0xAA BYTE Command start code2
2 Device ID WORD Device ID: default is 0x0001, always fixed
4 Parameter DWORD Input parameter
8 Command WORD Command code
10 Check Sum WORD Check Sum (byte addition) OFFSET[0]+…+OFFSET[9]=Check Sum
Any advice would be much appreciated. Thanks