def testAutoClose(self): devices = ics.find_devices() for device in devices: ics.open_device(device) del devices # emulate NeoDevice list going out of scope devices = ics.find_devices() for device in devices: ics.open_device(device)
def _find_device(self, type_filter=None, serial=None): if type_filter is not None: devices = ics.find_devices(type_filter) else: devices = ics.find_devices() for device in devices: if serial is None or self.get_serial_number(device) == str(serial): dev = device break else: msg = ['No device'] if type_filter is not None: msg.append('with type {}'.format(type_filter)) if serial is not None: msg.append('with serial {}'.format(serial)) msg.append('found.') raise Exception(' '.join(msg)) return dev
def open_device(index=0): device = None if enable_use_server: # ics.open_device() won't open a device if we have handles open already # so we need to find them and specify which ones to connect to. devices = ics.find_devices() print("Opening Device {} (Open Client handles: {})...".format(dev_name(devices[index]), devices[index].NumberOfClients)) ics.open_device(devices[index]) device = devices[index] else: print("Opening Device...") device = ics.open_device() print("Opened Device %s." % dev_name(device)) return device
def _detect_available_configs(): """Detect all configurations/channels that this interface could currently connect with. :rtype: Iterator[dict] :return: an iterable of dicts, each being a configuration suitable for usage in the interface's bus constructor. """ if ics is None: return [] # TODO: add the channel(s) return [{ 'serial': NeoViBus.get_serial_number(device) } for device in ics.find_devices()]
def _find_device(self, type_filter=None, serial=None): """Returns the first matching device or raises an error. :raise CanInitializationError: If not matching device could be found """ if type_filter is not None: devices = ics.find_devices(type_filter) else: devices = ics.find_devices() for device in devices: if serial is None or self.get_serial_number(device) == str(serial): return device else: msg = ["No device"] if type_filter is not None: msg.append("with type {}".format(type_filter)) if serial is not None: msg.append("with serial {}".format(serial)) msg.append("found.") raise CanInitializationError(" ".join(msg))
def open_dongle(self): #self.close_dongle() # au cas ou le processus etait toujours en vie # On execute le processus setup try: self.device = ics.find_devices() if self.device: self.process1 = Popen(["sudo","./icsscand/icsscand","-D"], stdout=PIPE) time.sleep(1) self.process2 = Popen(["sudo","ifconfig","ics0can0","up"], stdout=PIPE) return 1 else: showerror("No device Found","Veuillez brancher la clé VCAN !") return 0 except: print ("impossible de se connecter") showerror("Erreur de communication","Impossible d'ouvrir la clé VCAN. Assurez vous qu'elle est bien branchée et relancer le logiciel") return O
def _detect_available_configs(): """Detect all configurations/channels that this interface could currently connect with. :rtype: Iterator[dict] :return: an iterable of dicts, each being a configuration suitable for usage in the interface's bus constructor. """ if ics is None: return [] try: devices = ics.find_devices() except Exception as e: logger.debug("Failed to detect configs: %s", e) return [] # TODO: add the channel(s) return [{ 'interface': 'neovi', 'serial': NeoViBus.get_serial_number(device) } for device in devices]
#!/usr/bin/python import ics, sys, getopt, re, string import random, time, sched, threading linenm = 0 startime = time.time() schd = sched.scheduler(time.time, time.sleep) devices = ics.find_devices() msg = ics.SpyMessage() pre_miltm = 0.0 def tx_random_message(chnl=0,msgid=None,tmfm=None): global linenm, startime, devices, msg, msgdtstr, msgcyc, pre_miltm linenm += 1 msg.NetworkID = ics.NETID_HSCAN txch = msg.NetworkID if msgid == None: msg.ArbIDOrHeader = random.randint(0,0x7FF)# message ID else: msg.ArbIDOrHeader = msgid if msgdtstr != None : msgtxstr = re.sub(r'[^0-9a-fA-F]',random.choice(string.hexdigits),msgdtstr) else: msgtxstr = ''.join(random.choice(string.hexdigits) for i in range(random.randint(0,0x07))) if len(msgtxstr) > 12: msgdt = (int('07'), int(msgtxstr[:2],16), int(msgtxstr[2:4],16), int(msgtxstr[4:6],16), int(msgtxstr[6:8],16),
# msg parameter here can also be a tuple of messages ics.transmit_messages(device, msg) def receive_can(device): msgs, error_count = ics.get_messages(device) print("Received {} messages with {} errors.".format( len(msgs), error_count)) for i, m in enumerate(msgs): if m.NetworkID != ics.NETID_HSCAN: continue print('Message #{}\t'.format(i + 1), end='') print('\tArbID: {}\tData: {}'.format(hex(m.ArbIDOrHeader), [hex(x) for x in m.Data])) if __name__ == "__main__": import time # Lets figure out how many are connected to the PC and display it connected_count = len(ics.find_devices()) print("Found {} connected device(s)...".format(connected_count)) tx_dev = open_device(0) rx_dev = open_device(1) transmit_can(tx_dev) receive_can(rx_dev) print("Finished.")
def setUpClass(self): self.devices = ics.find_devices()
def test_find_vcan3(self): devices = ics.find_devices([ ics.NEODEVICE_VCAN3, ]) self.assertTrue(len(devices) == 2)
def test_find_fire2(self): devices = ics.find_devices([ ics.NEODEVICE_FIRE2, ]) self.assertTrue(len(devices) == 2)
def test_default_parameters(self): devices = ics.find_devices() self.assertTrue(len(devices) == 2)
def test_find_fire2_and_vcan3(self): devices = ics.find_devices([ics.NEODEVICE_FIRE2, ics.NEODEVICE_VCAN3]) self.assertTrue(len(devices) == 2)
def setUpClass(self): devices = ics.find_devices(ics.NEODEVICE_FIRE) ics.open_device(devices[0]) ics.open_device(devices[1]) self.dev1 = devices[0] self.dev2 = devices[1]