We want to communicate a temperature controller with Lab view for visualization the temperature and in order to control the temperature via lab view.
In the attached sheet we are implementing the logic / procedure required for of controller communication.
1- Header value is (colon) : ( 2 byte)
2- Salve address is variable, it is a device number (2 byte) e.g. 01
3- Data item is variable (2 byte) e.g. 03
4- Function is any function to performed e.g. set temp 0003, set alarming 0004
(4 byte)
5- Data is the actual value to be communicate e.g. 1234 (4byte)
6- LRC check byte (4 bytes), which is a 2�s complement of item 2, 3, 4 and 5.
Hence the total TX value is of 18 byte (: 01 03 0003 1234 and LRC 4 byte )
In order to generate a check byte (4 bytes) LRC we add the above items value, item # 2+ 3+ 4+5 and finally convert it into 2�s complement. I.e.
1- Covert all item value string to number
2- Then add item # 2, 3, 4 and 5 value
3- Convert this number to integer (Double word).
4- Convert the number to Boolean array
5- Invert the number for 1�s complement
6- Convert the Boolean array to number
7- Add +1 for 2�s complement
8- Finally we get the 4 byte LRC
The above LRC working properly if data is 1 byte i.e. 8 bit, however when we have 4-byte i.e. double word it will show some error. Therefore I need help i.e. how to covert the double word to 2�s complement. Is there any solution to directly convert 4 byte (double word) to 2�s complement?
Advance thanks to all professional
ASAD