11/5/2021 1:38 PM  
Joined: 10/18/2019 Last visit: 6/19/2023 Posts: 4 Rating: (0) 
Hello, I have the task of writing to specific bits in a register and I don't understand how to use Modbus FC16. I have learned that for this you need to use masking, Result = (Current Contents AND And_Mask) OR (Or_Mask AND (NOT And_Mask)) but i don't understand how to use it. Should I define variables for Current Contents, And_Mask and Or_Mask and assign the result to dataBuffer in Modbus_Client like dataBuffer:= Result := (Current Contents AND And_Mask) OR (Or_Mask AND (NOT And_Mask)). In this way will set and reset the bit depending on the bit state? Looking forward to your opinions! 
11/8/2021 10:55 AM  
Joined: 10/18/2019 Last visit: 6/19/2023 Posts: 4 Rating: (0) 
After some more documentation reading I have found that you can't change individual bits in word without sending the entire word. 
This contribution was helpful to1 thankful Users 
11/8/2021 3:44 PM  
Joined: 3/28/2010 Last visit: 4/17/2024 Posts: 1029 Rating: (211) 
A mask allows you to change just one bit in the register. The example is a byte, not a 16 bit register value, but the principle still applies. To create a logic 0 bit, AND the working word with a mask that is all logic 1's except the bit that should be zero; that bit is logic zero in the mask To create a logic 1 bit, OR the working word with a mask that is all logic 0's, except the bit that should 1, that bit is logic one in the mask Example: Working word is 0110 0101, bit 2 is a logic 1 (LSB 0 bit count; bits: 7,6,5,4,3,2,1,0) To make bit 2 a logic 1; case 1, bit 2 is a logic 1 0110 0101 OR 0000 0100 mask bit 2 is a logic 1, 0110 0101 makes result bit 2 a logic 1 to make bit 2 a logic 1; case 2, bit 2 is a logic 0 0110 0001 OR 0000 0100 mask bit 2 is a logic 1 0110 0101 makes result bit 2 a logic 1 To make bit 2 a logic 0: case 1, bit 2 is a logic 1 0110 0101 AND 1111 1011 mask bit 2 is a logic 0, 0110 0001 makes result bit 2 a logic 0 To make bit 2 a logic 0: case 1, bit 2 is a logic 1 0110 0001 AND 1111 1011 mask bit 2 is a logic 0, 0110 0001 makes result bit 3 a logic 0 FC 16 (0x10) writes one or more registers to continuous register addresses. FC 06 writes a single register (16 bits)) word so your code can use a mask to take into account the bits on either side of the target bit in order to not alter those bits. 
12/6/2021 9:31 AM  
Joined: 4/28/2015 Last visit: 2/7/2024 Posts: 10533 Rating: (818) 
Hello, you said you need set data inside some register but question is  what register???? 
With best regards... 

Follow us on