Machsupport Forum

Third party software and hardware support forums. => Modbus => Topic started by: qwertysimo on September 21, 2016, 05:15:51 AM

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

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.
Title: Re: Mach4 and modbus - help needed
Post by: qwertysimo on September 21, 2016, 05:30:06 AM
Can moderator move this topic to Modbus forum, please? Thanks.
Title: Re: Mach4 and modbus - help needed
Post by: DazTheGas on September 21, 2016, 11:47:30 AM
If it helps the -27 means  MERROR_REG_NOT_FOUND

DazTheGas
Title: Re: Mach4 and modbus - help needed
Post by: qwertysimo 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?
Title: Re: Mach4 and modbus - help needed
Post by: qwertysimo 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?