0
import can

bus = can.Bus(interface='socketcan',
              channel='can0',
              bitrate=500000)

for msg in bus:
    print("{}: {}".format(msg.arbitration_id, msg.data))

As a result of the code above, I get a bytearray with some ascii characters. For example

bytearray(b'@\x1f@\x00\x00\xf4\x00\x00')

bytearray(b'\x00\x90o\x10')

and here below their equivalent.

40 1f 40 00 00 f4 00 00

00 90 6f 10

How can i get pure hex values without "@" and "o" in bytearray?

Reactionic
  • 182
  • 1
  • 2
  • 12
  • 1
    What have you tried? Did you check `binascii.hexlify(bytearray(...))` from [here](https://stackoverflow.com/a/19210442/3727050)? – urban Oct 03 '20 at 12:28
  • 1
    This is just a printing issue as python replaces know hexcodes by known printable characters to shorten the output, f.e. `0x13` => `\n`,`0x10` => `\t` etc. You still have "the hex values" in your bytearray – Patrick Artner Oct 03 '20 at 12:29

0 Answers0