Modbus Martem: Difference between revisions

From Phobos Wiki
Jump to navigation Jump to search
No edit summary
 
Line 79: Line 79:
==== Analog output objects ====
==== Analog output objects ====


Analog output objects always use MODBUS_SET_SINGLE_REGISTER as function code.
Analog output objects use MODBUS_SET_SINGLE_REGISTER as function code for "SubType v" Normalized.
 
MODBUS_SET_MULTIPLE_REGISTER  on Float, Int32, UInt32.

Latest revision as of 05:16, 3 May 2022

Addressing scheme

Introduction

Modbus addressing scheme is separated in to the address and the function code.

Address

Modbus addresses are extracted from GWS column 'Obj. Addr. v' in the following way:

if(100000 <= address)
    address %= 100000;
else
    address %= 10000;


Function Code

Function Code enumeration

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
};

Function code extracting has small differences for input and output objects in Telem Application.

Input objects

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;
}

Digital output objects

Digital output function codes are determined by their 'SubType^' type in GWS:

if( SubType^ == Single ) {
    return MODBUS_FORCE_SINGLE_COIL
} else {
    return MODBUS_FORCE_MULTIPLE_COIL
}


Analog output objects

Analog output objects use MODBUS_SET_SINGLE_REGISTER as function code for "SubType v" Normalized.

MODBUS_SET_MULTIPLE_REGISTER on Float, Int32, UInt32.