tkteun
I'm getting back into PLC programming with OpenPLC after some decades. Now I want to be able to read/write booleans/bits with modbus from other platforms. This works fine for inputs and coils like %IX0.0 or %QX0.0 but not for %MX0.0. I have tried to make an array of booleans to fit into a word but I'm not quite sure what the syntax is supposed to be. When I define a (local) variable in program0 of type "ARRAY [1..5] OF BOOL" half the time the editor (3.0 2025-04-29) crashes, but when I do manage to define it, it won't allow me to edit the location. I would like to change it to %MW0 to be able to read it at the 1024 modbus holding register. In 4.0.3beta it says the location is invalid.
 
Am I going about this wrong or is this something that's still being developed?
Thanks
Reply 0 0
thiagoralves
OpenPLC does not have %MX bits. You can simply use unused QX locations as memory bits. Arrays cannot be mapped to located positions.
Reply 1 0
fg71
You could use 16#0001 to set the first bit of 16-bit using WORD
I have used myself in OpenPLC, the 16# stands for hexadecimal notation and after # you have 16-bit hexadecimal bitmask, I used Structured text.
Simple example to set the 8th bit of 16-bit register using holding register, the simulator is converting the hexadecimal number to decimal number.
I do not know what Client or Server you are using for your Modbus but if you get a wrong result it could be a endian problem.
Make sure the Client and Server use the same endians to set bits in 16-bit register.
 
In your case you could use 16#0400 and the simulator will read 1024
 
The approach I did it was using bitmask array to use hexadecimal value, and my Structured text function set the bit based on hexadecimal value.
The data type I used was word and holding register, You couldn't make a array of BOOL to later thinking holding register that use data type WORD.
 
 
[203128%2F9324516%2Fmceclip0]
Reply 0 0
Reply