Dropped CAN frame on every socket.recv()

CAN FD to LAN gateway in DIN rail plastic casing
Post Reply
formenergy
Posts: 5
Joined: Wed 23. Aug 2023, 16:09

Dropped CAN frame on every socket.recv()

Post by formenergy » Fri 30. Jan 2026, 22:03

Hello! I have a python app that reads from a PCAN Gateway once per second with a basic TCP socket connection (handshake is off), and I'm seeing a frame be dropped on every read.

My simplest reproducing case is that I have two devices on my bus that each broadcast one frame at 1 Hz and 5 additional frames every 30 seconds. My application calls socket.recv(50000) once a second. I picked 50 kB as my recv size just to be arbitrarily high so I always get all bytes. Each time I call recv(50000), I get 76 bytes, which is a single 48 byte payload CAN FD frame (plus the other bytes for timestamp and so on defined in the Developer Documentation). For many minutes at a time, the 1 frame I get is the 1 Hz frame from node 1 on my bus, and then it eventually switches on its own to being the 1 Hz frame from node 2 on my bus, but I never get both in the same recv() despite an external CAN dongle on the same bus showing both frames are constantly broadcast at 1 Hz. When the 30 s frames from one or the other node arrives, I get all of those frames seemingly without issue.

Similarly, when I put a single CAN 2.0 node that broadcasts at 10 Hz on a different channel, I only get exactly 9 frames on each recv(). In each case I've tested, I always end up with N-1 frames on a read compared to what I expect.

In the GUI, there are no CAN/IP errors. The number of CAN packets and IP packets are equal, and the number of CAN frames increments at the level I expect (e.g., for the situation with two devices broadcasting 1 Hz frames, I see the count go up by ~2 frames a second except occasionally when it bumps up by more because many of the 30 s frames arrived that cycle). This makes it seem that somehow the PCAN Gateway is getting all of the frames, but one is being dropped every time I do a recv() call.

This is very baffling! Any ideas from anyone as to what I might be doing wrong? Fundamentally, it's reproducible simply with a TCP socket doing socket.recv(50000) in a 1 Hz loop. If I change my loop period, the problem scales, for example a 1.5 second loop gets 14 10 Hz frames on every call, and so on.

Thanks in advance.

G.Lang
Support
Support
Posts: 192
Joined: Wed 22. Sep 2010, 14:58

Re: Dropped CAN frame on every socket.recv()

Post by G.Lang » Mon 2. Feb 2026, 13:02

Hi,

please send us your gateways config via email (info.peak@hms-networks.com) and refer to this topis.

Note: The config can be exported into an ini file via the PCAN-Ethernets WebGUI.

G.Lang
Support
Support
Posts: 192
Joined: Wed 22. Sep 2010, 14:58

Re: Dropped CAN frame on every socket.recv()

Post by G.Lang » Wed 4. Feb 2026, 08:56

Problem was solved by "formenergy" itself -> error inside the application code
Thanks for the feedback.

Post Reply