pyads icon indicating copy to clipboard operation
pyads copied to clipboard

WinError 10040 when communicating with network-connected PLC

Open kristianklein opened this issue 1 year ago • 4 comments

When trying to read a symbol from a PLC connected to the local network, I get the following error:

OSError: [WinError 10040] A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself

I am able to read symbols just fine when the PLC is connected directly to my PC with an ethernet cable. I am on a corporate network, so this might have something to do with it?

I tried increasing the PLC response length in adsGetNetIdForPLC() (in pyads_ex.py, line 395) from 395 bytes to 500 bytes. Now it works and it seems that the received packet is 432 bytes.

Windows 10 Python 3.11.2 pyads 3.4.0 TwinCAT 3.1.4024.44

kristianklein avatar Apr 24 '24 08:04 kristianklein

hello, could you please paste a small reproducible sample bit of code for this? I suspect this is an issue with your network if it works directly. But I can look into it.

chrisbeardy avatar Apr 24 '24 08:04 chrisbeardy

Thanks, Chris. Here is a bit of code that produces the error:

import pyads

conn = pyads.Connection(ams_net_port=10000, ip_address="10.10.10.10")

with conn:
    state = conn.read_state()
    print(state)

kristianklein avatar Apr 24 '24 08:04 kristianklein

Hi @kristianklein

have you change the default port ? normally it's 851 (instead of 10000)

Regards,

kryskool avatar May 06 '24 04:05 kryskool

@kryskool, port 10000 is for the system service. My TwinCAT 3 C++ task defaults to port 350, but the issue exists on both ports.

kristianklein avatar May 06 '24 06:05 kristianklein

did this get resolved?

chrisbeardy avatar Jul 30 '24 07:07 chrisbeardy