Codeys Modbus TCP Client reading from M241

kallileo
2018-12-12
2019-01-24
  • kallileo - 2018-12-12

    I'm doing some tests and I have setup Codesys Win PLC as Modbus TCP Client to read/write holding registers from a M241 PLC which acts as Modbus TCP Slave.
    I'm able to read data from the PLC using touch screen HMI and qModMaster but just I can't get it to work using Codesys Windows Soft PLC.

    The IP's and everything is setup correctly. When I run the program I get "Running" status on Modbus TCP slave so I guess it means that the communiction is established.

    Then since I need to read %MW10 from M241 I create a Modbus channel like in the picture.

    Unfortunately it doesn't work and I don't know what I'm doing wrong.

    IMG: CodesysModbusChannel.png

     
  • dFx

    dFx - 2018-12-12

    %MW is internal memory. This is not exposed by default to modbus TCP.

    On your TCP server instance (slave), you had to define buffers for 1x,2x,3x and 4x function code areas. Just fill them correctly to expose your data.

    using IL_ModbusTCPServerType02 FB from RIL_ModbusTCP with codesys 2.3/3.5, I had these parameters :
    arbyBitData
    arbyDiscreteInputs
    RegisterData
    InputRegisters

     
  • kallileo - 2018-12-12

    The thing is that Modbus TCP and RTU Servers are enabled by default on M241 so I'm sure that there is no problem with the Modbus Server.
    I have absolutely no problem accessing Modbus registers using other clients like HMIs or Windows Modbus TCP clients.
    There only problem is that I can't access them using the Modbus Client of Codesys runtime on Windows or actual hardware.

     
  • dFx

    dFx - 2018-12-12

    kallileo hat geschrieben:
    The thing is that Modbus TCP and RTU Servers are enabled by default on M241 so I'm sure that there is no problem with the Modbus Server.
    I have absolutely no problem accessing Modbus registers using other clients like HMIs or Windows Modbus TCP clients.
    There only problem is that I can't access them using the Modbus Client of Codesys runtime on Windows or actual hardware.

    So I bet you have double checked your access type (3x,4x), and addressing (Modbus base address is 0, but often you may see a +1 offset because of Jbus addressing).

    Can you issue a ping from your win PLC to your M241 ?

     
  • kallileo - 2018-12-12

    I can ping the M241 PLC (slave).

    The communication seems to be ok.
    Also as it shown in the screenshot qModMaster is reading the data in the holding register %MW10 without any problem but Codesys Win control reads nothing.

    IMG: CodesysModbusMaster.png

     
  • dFx

    dFx - 2018-12-12

    By issuing a ping, I mean, from your runtime. Cause this would validate the lP stack settings.

    Does M241 supports multiple connections from different hosts on port 502 ?
    Could you post your ModbusTCPSlave parameters ?

     
  • e.kislov - 2018-12-12

    You need set Always update variables: Activate 2 (always in bus cycle task).
    On your screenshot this setting hide under window QModMaster.

     
  • kallileo - 2018-12-12

    OK. I replaced the M241 PLC with pyModSlave which is now running on my laptop and is used as Modbus Server my clients connect to.
    Again I have no problem reading Modbus registers from QModMaster installed on the same PC as the Codesys Win control PLC.

    I have set the option "Always update variables:" to "Activate 2 (always in bus cycle task)" but it still doesn't work in Codesys.
    It's really driving me crazy.

     
  • dFx

    dFx - 2018-12-13

    please make sure that QmodSlave doesn't uses port 502 with netstat -a -b command.

     
  • kallileo - 2018-12-13

    Hi,

    "Always update variables:" to "Activate 2 (always in bus cycle task)"

    IT WORKED.
    It seems that if you don't assign Codesys variables to Modbus channels you need to have this option set to "Activate 2 (always in bus cycle task)" or else you see nothing in Codesys.

    Thank you for your help guys.

    It's also mentioned in the link below.
    https://faq.codesys.com/pages/viewpage. ... Id=3538995 m

     
  • TURCKONE - 2019-01-24

    Hello experts ,

    in codesys v3 my target is control win

    i want a bit for my modbus TCP cpmunication failure .

    is there any bit for this purpose ?

    and yes i am trying with Modbus_TCP_Slave.xerror .

     
  • jzhvymetal - 2019-01-24

    kallileo hat geschrieben:
    The thing is that Modbus TCP and RTU Servers are enabled by default on M241 so I'm sure that there is no problem with the Modbus Server.
    I have absolutely no problem accessing Modbus registers using other clients like HMIs or Windows Modbus TCP clients.
    There only problem is that I can't access them using the Modbus Client of Codesys runtime on Windows or actual hardware.

    @Kallileo not sure if you got the M241 modbus working but it could have been the Node ID you where using. With M241 it response differently depending on Node ID. See pic below

    IMG: M2x1 MODBUS TCP SLAVE.png

     

Log in to post a comment.