def __call__(callback=None, filter=None, configPath=None, **kwargs): CanConnectionFactory.loadConfiguration(configPath) CanConnectionFactory.checkKwargs(**kwargs) # check config file and load connectionType = CanConnectionFactory.config['can']['interface'] if connectionType == 'virtual': connectionName = CanConnectionFactory.config['virtual'][ 'interfaceName'] if connectionName not in CanConnectionFactory.connections: CanConnectionFactory.connections[ connectionName] = CanConnection( callback, filter, can.interface.Bus(connectionName, bustype='virtual')) else: CanConnectionFactory.connections[connectionName].addCallback( callback) CanConnectionFactory.connections[connectionName].addFilter( filter) return CanConnectionFactory.connections[connectionName] elif connectionType == 'peak': channel = CanConnectionFactory.config['peak']['device'] if channel not in CanConnectionFactory.connections: baudrate = CanConnectionFactory.config['can']['baudrate'] CanConnectionFactory.connections[channel] = CanConnection( callback, filter, pcan.PcanBus(channel, bitrate=baudrate)) else: CanConnectionFactory.connections[channel].addCallback(callback) CanConnectionFactory.connections[channel].addFilter(filter) return CanConnectionFactory.connections[channel] elif connectionType == 'vector': channel = int(CanConnectionFactory.config['vector']['channel']) app_name = CanConnectionFactory.config['vector']['appName'] connectionKey = str("{0}_{1}").format(app_name, channel) if connectionKey not in CanConnectionFactory.connections: baudrate = int(CanConnectionFactory.config['can']['baudrate']) CanConnectionFactory.connections[ connectionKey] = CanConnection( callback, filter, vector.VectorBus(channel, app_name=app_name, data_bitrate=baudrate)) else: CanConnectionFactory.connections[connectionKey].addCallback( callback) CanConnectionFactory.connections[connectionKey].addFilter( filter) return CanConnectionFactory.connections[connectionKey]
def __call__(callback=None, filter=None, configPath=None, **kwargs): CanConnectionFactory.loadConfiguration(configPath) CanConnectionFactory.checkKwargs(**kwargs) # check config file and load connectionType = CanConnectionFactory.config['can']['interface'] if connectionType == 'virtual': connectionName = CanConnectionFactory.config['virtual'][ 'interfaceName'] if connectionName not in CanConnectionFactory.connections: CanConnectionFactory.connections[ connectionName] = CanConnection( callback, filter, can.interface.Bus(connectionName, bustype='virtual')) else: CanConnectionFactory.connections[connectionName].addCallback( callback) CanConnectionFactory.connections[connectionName].addFilter( filter) return CanConnectionFactory.connections[connectionName] elif connectionType == 'peak': channel = CanConnectionFactory.config['peak']['device'] if channel not in CanConnectionFactory.connections: baudrate = CanConnectionFactory.config['can']['baudrate'] CanConnectionFactory.connections[channel] = CanConnection( callback, filter, pcan.PcanBus(channel, bitrate=baudrate)) else: CanConnectionFactory.connections[channel].addCallback(callback) CanConnectionFactory.connections[channel].addFilter(filter) return CanConnectionFactory.connections[channel] elif connectionType == 'vector': channel = int(CanConnectionFactory.config['vector']['channel']) app_name = CanConnectionFactory.config['vector']['appName'] connectionKey = str("{0}_{1}").format(app_name, channel) if connectionKey not in CanConnectionFactory.connections: baudrate = int(CanConnectionFactory.config['can']['baudrate']) CanConnectionFactory.connections[ connectionKey] = CanConnection( callback, filter, vector.VectorBus(channel, app_name=app_name, data_bitrate=baudrate)) else: CanConnectionFactory.connections[connectionKey].addCallback( callback) CanConnectionFactory.connections[connectionKey].addFilter( filter) return CanConnectionFactory.connections[connectionKey] elif connectionType == 'socketcan': if system() == "Linux": channel = CanConnectionFactory.config['socketcan']['channel'] if channel not in CanConnectionFactory.connections: CanConnectionFactory.connections[channel] = CanConnection( callback, filter, socketcan.SocketcanBus(channel=channel)) else: CanConnectionFactory.connections[channel].addCallback( callback) CanConnectionFactory.connections[channel].addFilter(filter) return CanConnectionFactory.connections[channel] else: raise Exception( "SocketCAN on Pythoncan currently only supported in Linux") elif connectionType == 'neovi': channel = int(CanConnectionFactory.config['neovi']['channel']) baudrate = int(CanConnectionFactory.config['can']['baudrate']) CanConnectionFactory.connections[channel] = CanConnection( callback, filter, ics_neovi.NeoViBus(channel, bitrate=baudrate)) return CanConnectionFactory.connections[channel] elif connectionType == 'kvaser': channel = int(CanConnectionFactory.config['kvaser']['channel']) baudrate = int(CanConnectionFactory.config['can']['baudrate']) CanConnectionFactory.connections[channel] = CanConnection( callback, filter, kvaser.canlib.KvaserBus(channel, bitrate=baudrate)) return CanConnectionFactory.connections[channel]