Hello Guest it is March 28, 2024, 06:56:19 AM

Author Topic: Mach4 and modbus - help needed  (Read 4728 times)

0 Members and 1 Guest are viewing this topic.

Mach4 and modbus - help needed
« 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:

Code: [Select]
[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.
« Last Edit: September 21, 2016, 05:27:48 AM by qwertysimo »
Re: Mach4 and modbus - help needed
« Reply #1 on: September 21, 2016, 05:30:06 AM »
Can moderator move this topic to Modbus forum, please? Thanks.

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Mach4 and modbus - help needed
« Reply #2 on: September 21, 2016, 11:47:30 AM »
If it helps the -27 means  MERROR_REG_NOT_FOUND

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Mach4 and modbus - help needed
« Reply #3 on: September 21, 2016, 04:05:55 PM »
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?
Re: Mach4 and modbus - help needed
« Reply #4 on: September 27, 2016, 01:41:11 AM »
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?