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 Master read/write over Ethernet UDP/TCP libraries

2015-05-12
2023-08-17
  • nathangreco - 2015-05-12

    Hello Everyone,

    I have need to read/write coils to a Modbus slave device from a CoDeSys PLC. I am testing it on my PC with CoDeSys RTE, but haven't gotten as far as getting a program to compile . I thought this should be a fairly common task with an obvious solution, but it seems this isn't the case or I'm a little slow this week...

    It seems there's a few different options, two of which seem to come from WAGO libraries. I have found this youtube video:

    https://www.youtube.com/watch?v=mCI19PJ2A5I

    But as you can see in my comments, I had to track down 2 dependent libraries (only 1 was indicated in the documentation). I used the following Libraries:
    ModbusEthernet_04.lib <- Contains the ETHERNET_MODBUSMASTER_UDP function block used in the demo
    Ethernet.lib <- Indicated as a dependent library
    Mod_com.lib <- Library I found also dependent, as it declares the 'CRC16' data type used in one of the above libraries

    As you can see by my comment, I could not compile the program without receiving the compile error #3821, "ETH_is16Bit (7): At least one input required for functions".

    Next option is a WAGOLibModbus_IP_01.lib, which in the comment is suggested in this video (its the same video by the original poster),

    https://www.youtube.com/watch?v=l4xkaKFTZB0

    Which appears the exact same, but when I try to compile this program (it is correct, SysLibSocket.lib is the only dependent library), I get the error #3820, ModbusRequest(36): 'VAR_OUTPUT' and 'VAR_IN_OUT' not allowed in functions.

    This seems to be basic error of the library.

    Additionally, I have searched this forum and found some threads regarding this topic, but most seem related to setting up a modbus device as an actual IO module in the PLC configuration, but I just want to send a request. Also, it seems some are clever enough to write their own functions and use only the SysLibSocket.lib, but I am not yet that clever. Anybody out there have a solution that's in use, robust, and clean? Or know what I'm doing wrong here? Thanks.

    Also, my CoDeSys version is 2.3.01.

     
  • nathangreco - 2015-05-12

    Hello jzhvymetal,

    I have found my compile issues were due to my version of CoDeSys being very old, although I still haven't successfully tested the library yet. Now I have 3 options, I think one will work Thanks for the help! I will provide feedback once I've got a device available to make some tests.

    -Nate

     
  • nathangreco - 2015-06-16

    Hey Guys,

    Finally got my hands on a Win 7 / 32-bit system to actually make some tests with a project loaded into CoDeSyS RTE v2.3. I haven't tried the Oscat libraries yet, but I've been messing around with the "WAGOLibModbus_IP_01.lib" libraries and it seems as if there's no network access at all to my Modbus device. The Ethernet_Modbusmaster_UDP Function block gives me an error code "153", which is a timeout error, and Ethernet_Modbus_TCP gives me an error code "150", which is Server not available.

    Is there anything I have to do with the CoDeSyS RTE configuration to give the PLC service access through Windows to my LAN? I recall during installation there was a firewall permission granted for something, (OPC, maybe?), possibly another port needs reserved for the PLC? From within windows I can definitely ping the device.

    If the RTE PLC has access to my LAN by default (is there an easy way to check this?) then I'll try some of the other modbus libraries.

    Thanks guys.

     
  • nathangreco - 2015-06-16

    Actually, is there any way functions that can simply ping from the SysSocket libraries? It would be good to confirm network access first.

    Thanks

     
  • nathangreco - 2015-06-29

    Update for those interested:

    http://www.oscat.de/community/index.php?topic=1827.0

    I was never successful with the ETHERNET_MODBUSMASTER_TCP function, which I'm not sure I understand why. No matter what the result was error 150, "server not available". Additionally, I was only only successful with one device. Another device I have (Cognex Dataman 60SX 2D barcode scanner) would only timeout. I'm still a bit stuck on this one and am going to post another thread on that topic, as with this device I have other options. I suspect maybe it doesn't support MODBUS UDP and for whatever reason the Modbus TCP function block doesn't work.

     

Log in to post a comment.