You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 7, 2021. It is now read-only.
I was hoping someone here might be able to help with an example of how to use the dispatcher in a loop and if a condition is met, send a relevant response.
Currently I've just been interacting with Pyvit in a simple while loop with dev.recv. However I'm not sure how to interact with the dispatcher given things are threaded.
Basically, I have a simple program using Pyvit acting as an ECU to send things such as RPM and Speed when requested by a connected device.
As you can see, I'm "cheating" with the VIN, and just sending the frames out without actually checking if a frame control message is received. I want to improve this, and actually use the ISO-TP functionality.
My issue is I've struggled to get ISO-TP messages working nicely.
Using the isotp_test I was able to get an idea on how to send an ISO-TP frame, provided you send a frame control message.
#!/usr/bin/env python3importthreadingfrommultiprocessingimportQueuefrompyvit.hwimportsocketcanfrompyvit.dispatchimportDispatcherfrompyvit.proto.isotpimportIsotpInterfacedev=socketcan.SocketCanDev("vcan0")
disp=Dispatcher(dev)
recv_queue=Queue()
disp.add_receiver(recv_queue)
# set up an isotp interface Sender/Receiver arb idsender=IsotpInterface(disp, 0x7DF, 0x7E8)
receiver=IsotpInterface(disp, 0x7E8, 0x7DF)
disp.start()
""" ISOTP transmission and reception of a multi-frame message"""print("payload creation")
payload= [0x49, 0x02, 0x01, 0x31, 0x41, 0x31, 0x4A, 0x43, 0x35, 0x34, 0x34, 0x34, 0x52, 0x37, 0x32, 0x35, 0x32, 0x33, 0x36, 0x37]
# we need to run this in a thread so that the flow control frame is# sent and received, as IsotpInterfaces blockprint("starting tx_thread")
tx_thread=threading.Thread(target=sender.send, args=(payload,))
tx_thread.start()
# we'll receive data in this threadresp=receiver.recv()
# wait for the transmitting thread to finish, then verify the resulttx_thread.join()
## I'm really not too sure what the above " .join"actually does....print("finished")
So the above "sort of" works, but still a tad buggy.
If I have tx_thread.join() in the function, and send VIN Req but no Control Frame, then it holds up the while loop from all other received frames until the thread control frame timeout.
The other issue, is that if you send a control frame, followed by the Vin Req, it'll immediately send the follow up frames. I tried adding resp = [] into the function in hope that it would clear the queue, but after playing around, I see this doesn't appear to make a difference.
Anyone able to give me a hand with this?
Thanks,
Matt
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi,
I was hoping someone here might be able to help with an example of how to use the dispatcher in a loop and if a condition is met, send a relevant response.
Currently I've just been interacting with Pyvit in a simple while loop with
dev.recv
. However I'm not sure how to interact with the dispatcher given things are threaded.Basically, I have a simple program using Pyvit acting as an ECU to send things such as RPM and Speed when requested by a connected device.
As an example:
As you can see, I'm "cheating" with the VIN, and just sending the frames out without actually checking if a frame control message is received. I want to improve this, and actually use the ISO-TP functionality.
My issue is I've struggled to get ISO-TP messages working nicely.
Using the
isotp_test
I was able to get an idea on how to send an ISO-TP frame, provided you send a frame control message.Example:
I'm just not sure how to interact with the Dispatcher send and receive methods/threads within a while loop.
I'm starting to get the impression my main loop should also be a thread but again not sure how to do this.
Sorry if this is an annoying question - I'm still pretty new to python.
Thanks,
Matt
The text was updated successfully, but these errors were encountered: