pyads: Python crashes after receiving a second notification

After moving my code from Windows to Linux I get crashes after the second notification. Both running pyads 2.2.5

This is an example of code that works on Windows but crashes on Linux:

import pyads
from time import sleep
import os

if not os.name == 'nt': # On Linux
    pyads.open_port()
    adr = pyads.AmsAddr(AMS, pyads.PORT_SPS2)
    pyads.add_route(adr, IP)
    sleep(8)
    print(pyads.get_local_address())

plc = pyads.Connection(AMS, pyads.PORT_SPS2, IP)
plc.open()

@plc.notification(pyads.PLCTYPE_REAL)
def callback(handle, name, timestamp, value):
    print(
        '{0}: received new notitifiction for variable "{1}", value: {2}'
        .format(name, timestamp, value)
    )

handles = plc.add_device_notification('REALVALUE', pyads.NotificationAttrib(4), callback)
sleep(10)
plc.del_device_notification(handles[0], handles[1])

The output on Linux is: REALVALUE: received new notitifiction for variable “2017-10-10 11:22:06.225441”, value: 1368.362548828125 REALVALUE: received new notitifiction for variable “2017-10-10 11:22:06.230441”, value: 1367.6650390625 python3: AdsLib/RingBuffer.h:71: void RingBuffer::Read(size_t): Assertion `n <= BytesAvailable()’ failed. Aborted (core dumped)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

The pleasure is all mine, it’s really fun to work with all of you to keep improving ADS. I will have a closer look on your Python ADS testserver, too 😉.

The fix is now on master: https://github.com/Beckhoff/ADS/commit/82e2ecf052bbaa1d7c1e530eb8a16f4c592b69b4

Thanks for the Wireshark. From what I can see there. The AMS Headers look good. Just the length in the NotificationHeader is somehow wrong. A patch should be simple so I pushed a version online: https://github.com/Beckhoff/ADS/tree/dev-fix-broken-notifications-v1

However simulating the error is much more difficult so I wasn’t able to test with bad packages, yet. I will work on that, but for the meantime I thought I show you my patch so you can test it, in case you find time for that.