christoph2 / pyxcp

ASAM XCP in Python
http://pyxcp.rtfd.org
GNU Lesser General Public License v3.0
197 stars 63 forks source link

Infinite loop of listener pyxcp.transport.can.CanInterfaceBase that does not stopping after session disconnect #115

Closed polarbearjngl closed 1 year ago

polarbearjngl commented 1 year ago

There is Infinite loop in pyxcp.transport.can.Can.listen. So even if we are closing connection using pyxcp.master.master.Master.disconnect - listener does not stopping pulling data. Seems like an issue for me

How it was reproduced by me Insert print line into (https://github.com/christoph2/pyxcp/blob/master/pyxcp/transport/can.py#L328) just for visual debug

print("listening")

And then run this one, using config from below ``` #!/usr/bin/env python # -*- coding: utf-8 -*- import struct from pyxcp.cmdline import ArgumentParser ap = ArgumentParser(description="pyXCP hello world.") def run(address): with ap.run() as x: x.connect() print("Connected") x.setMta(address=address) b_data = x.upload(4) print(f"Get params, bytes {b_data}") data = struct.unpack('>f', b_data)[0] print(f"Get params, decoded {data}") print("Disconnecting") x.disconnect() print("Disconnected") print("open first XCP session") run(address=0x528013B8) print("open second XCP session") run(address=0x010F4E28) ```

I was using PeakCan adapter

Config that was used ``` { "TRANSPORT": "CAN", "CAN_USE_DEFAULT_LISTENER": true, "ACCEPT_VIRTUAL": true, "BAUDRATE_PRESET": true, "CAN_ID_BROADCAST": 256, "MAX_DLC_REQUIRED": false, "BTL_CYCLES": 16, "SAMPLE_RATE": 1, "SAMPLE_POINT": 87.5, "SJW": 2, "TSEG1": 5, "TSEG2": 2, "CAN_DRIVER": "PCan", "CAN_ID_MASTER": 2572287332, "CAN_ID_SLAVE": 2572182781, "CREATE_DAQ_TIMESTAMPS": false, "CHANNEL": "PCAN_USBBUS1", "BITRATE": 500000 } ```

Watch output of running this code. Even after closing listener still continue running in the loop

output logs.txt

Solution

add into method pyxcp.transport.can.Can.close call to end listener loop using self.finishListener()