2021-01-30 01:05 AM
Hi, i am using Modbus to write and read registers . can i send one-one bits by selecting holding registers.
For example : i am initalizing uint16_t control _reg = Modbus[6]; //Modbus[6]=000000001
is the value i am sending from Modbus.
next i am using different variables to store those values in bit format like
a = 1; // a = (control _ reg>>0)&1; is the format to store
b=0; // b = (control _ reg>>1)&1
c=0; // c= (control _ reg>>2)&1
d=0; // d= (control_ reg>>3)&1
e=0; // e = (control_ reg>>4)&1
f=0; // f= (control _reg>>5)&1
g=0; // g = (control _reg>>6)&1
h=0; // h = (control _reg>>7)&1
i=0; / i = (control _reg>>8)&1
next time if i send modbus[6] = 000000010 then it should store like
a = 0; // a = (control _ reg>>0)&1; is the format to store
b=1; // b = (control _ reg>>1)&1
c=0; // c= (control _ reg>>2)&1
d=0; // d= (control_ reg>>3)&1
e=0; // e = (control_ reg>>4)&1
f=0; // f= (control _reg>>5)&1
g=0; // g = (control _reg>>6)&1
h=0; // h = (control _reg>>7)&1
i=0; / i = (control _reg>>8)&1
At the end if i send that particular bit 0 or 1 then it store 0 or 1 only other variables must be 0. please tell me how to write code for this using Modbus. And the code written for that is it correct or not . if not then please help me how to do it
Thank you