I have a cangen process running that's sending out CAN traffic 1/second. (cangen can1 -D 1021324354c0ffee -L 8). I've connected my can1 and can0 ports together, and I can see that can1 traffic on can0 in my python3 program just fine, via
can_interface='can0'
bus=can.interface.Bus(can_interface, bustype='socketcan_native')
while True:
msg=bus.recv()
print(msg)
This causes a line like the following to print on stdout: Timestamp: 1606022413.287309 ID: 0746 S DLC: 8 11 22 33 44 de ad be ef Channel: can0
I want to send that 'msg' information as a UDP packet on my network. But I still don't understand the strings-vs-bytes distinction of python, so the obvious doesn't work:
sent = sock.sendto(msg, server_address)
What transmogrification must I do to the CAN msg to make it suitable for use as an arg to sendto()?
I do realize that msg is really (whatever python calls) a structure, and I can access the various components of msg via msg.data, msg.timestamp, and msg.dlc. If I could take all of these msg components and concatenate them into a string and then send that, or a hexified version of that, I'd be happy. Or maybe some such string already exists, and I just need to convert that string into bytes to make sendto() happy. I've tried all sorts of permutations to no avail. Help?