Modbus Martem

From Phobos Wiki
Revision as of 08:05, 18 August 2016 by MarkTomm (talk | contribs) (Uus lehekülg: '== Addressing scheme == Telem Application Modbus function code enumeration: <pre> enum ModbusFunctionCodes { MODBUS_FN_UNSUPPORTED = 0x0, MODBUS_READ_COIL ...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Addressing scheme

Telem Application Modbus function code enumeration:

enum ModbusFunctionCodes
{
    MODBUS_FN_UNSUPPORTED           = 0x0,
    MODBUS_READ_COIL                = 0x1,
    MODBUS_READ_INPUT               = 0x2,
    MODBUS_READ_HOLDING_REGISTERS   = 0x3,
    MODBUS_READ_INPUT_REGISTERS     = 0x4,
    MODBUS_FORCE_SINGLE_COIL        = 0x5,
    MODBUS_SET_SINGLE_REGISTER      = 0x6,
    MODBUS_FORCE_MULTIPLE_COIL      = 0xF,
    MODBUS_SET_MULTIPLE_REGISTER    = 0x10
};

Lower device addressing has small differences for input and output objects in Telem Application.

Input objects function code is determined from the address in the following way:

if(100000 <= address)
    fn_code = address / 100000;
else
    fn_code = address / 10000;

switch( fn_code )
{
case 0:
    return MODBUS_READ_COIL;
case 1:
    return MODBUS_READ_INPUT;
case 3:
    return MODBUS_READ_INPUT_REGISTERS;
default:
case 4:
    return MODBUS_READ_HOLDING_REGISTERS;
}

Note that ...