xsnippet logotype

xsnippet

whatever [ Python ]

by Guest /
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python

import can
import sys
import time

def main(cmd):
    print('Command to be sent: {}'.format(' '.join(cmd)))
    _id = int(cmd.pop(0), 16)
    print('_id: {}'.format(_id))
    hexcmd = [chr(int(i)) for i in cmd]
    print('Data: ', hexcmd)
    bus = can.interface.Bus(channel='ics0can1', bustype='socketcan_ctypes')
    msg = can.Message(arbitration_id=_id, data=hexcmd, extended_id=False)
    bus.send(msg)

if __name__ == '__main__':
    main(sys.argv[1:])