python-udsoncan: udsoncan.exceptions.TimeoutException: Did not receive response in time. P2 timeout time has expired (timeout=10.000 sec)
I have already created a bus in another python file and added it to a global dict - GLOBAL_DICT. And I tried to use it as below:
bus = GLOBAL_DICT['bus']
stack = isotp.CanStack(bus=bus, address=tp_addr, params=isotp_params)
But got error as below:
Exception in thread Thread-3:
Traceback (most recent call last):
File "D:\Development_Tools\Python\lib\site-packages\udsoncan\client.py", line 1647, in send_request
payload = self.conn.wait_frame(timeout=timeout_value, exception=True)
File "D:\Development_Tools\Python\lib\site-packages\udsoncan\connections.py", line 68, in wait_frame
frame = self.specific_wait_frame(timeout=timeout)
File "D:\Development_Tools\Python\lib\site-packages\udsoncan\connections.py", line 490, in specific_wait_frame
raise TimeoutException("Did not receive frame IsoTP Transport layer in time (timeout=%s sec)" % timeout)
udsoncan.exceptions.TimeoutException: Did not receive frame IsoTP Transport layer in time (timeout=10 sec)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Development_Tools\Python\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "D:\Development_Tools\Python\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "D:\Development_Tasks\CANSimulator\send_diag_request.py", line 262, in send_diag_session_control
session_response = self.client.change_session(DiagnosticSessionControl.Session.defaultSession)
File "D:\Development_Tools\Python\lib\site-packages\udsoncan\client.py", line 131, in decorated
return func(self, *args, **kwargs)
File "D:\Development_Tools\Python\lib\site-packages\udsoncan\client.py", line 189, in change_session
response = self.send_request(req)
File "D:\Development_Tools\Python\lib\site-packages\udsoncan\client.py", line 1655, in send_request
raise TimeoutException('Did not receive response in time. %s time has expired (timeout=%.3f sec)' % (timeout_name_to_report, timeout_value))
udsoncan.exceptions.TimeoutException: Did not receive response in time. P2 timeout time has expired (timeout=10.000 sec)
However, it works well when I changed the code as follows:
if 'bus' in GLOBAL_DICT.keys():
GLOBAL_DICT['bus'].shutdown()
bus = can.ThreadSafeBus(bustype='pcan', app_name=None, channel='PCAN_USBBUS1', bitrate=bitrate1, receive_own_messages=True, name="BUS1")
And then, I tried to added the new bus to GLOBAL_DICT, and it got the same error again:
if 'bus' in GLOBAL_DICT.keys():
GLOBAL_DICT['bus'].shutdown()
bus = can.ThreadSafeBus(bustype='pcan', app_name=None, channel='PCAN_USBBUS1', bitrate=bitrate1, receive_own_messages=True, name="BUS1")
GLOBAL_DICT['bus'] = bus
I printed the GLOBAL_DICT before and after, but it seems normal:
{'bus': <ThreadSafeBus at 0x000001707C5F6048 for PcanBus at 0x000001707C5BFD30>}
{'bus': <ThreadSafeBus at 0x000001707C9B1308 for PcanBus at 0x000001707C5E9470>}
I’m so confused about it. Could anyone help to check? Thanks in advance!
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 16 (6 by maintainers)
If you have another section of your program rwading the bus, it will deplete the rx queue of the bus. You need to read a message and based on the ID, redirect to isotp or aomething else.
The best solution is to use a listener
If you don’t call uds or isotp layer across threads, that should be fine. The isotp connection is thread safe.