python-can icon indicating copy to clipboard operation
python-can copied to clipboard

SLCAN does not support receive_own_messages

Open Oemm868 opened this issue 2 years ago • 2 comments

I am trying to get my own send messages using the SLCAN Interface. Am I right, that the module does not support this feature?

Oemm868 avatar Jul 26 '22 07:07 Oemm868

Could you provide more information? What object are you referring to? Do you have a minimal script that someone could get started with?

j-c-cook avatar Aug 06 '22 14:08 j-c-cook

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()

Oemm868 avatar Aug 09 '22 09:08 Oemm868

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}")

wallem89 avatar Jun 20 '23 13:06 wallem89

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.

Oemm868 avatar Jul 06 '23 07:07 Oemm868