def __init__(self, parsedURL): if not SocketCANSupported(): raise CANInterface.InterfaceNotSupported( 'Socket module does not support CAN') self._s = socket.socket(socket.AF_CAN, socket.SOCK_RAW, socket.CAN_RAW) self._slaveAddr = CANInterface.XCPSlaveCANAddr(0xFFFFFFFF, 0xFFFFFFFF) self._dumpTraffic = False if parsedURL.netloc == None or parsedURL.netloc == "": dev = 'can0' else: dev = parsedURL.netloc try: self._s.bind((dev, )) except socket.error: self._s.close() raise CANInterface.ConnectFailed() urlQueryDict = urllib.parse.parse_qs(parsedURL.query) if 'filterxcp' in urlQueryDict: self._filterXcp = (urlQueryDict['filterxcp'][0] != "0") else: self._filterXcp = True
def __init__(self, parsedURL): self._icsNetId = None self._cfgdBitrate = None self._dumpTraffic = False self._filter = 0x00000000 self._mask = 0x00000000 if not hasattr(ctypes, 'windll'): raise CANInterface.InterfaceNotSupported('Not a Windows system') try: self._dll = ctypes.windll.icsneo40 except OSError: raise CANInterface.InterfaceNotSupported( 'Loading icsneo40.dll failed') neoDevices = (_ICSNeoDevice * 64)() self._neoObject = None nNeoDevices = ctypes.c_int(64) findResult = self._dll.icsneoFindNeoDevices(0xFFFFFFFF, neoDevices, ctypes.byref(nNeoDevices)) if findResult != 1: raise CANInterface.ConnectFailed('Finding ICS devices failed') splitPath = parsedURL.path.split('/') if len(splitPath) != 3: raise CANInterface.ConnectFailed( 'Invalid ICS device path \'' + parsedURL.path + '\'; path is ics:<devtype>/<dev-index>/<net-id>') try: devTypeMask = _ICS_TYPE_STRING_MASKS[splitPath[0]] except KeyError: raise CANInterface.ConnectFailed('Invalid ICS device type \'' + splitPath[0] + '\'') try: devIdx = int(splitPath[1]) except ValueError: raise CANInterface.ConnectFailed('Invalid ICS device index \'' + splitPath[1] + '\'') try: self._icsNetId = _ICS_NET_IDS[splitPath[2]] except KeyError: raise CANInterface.ConnectFailed('Invalid ICS net id \'' + splitPath[2]) devOfType = [ dev for dev in neoDevices[0:nNeoDevices.value] if dev.DeviceType & devTypeMask ] if len(devOfType) < devIdx + 1: raise CANInterface.ConnectFailed('ICS device of type \'' + splitPath[0] + '\', index ' + str(devIdx) + ' not found') sys.stderr.write('Connecting to ' + _ICSDevTypeStr(neoDevices[0].DeviceType) + ' #' + str(devIdx) + '\n') netIDs = (ctypes.c_ubyte * 64)() for i in range(len(netIDs)): netIDs[i] = i tempNeoObject = ctypes.c_int() openResult = self._dll.icsneoOpenNeoDevice( ctypes.byref(devOfType[devIdx]), ctypes.byref(tempNeoObject), netIDs, 1, 0) if openResult != 1: raise CANInterface.ConnectFailed('Opening ICS device failed') self._neoObject = tempNeoObject.value self.setBitrate(CANInterface.URLBitrate(parsedURL)) self._slaveAddr = CANInterface.XCPSlaveCANAddr(0xFFFFFFFF, 0xFFFFFFFF)