christiansandberg / canopen

CANopen for Python
http://canopen.readthedocs.io/
MIT License
434 stars 194 forks source link

`network.PeriodicTask.update` fails to update periodic RPDO #519

Open dominjon opened 1 month ago

dominjon commented 1 month ago

I believe I've found a bug when attempting to update a periodic RPDO whose values I'm setting.

The logic of network.PeriodicTask.update attempts to check if the data are new by checking the argument it's been passed against the existing value in the pdo.Map. However, pdo.Map.update is passing network.PeriodicTask.update the same value. If the task does not have the modify_data attribute, then the fact that new_data != old_data is trivially false means that the data are never updated.

erlend-aasland commented 1 month ago

The new data is saved to .msg.data, no matter which branch is taken:

https://github.com/christiansandberg/canopen/blob/a196e1e3b62bddcfd62cea9fc5293efe8a8cc0a4/canopen/network.py#L327-L335

AFAICS, modify_data is only used to update the task without affecting the timing (see the python-can source). If modify_data is not available, the workaround is to restart the task, thus affecting the timing for the subsequent task execution.

Do you have a code snippet to reproduce the failure you're seeing?