Announcement

Collapse
No announcement yet.

Ethernet/IP between P2K and PC

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts


  • Ethernet/IP between P2K and PC

    Hello all, I am pretty new to all of this so I'm hoping my question has a simple answer. Basically, I'm trying to send data from a P2K (acting as a server) to my PC running a Python script (client). I followed the AutomationDirect video for setting the PLC up as an adapter found here: https://www.youtube.com/watch?v=FNGIgqi0AYQ. I have the PLC connected to the same network as my PC, which is verified by the fact I can program the PC over Ethernet and see its IP in the Productivity Suite software.

    When looking at the network traffic using Wireshark, I see UDP data being transmitted (or at least I think) from the IP of the PLC (and port 9999) to the IP of my PC (port varies if connection is changed) roughly every 250ms. I have not set up any timers regarding this so maybe this is the default I'm not sure, but that's a problem for another day. Also something of mention is when clicking "Help" on the Ethernet/IP Adapter in Productivity Suite, it mentions port 44818 and TCP, but Wireshark does not show any such data.

    The real issue that I'm running into is I'm not seeing any data on the client side. When running my Python script, the program is hanging at a specific point, which is due to it not receiving data. I have successfully set up server/client communications where both are done in Python using my local machine, which makes me think the problem is either on the end of the PLC or some sort of networking thing that I don't understand. As I said, from Wireshark it appears the data is there (although from what I understand Wireshark sees the traffic before anything else, such as Firewall [which I've tried disabling]), but somehow my client is not receiving it. If anyone has any insight I would greatly appreciate it.

    Also posted below is my python code (comments are included after the # in each line). The program hangs at the line where I do s.recvfrom(4096), which is due to it not seeing data. This has been verified by using print statements for debugging and by the fact the program immediately closes if I make it a non-blocking socket.

    Python Code
    __________
    import socket # import socket library

    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Create IPv4/UDP socket

    #UDP_IP = socket.gethostname() # was used for testing local machine
    PLC_IP = '192.168.3.1' # IP of PLC
    UDP_PORT = 9999 # Port Wireshark says PLC is sending data from

    s.connect((PLC_IP, UDP_PORT)) # Connect to PLC socket at specified IP and port

    while True: ### The next two lines are indented and inside the while loop, but whenever trying to format it that way I can't save the changes
    data, addr = s.recvfrom(4096) # receive data and store it in data variable and store the address received from in addr
    print(f"Received message: {data} from address: {addr}") # Print out data and address
    Last edited by medwards; 06-28-2019, 11:33 AM.


  • #2
    You should look at the help topic P197 which has all the TCP and UDP port numbers listed. Your EtherNet/IP UDP port should be set to 2222. The UDP traffic that you see on 9999 is to/from the Programming Software.

    Comment



    • #3
      Thank you for your response, that was definitely a helpful read. I have figured out the issue and to anyone curious, it is as follows. Instead of setting up the PLC as I did in the youtube video linked in my first post, I needed to set up a Custom Protocol over Ethernet. I found this post here which gives a great explanation that I followed: https://forum.automationdirect.com/f...ab-over-tcp-ip. By setting up the PLC that way and slight alterations to the Python code I am now able to read data from the PLC at a specified time interval and decode it.

      Comment



      • #4
        "EtherNet/IP" sounds like a generic TCP/IP protocol (i.e. Custom Protocol), but it is actually an industry standard protocol that is trademarked by a large organization (www.odva.org note the trademark and capitizalization nuance). Automation Direct did not name it, but many of AD's PLC's implement that standard (Click, Do-more, and Productivity, but not DL). The people that know what it is, know what it is. Like many organizations led by engineers, they thought it was a great name because it is completely unambigious AND non-redundant AND cannot be mis-understood (I am a software engineer, BTW ).

        Glad to see that you figured out that you just need simple "Custom" generic Ethernet TCP/IP (that also includes generic UDP).

        Don't get me started on IEC-61131 Function Blocks vs. IEC-61131 Function Block DIAGRAMs.
        There are 10 kinds of people in this world, those who know binary, and those who do not.

        Comment



        • #5
          I went with the pymodbus module communicate over modbus with python to a P1000 while testing for a project. I am looking for a a good odva Ethernet IP module but haven't tested any yet.

          Comment

          Working...
          X