Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Modbus non-standard addressing FC3

Scoobler
2019-02-06
2019-02-08
  • Scoobler - 2019-02-06

    I am currently using a HMI/Codesys device to talk to multiple Modbus devices - all this works well, not that it makes any difference everything is in ST as this is all fairly new to me and I come from a software programming background.

    I have a new set of devices I need to collect data from however they don't use standard addressing. Everything is in a holding register, from 0-65536. They don't conform to the holding registers being in the 40x range.

    When adding a channel I can either enter the address in decimal and it gets converted or enter the hex value, however if I enter 1 for example using function 3 to read holding registers it assumes 40001 but for this device I actually want 00001.

    Is this possible with the standard library? Is there any other library which can do it?

    Thanks in advance!

     
  • dFx

    dFx - 2019-02-07

    Wikipedia hat geschrieben:
    In the traditional standard, numbers for those entities start with a digit, followed by a number of 4 digits in the range 1–9,999:
    coils numbers start with 0 and span from 00001 to 09999,
    discrete input numbers start with 1 and span from 10001 to 19999,
    input register numbers start with 3 and span from 30001 to 39999,
    holding register numbers start with 4 and span from 40001 to 49999.
    This translates into addresses between 0 and 9,998 in data frames. For example, in order to read holding registers starting at number 40001, corresponding address in the data frame will be 0 with a function code of 3 (as seen above). For holding registers starting at number 40100, address will be 99. Etc.
    This limits the number of addresses to 9,999 for each entity. A de facto referencing extends this to the maximum of 65,536.[13] It simply consists of adding one digit to the previous list:
    coil numbers span from 000001 to 065536,
    discrete input numbers span from 100001 to 165536,
    input register numbers span from 300001 to 365536,
    holding register numbers span from 400001 to 465536.

    source : https://en.wikipedia.org/wiki/Modbus#Coil,_discrete_input,_input_register,_holding_register_numbers_and_addresses

    EDIT : To make it clear, if a holding register address is told being 0001, then read it as read code 4 then address 1. But if it's told to be 40001, use read code 4 but address may vary depending the constructor (1 or 40001).

     
  • Scoobler - 2019-02-07

    Hi dFx thanks for the reply.

    The 'problem' in theory is, the new device (which is arriving tomorrow so I can start some testing) holds everything in holding registers.

    There are no coils, discrete coils or input registers.

    So within the device everything from 0 to 65,536 is a holding register.

    I have been informed however Codesys doesn't do anything to add the '4'.
    So for example one controller I normally use follows the standard, holding registers are in the '4' section, so asking for register 1 function code 3, is the same as 40001.
    However Codesys simply asks for register 1 with function code 3, it is the controller that returns the correct register. Because the new controller has everything in holding registers, when Codesys asks for register 1 with function code 3, it will get register 00001.

    My confusion came because the HMI which can access tags prefixes the number with the 4 so would only allow access to 9,999 registers which would miss off 55,537 potential registers. I have been informed Codesys will not do this and nothing special needs to be done to make it work!?

     
  • dFx

    dFx - 2019-02-07

    By default, memory maps are 65536 words long.
    There are 4 maps, one for each 1x 2x 3x and 4x codes.
    If everything is in 4x code memory map, then, just use the address provided in the supplier memory map, and it should be fine.
    I Don't really get your concerns. Maybe it will vanish tomorow

     
  • Scoobler - 2019-02-08

    dFx that is basically what I was told. This is from the controller manufacturer that set the alarm bells off:

    Zitat:
    Controllers support the full modbus address range (0-65535 decimal, 0000-FFFF hexadecimal) therefore to address every register in the module, the Modbus Master system must also support this address range.
    All modbus registers are classified as Holding Registers. They can only be read using modbus function code 3 (Read Multiple Registers).
    Some modbus masters use a suffix to the address as a way of specifying the function code to use for the query.
    For example 41,029 is used to instruct the master to query address 1029 using function code 3.
    Some modbus masters also require you to add β€˜1’ as previously described.
    This means that in many cases the master can read only up to register 9999 (49999 is last register that will be read using function code 3).
    These modbus masters are therefore limited and cannot read the full list of registers from the module.

    As stated I am using a HMI which includes Codesys, the HMI allows tags and can read from modbus devices, however the programming software does prefix the '4' for holding registers.

     

Log in to post a comment.