Skip to content
Permalink
97ec823e1e
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
43 lines (33 sloc) 916 Bytes
#!/usr/bin/env python3
import sys
import can
import cantools
import os
dbcFilename = "data.dbc"
dbcPath = os.path.join( dbcFilename )
canType = "socketcan"
canChannel = "vcan0"
def main():
db = cantools.database.load_file( dbcPath )
# === open can device ===
try:
bus = can.interface.Bus( channel=canChannel, bustype=canType )
except OSError:
print( f"Failed to open {canChannel}" )
return 1
# === main loop ===
recvCount = 0
while recvCount < 1000:
# get can message
msg = bus.recv( 1 )
if msg is None: # nothing recieved
continue
try:
data = db.decode_message( msg.arbitration_id, msg.data )
print( f"{msg.arbitration_id} {data}" )
recvCount += 1
except KeyError:
pass
bus.shutdown()
if __name__ == '__main__':
sys.exit( main() )