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

Modicon m241 Modbus TCP client server

MassSarr
2016-03-23
2016-04-07
  • MassSarr - 2016-03-23

    Hi to all of you,
    I tried to establish Modbus TCP network with SoMachine software between two modicon m241 PLCs but without of any success so I would appreciate some help.
    My goal is to configure one PLC as server and the other one as client in order to exchange data.
    I have searched web and this forum for possible help but with no success so I made this post.
    I tried various options and ways to set this configuration so I think it is better not to write anything what I did because bassically I don't know where I stuck and what is right way to make proper configuration.
    Any kind of help will be great.

     
  • singleton - 2016-03-24

    Hi,
    this is explained in the Online Help of SoMachine. "Programming with SoMachine --> Device Editors --> Modbus Configuration Editor".
    There you can find informations on how to configure the master and the slave.

     
  • MassSarr - 2016-03-25

    Hi singleton,

    my issue is client/server not master/slave. I have established master/slave configuration between HMI and PLC and now I want to make client/server network between two PLCs.

     
  • jzhvymetal - 2016-03-29

    This is easy to do. SE M241/M251 have a Modbus slave server running by default. All that is required is to locate you variables on fixed IEC address.

    Here how to map variables to IEC address

    To be a Modbus master client you have to use READ_VAR, WRITE_VAR, or READWRITE_VAR FB provided by SE. You address TCP using the following:

    β€˜<communication port="" number="" a.b.c.d="">{<ip address="">:<port>}’
    For example, to send a message at Modbus TCP slave IP address 192.168.1.2 using standard TCP port 502, use this string: β€˜3{192.168.1.2}’</port></ip></communication>

    IMG: READWRITE_VAR_EXAMPLE.png

    SoM Modbus Table V3.xls [409 KiB]

     
  • MassSarr - 2016-04-05

    Hi,

    I have been occupied with some other jobs last few days so I had to put on side this my issue. Yesterday I opened my SoMachine project, downloaded it to PLCs and established communication without touching anything. After some time something corrupted and what ever I do and which ever number I sent from first PLC to second one I always had same result on second PLC. After I have done 'Reset origin' on first PLC which is sending data, after that reading results on second PLC were zero all the time.
    After that I have done something like jzhvymetal proposed and nothing changed, readings are zero, ETH LED state lamp on PLCS is lightning steady green, WRITE_READ_VAR FBs don't display any error.

    If you have any idea about solution I would be grateful.

    Print screen of my two POUs is attached here :

    IMG: Modbus Comm.png

     
  • ndzied1 - 2016-04-05

    If the PLC supports Network Variables, this might be an easier way for you to do this.

    No function block calls or dealing with Modbus offsets or lack of defined data types.

     
  • MassSarr - 2016-04-06

    Thanks for advice, I have established communication between two modicon PLCs via Network Variables.
    I found out, between all other rules, that data exchange between several GVLs (senders) of one controller and their associated GNVLs (receivers) should not exceed 1000 bytes of variables what is ok for me now but my goal is Modbus TCP/IP so I will have to figure out what is happening with my application.

     
  • ndzied1 - 2016-04-06

    Depending on what version of CoDeSys your software is built on you may be able to do Modbus without the Function Blocks (Can you tell I hate using the function blocks for Modbus )

    Can you add devices to your tree like in the attached image?

    IMG: Modbus.PNG

     
  • jzhvymetal - 2016-04-07

    MassSarr,

    Your close but maybe I was not clear. You do not have to do FB's on both PLC's unless you want both to be masters and slaves to each other PLC. Since you will probably have only one master see the following example below.

    Also what ndzied1 was describing above is not always implement on the SE PLC's. The Modbus_TCP_Master is only on the dual Ethernet M251 and only available on the device Ethernet port (labeled with non-green border). Also in newer version of SoMachine this has been replace with an Industrial_Ethernet_Manager. Which in effect works the same as the CoDeSys master but also does EthernetIP Master.

    IMG: M2x1 MODBUS COMS.png

     
  • MassSarr - 2016-04-07

    Thanks jzhvymetal

    I know that I am missing something all the time. Whole time I thought that I need FBs on both sides but everthing I had to do is take my values from %MW.

    Once again thanks to all on your kind help.

     

Log in to post a comment.