# -*- coding: utf-8 -*- # tec.py import os from threading import Thread, Lock from time import sleep from canusb import * import struct def CAN_Enable(): pass def CAN_Disable(): pass class CAN: # thread safe def __init__(self): self.__can0 = None self.__lock = Lock() self.connect() def connect(self): self.__can0 = CANUSB("/dev/ttyUSB0") @staticmethod def toBytes(x : int): return x.to_bytes(4, byteorder='big', signed=False) @staticmethod def toInt(b) -> int: return int.from_bytes(b, byteorder='big', signed=True) @staticmethod def toFloat(b) -> float: a = bytearray(b) return struct.unpack('