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/TCP supported functions

ndzied1
2014-04-10
2019-08-15
1 2 > >> (Page 1 of 2)
  • ndzied1 - 2014-04-10

    What Modbus Functions does the Rpi support? I'm trying to use a package to write data to the Pi over modbus but I keep getting exceptions.
    Thanks

     
  • ndzied1 - 2014-04-10

    I found out that they are using function 22 mask write register. I'm guessing that is not supported.

     
  • eschwellinger

    eschwellinger - 2014-04-11

    Hi,

    here the overview, if you are Master (ModBusMaster.jpg ) and you try to add slave functions codes you see them.

    in case the plc is modbus slave (ModbusSlave_FC-Code.jpg):

    Supported Function Codes
    If not restricted by a special type of the controller, the slave generally supports the following function codes:

    See the description in the online help:
    FC03 Read Holding Registers
    FC04 Read Input Registers
    FC06 Write Single Register
    FC16 Write Multiple Registers
    FC23 Read/Write Multiple Registers

    BR
    Edwin

    IMG: ModbusSlave_FC

    IMG: ModBusMaster.jpg

     
  • ndzied1 - 2014-04-11

    Thanks Edwin.

    Is there a way for my controller to be a slave and support Coil Data?

    Thanks,

    Norm

     
  • switcher - 2014-04-20

    Hi,

    I am using Raspberry as as Modbus TCP slave device.

    I like to write holding registers in Raspberry (%IW0) from Modbus master (PC).
    When I write new value into the register, I can shortly see this new value in raspberry, but immediately after this, something override this with value 0.
    Any idea?

    I also like to use modbus coils and discrete inputs. Is this not supported?

    Thank you.
    BR
    Zdenko.

     
  • eschwellinger

    eschwellinger - 2014-04-20

    Hi,

    you need to remove the tag timeout in the modbus slave... see screenshot

    From online help see supported function codes.

    BR
    Edwin

    IMG: Slave_Fuction_Codes.jpg

    IMG: ModbusTimeout.jpg

     
  • switcher - 2014-04-20

    Thank you Edwin . This works great!

    I have another question. Rassberry is still configured as modbus slave.
    I like to use holding registers for read and write variables value. The problem is that I can't write value to modbus holding registers variable within the program execution. For example: I like to read and write temperature setpoint from Modbus master (PC). This setpoint can also be set within the program execution on Raspberry. In this case, Modbus master have to read this changed value. How can I make this work?

    Best regards,
    Zdenko.

     
  • ndzied1 - 2014-04-20

    You need to use the Modbus Input Registers for that.

    I was very confused by this as well.

     
  • switcher - 2014-04-20

    Thank you Norman.
    But I am not sure if I understand your suggestion.
    Input register is only allowed to be read from Master. We can not write to it.

    I think holding register have to be used. With function 03 we can read and with 06 we can write to it.
    The main idea (and demand) is that we can read and write the same holding register from Modbus Master and in PLC (Raspberry in this case).

    Any idea?

    Best regards,
    Zdenko.

     
  • ndzied1 - 2014-04-20

    Sorry for the confusion. I have not been able to find a way to read and write to the same holding registers. I used a combination of holding registers and input registers for getting my sample application working.

    I have seen this in other systems and I believe they are trying to avoid confusion over which is the proper data.

     
  • jzhvymetal - 2014-04-20

    To have Holding registers read/write use CoDeSys ModbusTCP Slave library. See the screen shot for the example how to use it.

    IMG: CoDeSys Modbus Slave.jpg

     
  • switcher - 2014-04-21

    Thank you very much. I added Modbus TCP slave library from Intern/ModbusTCP Slave.
    It is strange that I don't have the same function block:

    Best regards,
    Zdenko.

    IMG: Bild

     
  • switcher - 2014-04-21

    Hi,

    I created new project. In this project is Modbus server function block is shown as it should be. Why it was shown different in my first project I don't know... Maybe can someone help us and explain this situation.

    Anyway, this version works perfect! I can read and write modbus holding registers with master and slave devices.

    Best regards,
    Zdenko.

     
  • eschwellinger

    eschwellinger - 2014-04-21

    Hi,

    there are two ModbusServer fb's available one for Modbus TCP the other for Modbus RTU...
    See screenshots:

    BR
    Edwin

    IMG: ModbusServer2Serial.jpg

    IMG: ModBusServer.jpg

     
  • switcher - 2014-04-21

    Thank you. Yes, RTU is different as TCP. But it is strange that I insert TCP FB and there is RTU.

    This is added libraries. Here it TCP, which is correct:

    Here is Input Assistant to choose Modvus server TCP:

    And this is result, which is not correct:

    Best regards,
    Zdenko.

    IMG: Bild

    IMG: Bild

    IMG: Bild

     
  • eschwellinger

    eschwellinger - 2014-04-22

    Hi,

    i've tried to reproduce that...for me the correct fb occure after insert it with input assistent.
    But anyway if you have steps to repeat to reprocude it please let me know.

    BR
    Edwin

    IMG: Modbus_insert.jpg

     
  • switcher - 2014-04-22

    Thank you Edwin.
    Enclosed I am sending the project. Maybe you can try the same. When I am adding TCP Modbus server function block in MB_FBD, inserted block is not right.

    Best regards,
    Zdenko.

    MBSlave_problem.rar [217.19 KiB]

     
  • eschwellinger

    eschwellinger - 2014-04-26

    Hi,

    on 3.5SP5 Release (July 2014) there is an solution for this issue,
    because we recommend to have all in the configuration it should not be needed to use modbus fb's and call them
    manually. (Sure this will be always possible but the easy way is to have everything called implicit by the system)

    Holding Registers (Slave %I) can be configured to overlay Input Registers (Slave %Q).
    This way they can be made updateable by the Slave's application code.
    See Screenshot.

    BR
    Edwin

    IMG: ModbusHolding.jpg

     
  • switcher - 2014-04-26

    Hi,

    this will be great. Thank you.

    Best regards,
    Zdenko.

     
  • ndzied1 - 2014-04-26

    Edwin Schwellinger hat geschrieben:
    Hi,
    on 3.5SP5 Release (July 2014) there is an solution for this issue,
    because we recommend to have all in the configuration it should not be needed to use modbus fb's and call them
    manually. (Sure this will be always possible but the easy way is to have everything called implicit by the system)
    Holding Registers (Slave %I) can be configured to overlay Input Registers (Slave %Q).
    This way they can be made updateable by the Slave's application code.
    See Screenshot.
    BR
    Edwin

    That is great news. Keep up the good work!

     
  • volio - 2014-05-01

    Hi All,

    Is it possible to have a Modbus TCP server with the same port number per each slave ID and a unique I/O mapping for each of the slaves ? I'm not a very experienced Codesys user, just wondering whether there is a possibility to amend a TCP message processing somewhere in Codesys, which could allow me to point specific slave ID's to specific data maps ?

    At the moment, if we have a one ModbusTCP_Slave _Device added to the devices structure it allows to have (simulate) all 255 slaves on the same port (as I understand this functionality comes by default). Each slave has the same I/O mapping. Now, under "ModbusTCP --> Configuration Parameters" there is an option which should allow to apply a Unit ID, tried to use it expecting to have just one slave active, but looks like it makes no difference at all - am I thinking correctly about the usage of this option ?.

    Besides, tried to add two ModbusTCP_Slace_Devices with different port number and only in this way I did managed to get different I/O mapping for slaves.

    Thanks

     
  • switcher - 2014-08-06

    Hi all,

    I like new Modbus functions support in 3.5SP5 (coils and discrete inputs).

    @Edwin:
    I like to change holding registers with RPi application. I made a configuration with overlay input and holding registers like you suggest. But unforunately it doesn’t work for me. Can you please suggest how to configure this to make it work.

    Thank you.
    BR
    Zdenko.

     
  • eschwellinger

    eschwellinger - 2014-08-07

    Hi Zdenko,

    please send me your project.

    BR
    Edwin

     
  • eschwellinger

    eschwellinger - 2014-08-10

    Hi Zdenko,
    see attached example, this should show how it works, Pi is ModbusMaser and Modbus Slave at the same time (only for me to test purpose),
    in case you use this with you Modbus Master which is running on you windows machine, please remove the Modbus Master from this project example.

    BR
    Edwin

    IMG: ModbusOverlay.jpg

    IMG: ModbusSlave.jpg

    ModbusUpdateHolding.project [223.46 KiB]

     
  • switcher - 2014-08-11

    Thank you very much Edwin,

    I understand the solution. It can be done. I tested it and works ok. But I must say that this is more like a work-around. It is not so easy to define all needed helping variables and program functionality if we have bigger project with a lot of holding registers.

    I think it is easiest to use MB server function block from Modbus lib. In this case this functionality works ok. But unfortunately there are no coils and discrete inputs integrated.

    It will be the best if you integrate this functionality directly in Modbus driver. It is normally used in industrial devices on the market. Do you have a plan to integrate this in the next Codesys release?

    Best regards,
    Zdenko.

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.