writing pgn hexdecimal .i want to write pgn as hexdecimal in canking .by using canwrite method but it is writing as 00000 instead of 1F801
Writing pgn hexdecimal .i want to write pgn as hexdecimal in canking .
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Jithu ThomasRank #437 · 5.7K reputationPosted Jan 18, 2024, 8:00 AM EST
Please try this,
# Assuming you have a can object, for example using python-can library
import can
# PGN in hexadecimal format (1F801)
pgn_hex = 0x1F801
# Convert PGN to bytes
pgn_bytes = pgn_hex.to_bytes(3, byteorder='big')
# Create a CAN message with the PGN as the identifier
can_message = can.Message(arbitration_id=pgn_hex, data=pgn_bytes, extended_id=True)
# Now, you can use your CAN write method to send the message
# For example, if you are using python-can library:
# bus.send(can_message)
if it is usefull please accept the answer.