m_ledo

Hello, 

How can I access specific bit/bits of word address In openPLC Editor? 

Thanks.

Quote 0 0
thiagoralves
There isn’t an instruction to do that on the library. What you can do is create your own function block that does that. Inside your function block you can have an input of your word and 16 Boolean outputs for each bit. The code would be something like this:

Value AND 1 > 0 tells you if bit 0 is set
Value AND 2 > 0 tells you if bit 1 is set
Value AND 4 > 0 tells you if bit 2 is set
Value AND 8 > 0 tells you if bit 3 is set
Value AND 16 > 0 tells you if bit 4 is set
Value AND 32 > 0 tells you if bit 5 is set
etc.
Quote 0 0
m_ledo
This function may tell me which bits are active, but I also need to activate specific ones - I use variable frequency drive which is controlled by modbus words. 
However, as I need to use only few  commands, I convert them into decimal number and send them like that.
Quote 0 0
thiagoralves
You can do something similar to set the bits as well. Ex:

(bit0 * 1) + (bit1 * 2) + (bit3 * 4) + (bit4 * 8) ... = word
Quote 0 0