python-can
python-can copied to clipboard
SLCAN does not support receive_own_messages
I am trying to get my own send messages using the SLCAN Interface. Am I right, that the module does not support this feature?
Could you provide more information? What object are you referring to? Do you have a minimal script that someone could get started with?
Hi first, thank you for your reply. I am trying to log and later analyze traffic on the CAN-BUS. It would be very useful, if I could log every msg on the Bus, including the messages I send. I tried using the listener class as described in the Listeners Chapter in the docs (https://python-can.readthedocs.io/en/master/listeners.html#listener). To receive my own messages, there is a Parameter in the can.interface.Bus class called receive_own_messages. I tried enabling this feature for the bus type "slcan" so that the Listener can receive the own send messages. As requested, I added a minimal example to this description.
import can
import time
file = open("log.txt", "a+")
slcanbus = can.interface.Bus(bustype = 'slcan', channel = 'COM5@' + str(115200) , bitrate = 10000, receive_own_messages = True)
#receive_own_messages does not change the behavior of the Interface
slcanbus.channel_info = 'slcan device'
printer = can.Printer(file)
can.Notifier(slcanbus, [printer], timeout=10, loop=None)
message = can.Message(arbitration_id=0x220, data=[0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00], is_extended_id=False, is_fd=False)
slcanbus.send(message, timeout=0.1)#This message is send but not logged from the printer
print("send msg: ", message)#The only way to get "send" messages
time.sleep(5)#waiting some time to gather some messages in the log.txt
file.close()
The receive own messages function does work with a SLCAN, at least with a VSCOM adapter that I am using. I expect the problem might be in the listener. Did you try to receive the message without the notifier?
So try something like this:
for msg in can_bus:
print(f"Message ID {msg.arbitration_id} received with data {msg.data}")
Hi wallem89, I have checked your procedure but had no success. I am checking if it is a hardware problem with my adapter. It seems likely that this problem is caused there. I have a great ambition to solve the problem, but the priority of my project is currently low. I close this issue first, in case it is not a "My Hardware Problem" I open the issue again.