-
Notifications
You must be signed in to change notification settings - Fork 202
Use canopen with externally provided bus and notifier #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Still haven't quite wrapped my head around what approach makes most sense here. I do see the possible need to provide your existing implementation / instance for the bus. Not sure what the requirements are for the notifier, and why that should be required to be a single instance. In general, I think having a clearly defined point when these things are assigned, to be important. For the Providing bus and notifier as keyword arguments to
In my opinion, the direct attribute access (Option 1) makes more sense, for the reasons outlined above. Thus the only needed change would be to avoid overwriting a preset |
The following code demonstrates that it doen't work with multiple notifiers. If they where truly independent every message received on the bus should be delivered to each of the independent listener. But it itsn't. Only the first in line gets the message, which can be seen on the output. And for the record, this example being async has no impact. Set class MyListener(can.Listener):
def __init__(self):
print(f"Listener {id(self)} created")
def on_message_received(self, msg):
print(f"{id(self)} Message received: {msg}")
async def main():
loop = asyncio.get_event_loop()
bus = can.Bus(interface='pcan', bitrate=1000000)
listen1 = MyListener()
notifier1 = can.Notifier(bus, [listen1], loop=asyncio.get_event_loop())
listen2 = MyListener()
notifier2 = can.Notifier(bus, [listen2], loop=asyncio.get_event_loop())
await asyncio.sleep(3600) Which produce
So this is the long rationale for why a system running multiple can protocols must share |
FYI for inspiration: It was urgently needed in the async port, so I've implemented the following: |
On the same can Bus, I use a mix of CANopen, J1939 and raw-can. I do not use the "connect" or "disconnect" methods ( also used in the J1939 library ). SO, your "network bus" needs to be added or removed to the can.listeners list rather then "connected"/"disconnected". when the can interface thread have a message available: it will call each "listerners" ( canopen / j1939 /rawcan ) you added |
This is precisely the main point of this issue. canopen is creating a new notifier from its Edit:
|
I understand your point of view and I agree, it would be awesome ! Your in-depth understanding of the underlaying issue makes me believe you would like to propose a Pull-request and wanted to know if Christian or some other hardcore user of this library would be willing to take over the maintenance of this new "Layer". Do I understand you well ? I saw from your repos you are getting your hands dirty on an asyncio spin-off ... If yes, I would be more then interested in using your "Branch". Possibly testing it and providing feedback( Pull-request ) to address some of the issues that will arise. I am not as well versed on multi-threading BUT I always end-up having to adjust the libraries I use. MY TARGET USE-CASE: Bus sniffing/decoding & emulating. In the mean time, I replaced the CANopen.network Listener with my own ... Looking forward for a sveineBus interface layer |
I have a use-case where canopen have to live next to another protocol (using only extendedids). The (physical) can bus interface cannot have multiple instances and the same
can.Bus()
interface. It and and thecan.Notifier()
instance must be shared with both protocols.Network.connect()
makes it a bit cumbersome to define bus and notifier from the outside.https://github.com/christiansandberg/canopen/blob/ae71853be7fb42870bb5763066b0c3c50d015669/canopen/network.py#L83-L112
There are several things that can be done here to make it more consistent. I'm interested in hearing what opinions there might be for how to improve this:
Option 1
Be able to support a provided notifier, similar to what's done with
bus
:To use your own:
Option2
Extend arguments to
connect()
:This allows the usage:
PS!
Network.disconnect()
doesn't really play nice with externally provided bus and notifier either and should be looked at.* EDIT *
I think also the init of
Network
should be extended:The text was updated successfully, but these errors were encountered: