hardbyte / python-can

The can package provides controller area network support for Python developers
https://python-can.readthedocs.io
GNU Lesser General Public License v3.0
1.29k stars 602 forks source link

Receive messages which are sent #43

Closed hardbyte closed 8 years ago

hardbyte commented 8 years ago

Originally reported by: Kyle Altendorf (Bitbucket: altendky, GitHub: altendky)


Is it possible to configure a bus to add sent messages to the receive queue? I am writing an integrated script that both controls a device and logs all bus traffic. I would like the sent messages stored with accurate timestamps and logged as well. I am specifically working on Windows with PCANBasic but would be interested generally.

If not presently available, is anyone already familiar with whether or not the underlying libraries generally support this?

Thanks for your help.

Cheers, -kyle


hardbyte commented 8 years ago

Original comment by Brian Thorne (Bitbucket: hardbyte, GitHub: hardbyte):


Yeah that lines up with my experience as well Kyle. There shouldn't be any problem having another open bus handle to do your logging which will include the bus timestamps. When you run can_logger or candump that is essentially what is happening.

hardbyte commented 8 years ago

Original comment by Kyle Altendorf (Bitbucket: altendky, GitHub: altendky):


Candump is a separate connection to the underlying bus and so what you are sending is not actually being sent by the particular connection candump has, but rather by the connection that cansend (or your Python application) has open. If you were to open two separate python-can buses I bet they would each receive the other's sent messages, but not their own. Anyways, my particular interest is not just to have the messages present but with bus-accurate timestamps. I don't know what if any hardware even supports this.

hardbyte commented 8 years ago

Original comment by Mike Molt (Bitbucket: M_Molt, GitHub: Unknown):


I'll be interested to see what Brian thinks, but for now I've just decided to write all messages I send directly to the buffered reader queue so they show up. Now it works.

hardbyte commented 8 years ago

Original comment by Mike Molt (Bitbucket: M_Molt, GitHub: Unknown):


I've noticed the same thing...messages sent do not seem to end up in the queue. I'd like to see all messages on the bus, not just the ones received by other hardware.

I'm confused though as candump shows all messages.

altendky commented 7 years ago

Two issues with the option of just opening another connection.

  1. PCANBasic (in Windows) only allows one connection to the hardware
  2. Since message objects don't contain tx/rx information you won't be able to differentiate between whether your first connection sent any given message vs. any other program did so. Or even just whether the adapter sent the message vs. received the message from the physical bus.

This is relevant to me as I am adding logging functionality to my application (different than the script I was writing when this issue was originally opened). Presently I just catch messages that I am sending to python-can and also feed them back to my logging code and accept that there won't be timestamps (well, I could create one that would likely be good enough but no timestamp from PCAN/python-can).