Machsupport Forum
Third party software and hardware support forums. => Modbus => Topic started by: qwertysimo on September 21, 2016, 05:15:51 AM
-
Hi,
please, can you help me with actual problem? While I can read (0x03) and write (0x06) holding register and I can read (0x01) coil, I cannot write coil (0x05). This is the code, a snippet from signal library definition, with some debug output:
[mc.OSIG_RUNNING_GCODE] = function( state )
local hregTestCoil, rc = mc.mcRegGetHandle( inst, "modbus0/testCoil" ); -- THIS COMMAND IS FAILING
mc.mcCntlSetLastError( inst, "testCoil handle: " .. tostring( hregTestCoil ) .. ", rc: " .. tostring( rc ) );
local hregTestRegister, rc = mc.mcRegGetHandle( inst, "modbus0/testRegister" );
mc.mcCntlSetLastError( inst, "testRegister handle: " .. tostring( hregTestRegister ) .. ", rc: " .. tostring( rc ) );
if( state == 1) then
mc.mcCntlSetLastError( inst, "signal changed to 1" );
mc.mcRegSetValue( hregTestCoil, 1 );
mc.mcRegSetValue( hregTestRegister, 101 );
else
mc.mcCntlSetLastError( inst, "signal changed to 0" );
mc.mcRegSetValue( hregTestCoil, 0 );
mc.mcRegSetValue( hregTestRegister, 100 );
end
end,
Attempt to get handle for testCoil fails with return code of -27 which should mean MERROR_REG_NOT_FOUND. What is wrong?
Thanks.
-
Can moderator move this topic to Modbus forum, please? Thanks.
-
If it helps the -27 means MERROR_REG_NOT_FOUND
DazTheGas
-
It does not help. I wrote that information in my first post already.
As a workaround, I do not use coils, I use only holding registers...
Another question - modbus function 0x10, write multiple registers. How to enter several integers in one command?
mc.mcRegSetValue( number hReg, number value )
How to specify "value" to represent several integers for multiple registers?
-
BUMP
Another question - modbus function 0x10, write multiple registers. How to enter several integers in one command?
mc.mcRegSetValue( number hReg, number value )
How to specify "value" to represent several integers for multiple registers?