python - Faster alternatives to Popen for CAN bus access? -
i'm using popen send instructions utility (canutils
... cansend
function in particular) via command line.
the entire function looks this.
def _cansend(self, register, value, readwrite = 'write'): """send can frame""" queue=self.canbus.queue cobid = hex(0x600 + self.nodeid) #assign nodeid indexbytelow,indexbytehigh,indexbytehigher,indexbytehighest = _bytes(register['index'], register['objectdatatype']) subindex = hex(register['subindex']) valuebytelow,valuebytehigh,valuebytehigher,valuebytehighest = _bytes(value, register['objectdatatype']) io = hex(command_specifier[readwrite]) frame = ["cansend", self.formattedcanbus, "-i", cobid, io, indexbytelow, indexbytehigh, subindex, valuebytelow, valuebytehigh, valuebytehigher, valuebytehighest, "0x00"] popen(frame,stdout=pipe) a=queue.get() queue.task_done() return
i running issues trying send frames (the popen
frame executes command sends frame) in rapid succession, found popen line taking somewhere on order of 35 ms execute... every other line less 2 us.
so... might better way invoke cansend
function (which, again, part of canutils
utility..._cansend
python function above calls ) more rapidly?
i suspect of time due overhead of forking every time run cansend. rid of it, you'll want approach doesn't have create new process each send.
according this blog post, socketcan supported python 3.3. should let program create , use can sockets directly. that's direction you'll want go.
Comments
Post a Comment