def __init__(self, port, datarate=1000000, hostID=2, moduleID=1, debug=False): if type(port) != str: raise TypeError if not port in _CHANNELS: raise ValueError("Invalid port") tmcl_interface.__init__(self, hostID, moduleID, debug) self.__debug = debug self.__channel = port self.__bitrate = datarate try: self.__connection = can.Bus(interface="pcan", channel=self.__channel, bitrate=self.__bitrate) self.__connection.set_filters([{ "can_id": hostID, "can_mask": 0xFFFFFFFF }]) except PcanError as e: self.__connection = None raise ConnectionError("Failed to connect to PCAN bus") from e if self.__debug: print("Opened bus on channel " + self.__channel)
def __init__(self, comPort, datarate=1000000, hostID=2, moduleID=1, debug=True, SerialBaudrate=115200): if type(comPort) != str: raise TypeError tmcl_interface.__init__(self, hostID, moduleID, debug) self.__debug = debug self.__bitrate = datarate self.__Port = comPort self.__serialBaudrate = SerialBaudrate try: self.__connection = can.Bus(interface='slcan', channel=self.__Port, bitrate=self.__bitrate, ttyBaudrate=self.__serialBaudrate) self.__connection.set_filters([{ "can_id": hostID, "can_mask": 0x7F }]) except CanError as e: self.__connection = None raise ConnectionError("Failed to connect to CAN bus") from e if self.__debug: print("Opened slcan bus on channel " + self.__Port)
def __init__(self, port=2, data_rate=None, host_id=2, module_id=1, debug=False, can_mode=CanModeNormal()): del data_rate tmcl_interface.__init__(self, host_id, module_id, debug) tmcl_host_interface.__init__(self, host_id, module_id, debug) self.__silent = Pin(Pin.cpu.B14, Pin.OUT_PP) self.__mode = can_mode self.__flag_recv = False self.__set_mode() CAN.initfilterbanks(14) self.__can = CAN(port, CAN.NORMAL) # PCLK1 = 42 MHz, Module_Bitrate = 1000 kBit/s # With prescaler = 3, bs1 = 11, bs2 = 2 # Sample point at 85.7 %, accuracy = 100 % self.__can.init(CAN.NORMAL, prescaler=3, bs1=11, bs2=2, auto_restart=True) self.__can.setfilter(0, CAN.LIST16, 0, (host_id, host_id, host_id, host_id)) self.__can.rxcallback(0, self.__callback_recv)
def __init__(self, port=None, data_rate=None, host_id=2, module_id=1, debug=False): tmcl_interface.__init__(self, host_id, module_id, debug) tmcl_host_interface.__init__(self, host_id, module_id, debug) self.__buffer = bytearray()
def __init__(self, port=0, data_rate=None, host_id=2, module_id=1, debug=False): del data_rate tmcl_interface.__init__(self, host_id, module_id, debug) tmcl_host_interface.__init__(self, host_id, module_id, debug) self.__vcp = USB_VCP(port) self.__vcp.init() self.__vcp.setinterrupt(-1)
def __init__(self, port, datarate=115200, hostID=2, moduleID=1, debug=True): """ Opens a dummy TMCL connection """ if type(port) != str: raise TypeError del debug tmcl_interface.__init__(self, hostID, moduleID, debug=True) if self._debug: print("Opened dummy TMCL interface on port '" + port + "'") print("\tData rate: " + str(datarate)) print("\tHost ID: " + str(hostID)) print("\tModule ID: " + str(moduleID))
def __init__(self, port=3, data_rate=9600, host_id=2, module_id=1, debug=False): tmcl_interface.__init__(self, host_id, module_id, debug) tmcl_host_interface.__init__(self, host_id, module_id, debug) self.__uart = UART(port, data_rate) self.__uart.init(baudrate=data_rate, bits=8, parity=None, stop=1, timeout=10000, timeout_char=10000)