Found an issue with the modbus master code in protocol_modbus_master.c which I've fixed but there may be an underlying issue I do not understand.
force coils works, but force single coil did not work on my modbus serial device, or connecting via tcp to another instance of classicladder.
line 168 of protocol_master_modbus.c read:
AskFrame[ FrameSize++ ] = (unsigned char)BitValue>>8;
AskFrame[ FrameSize++ ] = (unsigned char)BitValue;
I changed them to:
AskFrame[ FrameSize++ ] = (BitValue>>8)&255;
AskFrame[ FrameSize++ ] = BitValue&255;
For some reason the type declaration is not working? I put some debug code around it, and the logic is correct, and the code setting BitValue works, it's just the type conversion for the shifted value results in zero being placed in the MSB of the bit field in the Modbus frame.
This patch fixed it for me.
classicladder 0.8.003
GCC 4.2.4 on Linux (ubuntu) and GCC 4.1.2 on Debian Etch
I think this issue is related to operator precedence. Typecast is evaluated before logical shift[1]. So, you must use some parenthesis, like this:
AskFrame[ FrameSize++ ] = (unsigned char) (BitValue>>8);
[1]http://www.cppreference.com/wiki/operator_precedence