Code Monkey home page Code Monkey logo

Comments (1)

mattie47 avatar mattie47 commented on June 12, 2024

So I had another go:

#!/usr/bin/env python3

import threading
from multiprocessing import Queue

from pyvit.hw import socketcan
from pyvit.dispatch import Dispatcher
from pyvit.proto.isotp import IsotpInterface

dev = socketcan.SocketCanDev("vcan0")
disp = Dispatcher(dev)
recv_queue = Queue()
disp.add_receiver(recv_queue)

# set up an isotp interface Sender/Receiver arb id
sender = IsotpInterface(disp, 0x7DF, 0x7E8)
receiver = IsotpInterface(disp, 0x7E8, 0x7DF)
disp.start()


def vin():
    payload = [0x49, 0x02, 0x01, 0x31, 0x41, 0x31, 0x4A, 0x43, 0x35, 0x34, 0x34, 0x34, 0x52, 0x37, 0x32, 0x35, 0x32, 0x33, 0x36, 0x37]
    tx_thread = threading.Thread(target=sender.send, args=(payload,))
    tx_thread.start()
    resp = receiver.recv()
    print(resp)
    # resp
    # tx_thread.join()
    resp = []
    print("finished")


while True:
    CanFrameRecv = IsotpInterface.recv(receiver) # This works
    print(CanFrameRecv)

    if CanFrameRecv == [0x09, 0x02]:
        print("It is!")
        vin()

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

from pyvit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.