Repository navigation
Closed
Description
This error is returned when attempting to stop messages that have the same arbitration ID
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/can/interfaces/socketcan/socketcan.py", line 280, in send_bcm
return bcm_socket.send(data)
OSError: [Errno 22] Invalid argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "simple-nm-sim.py", line 238, in <module>
sim.force_stop()
File "simple-nm-sim.py", line 179, in force_stop
self.vin1_task.stop()
File "/usr/local/lib/python3.5/dist-packages/can/bus.py", line 218, in wrapped_stop_method
original_stop_method()
File "/usr/local/lib/python3.5/dist-packages/can/interfaces/socketcan/socketcan.py", line 365, in stop
send_bcm(self.bcm_socket, stopframe)
File "/usr/local/lib/python3.5/dist-packages/can/interfaces/socketcan/socketcan.py", line 285, in send_bcm
raise can.CanError(base + "You are probably referring to a non-existing frame.")
can.CanError: Couldn't send CAN BCM frame. OS Error 22: Invalid argument
You are probably referring to a non-existing frame.
Below is the code snippet where messages are defined and also where messages are being stopped. pm_snapshot_task is stopped first then an error is thrown when attempting to stop vin1_task as it has the same arbitration ID.
self.pm_snapshot_msg = can.Message(
arbitration_id=0x400,
data=self.pm_snapshot_data,
extended_id=False,
dlc=8)
self.nm_msg = can.Message(
arbitration_id=0x51E,
data=self.nm_data,
extended_id=False,
dlc=8)
self.vs_msg = can.Message(
arbitration_id=0x11,
data=self.vs_data,
extended_id=False,
dlc=8)
self.vin1_msg = can.Message(
arbitration_id=0x400,
data=self.vin1_data,
extended_id=False,
dlc=8)
Stopping the tasks
if self.pm_snapshot_task is not None:
self.pm_snapshot_task.stop()
self.pm_snapshot_task = None
if self.vs_task is not None:
self.vs_task.stop()
self.vs_task = None
if self.vin1_task is not None:
self.vin1_task.stop()
self.vin1_task = None
Metadata
Metadata
Assignees
Labels
No labels
Activity
karlding commentedon Jul 10, 2019
Sorry, just realized this went untriaged all this time! The reason for the behaviour that you're observing is pretty simple.
This is because
python-cannaively wraps theTX_SETUPBCM opcode when setting up periodic transmissions. The semantics that the kernel driver provides forTX_SETUPare essentially an "upsert", where if the number of frames is equal to the original periodic task, then it updates the existing task, otherwise it creates a new task. As with all abstractions, theTaskis a leaky abstraction (for what the kernel is doing).We could potentially fix this by issuing a
TX_READfirst before creating a newTask, and seeing if one already exists. If we getEINVAL, then we should be able to proceed with creating a new periodic transmission task, since none exists. Otherwise, we can raise aValueErroror some otherException.Alternatively, we can keep this all in userspace, and have
python-cankeep track of currently active periodic tasks, so we don't have the additional overhead of a socketread/writefor each task that's created. I don't think the overhead is too big of a deal, but I'm open to either solution.Note: I think in order to do what you intended to do, you can create a periodic transmission with an array of 3 elements, or modify your periodic task with the message contents as needed, instead of trying to create 3 separate
Tasks.Read the BCM status before creating a Task
Backport socketcan fix: Read the BCM status before creating a Task