Exemplo n.º 1
0
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
Exemplo n.º 2
0
    def __init__(self, channel, can_filters=None, **config):
        """

        :param int channel:
            The Channel id to create this bus with.
        :param list can_filters:
            See :meth:`can.BusABC.set_filters` for details.

        :param use_system_timestamp:
            Use system timestamp for can messages instead of the hardware time
            stamp
        :param str serial:
            Serial to connect (optional, will use the first found if not
            supplied)
        :param int bitrate:
            Channel bitrate in bit/s. (optional, will enable the auto bitrate
            feature if not supplied)
        """
        if ics is None:
            raise ImportError('Please install python-ics')

        super(NeoViBus, self).__init__(channel=channel,
                                       can_filters=can_filters,
                                       **config)

        logger.info("CAN Filters: {}".format(can_filters))
        logger.info("Got configuration of: {}".format(config))

        self._use_system_timestamp = bool(
            config.get('use_system_timestamp', False))
        try:
            channel = int(channel)
        except ValueError:
            raise ValueError('channel must be an integer')

        type_filter = config.get('type_filter')
        serial = config.get('serial')
        self.dev = self._find_device(type_filter, serial)
        ics.open_device(self.dev)

        if 'bitrate' in config:
            ics.set_bit_rate(self.dev, config.get('bitrate'), channel)

        self.channel_info = '%s %s CH:%s' % (
            self.dev.Name, self.get_serial_number(self.dev), channel)
        logger.info("Using device: {}".format(self.channel_info))

        self.rx_buffer = deque()
        self.network = channel if channel is not None else None
Exemplo n.º 3
0
 def testOpenCloseByFirstFound(self):
     # Open by first found
     first_devices = []
     for x in range(len(self.devices)):
         first_devices.append(ics.open_device())
     # Close by API
     for device in first_devices:
         ics.close_device(device)
Exemplo n.º 4
0
    def __init__(self, channel, can_filters=None, **config):
        """
        :param channel:
            The channel ids to create this bus with.
            Can also be a single integer, netid name or a comma separated
            string.
        :type channel: int or str or list(int) or list(str)
        :param list can_filters:
            See :meth:`can.BusABC.set_filters` for details.
        :param bool use_system_timestamp:
            Use system timestamp for can messages instead of the hardware time
            stamp
        :param str serial:
            Serial to connect (optional, will use the first found if not
            supplied)
        :param int bitrate:
            Channel bitrate in bit/s. (optional, will enable the auto bitrate
            feature if not supplied)
        :param bool fd:
            If CAN-FD frames should be supported.
        :param int data_bitrate:
            Which bitrate to use for data phase in CAN FD.
            Defaults to arbitration bitrate.
        """
        if ics is None:
            raise ImportError('Please install python-ics')

        super(NeoViBus, self).__init__(
            channel=channel, can_filters=can_filters, **config)

        logger.info("CAN Filters: {}".format(can_filters))
        logger.info("Got configuration of: {}".format(config))

        if isinstance(channel, (list, tuple)):
            self.channels = channel
        elif isinstance(channel, int):
            self.channels = [channel]
        else:
            # Assume comma separated string of channels
            self.channels = [ch.strip() for ch in channel.split(',')]
        self.channels = [NeoViBus.channel_to_netid(ch) for ch in self.channels]

        type_filter = config.get('type_filter')
        serial = config.get('serial')
        self.dev = self._find_device(type_filter, serial)
        ics.open_device(self.dev)

        if 'bitrate' in config:
            for channel in self.channels:
                ics.set_bit_rate(self.dev, config.get('bitrate'), channel)

        fd = config.get('fd', False)
        if fd:
            if 'data_bitrate' in config:
                for channel in self.channels:
                    ics.set_fd_bit_rate(
                        self.dev, config.get('data_bitrate'), channel)

        self._use_system_timestamp = bool(
            config.get('use_system_timestamp', False)
        )

        self.channel_info = '%s %s CH:%s' % (
            self.dev.Name,
            self.get_serial_number(self.dev),
            self.channels
        )
        logger.info("Using device: {}".format(self.channel_info))

        self.rx_buffer = deque()
Exemplo n.º 5
0
        elif opt in ("-i","--id"):
            msgid = int(arg,16)
        elif opt in ("-t","--cycletime"):
            msgcyc = float(arg)
        elif opt in ("-d", "--datafield"):
            msgdtstr = str(arg)
            if len(msgdtstr) > 14:
                msgdtstr = msgdtstr[0:14]
        elif opt in ("-f", "--timeformat"):
            tmfm = str(arg)
            if len(tmfm) > 5:
                tmfm = tmfm[0:5]
        elif opt in ("-n", "--countnum"):
            txcnt = int(arg)
   
    ics.open_device(devices[chnl])
    if re.search('abs',tmfm,re.IGNORECASE):
        print('Count\tSysTime(abs)\tMsgID\tData',flush=True)
    elif re.search('rel',tmfm,re.IGNORECASE):
        print('Count\tSysTime(rel)\tMsgID\tData',flush=True)
    else:
        print('Count\tSysTime(abs)\tMsgID\tData',flush=True)

    while True:
        if txcnt <= 0:
            tx_cycle_message(chnl,msgid,msgcyc,tmfm)
        elif txcnt > i:
            i += 1
            tx_cycle_message(chnl,msgid,msgcyc,tmfm)
        else:
            exit()
Exemplo n.º 6
0
    def __init__(self, channel, can_filters=None, **kwargs):
        """
        :param channel:
            The channel ids to create this bus with.
            Can also be a single integer, netid name or a comma separated
            string.
        :type channel: int or str or list(int) or list(str)
        :param list can_filters:
            See :meth:`can.BusABC.set_filters` for details.
        :param bool receive_own_messages:
            If transmitted messages should also be received by this bus.
        :param bool use_system_timestamp:
            Use system timestamp for can messages instead of the hardware time
            stamp
        :param str serial:
            Serial to connect (optional, will use the first found if not
            supplied)
        :param int bitrate:
            Channel bitrate in bit/s. (optional, will enable the auto bitrate
            feature if not supplied)
        :param bool fd:
            If CAN-FD frames should be supported.
        :param int data_bitrate:
            Which bitrate to use for data phase in CAN FD.
            Defaults to arbitration bitrate.
        :param override_library_name:
            Absolute path or relative path to the library including filename.
        """
        if ics is None:
            raise ImportError("Please install python-ics")

        super().__init__(channel=channel, can_filters=can_filters, **kwargs)

        logger.info("CAN Filters: {}".format(can_filters))
        logger.info("Got configuration of: {}".format(kwargs))

        if "override_library_name" in kwargs:
            ics.override_library_name(kwargs.get("override_library_name"))

        if isinstance(channel, (list, tuple)):
            self.channels = channel
        elif isinstance(channel, int):
            self.channels = [channel]
        else:
            # Assume comma separated string of channels
            self.channels = [ch.strip() for ch in channel.split(",")]
        self.channels = [NeoViBus.channel_to_netid(ch) for ch in self.channels]

        type_filter = kwargs.get("type_filter")
        serial = kwargs.get("serial")
        self.dev = self._find_device(type_filter, serial)

        with open_lock:
            ics.open_device(self.dev)

        if "bitrate" in kwargs:
            for channel in self.channels:
                ics.set_bit_rate(self.dev, kwargs.get("bitrate"), channel)

        fd = kwargs.get("fd", False)
        if fd:
            if "data_bitrate" in kwargs:
                for channel in self.channels:
                    ics.set_fd_bit_rate(self.dev, kwargs.get("data_bitrate"),
                                        channel)

        self._use_system_timestamp = bool(
            kwargs.get("use_system_timestamp", False))
        self._receive_own_messages = kwargs.get("receive_own_messages", True)

        self.channel_info = "%s %s CH:%s" % (
            self.dev.Name,
            self.get_serial_number(self.dev),
            self.channels,
        )
        logger.info("Using device: {}".format(self.channel_info))

        self.rx_buffer = deque()
Exemplo n.º 7
0
import ics
import time


def print_device_status(s):
    for attr_name in dir(s):
        if attr_name.startswith('_'):
            continue
        print(attr_name, " " * (35 - len(attr_name)), getattr(s, attr_name))
        if attr_name.upper() in ('FIRE2STATUS', 'VCAN4STATUS'):
            print()
            print_device_status(getattr(s, attr_name))
            print()


d = ics.open_device()
time.sleep(0.250)  # Give the device time to send the frame
s = ics.get_device_status(d)
print_device_status(s)
Exemplo n.º 8
0
 def setUpClass(self):
     #input() # for debugging purposes
     self.dev1 = ics.open_device()
     self._clear_coremini(self)
Exemplo n.º 9
0
    chnl = 0
    tmfm = 'absolute'
    try:
        opts, args = getopt.getopt(sys.argv[1:],"hc:f:",["channel=","timeformat="])
    except getopt.GetoptError:
        usage()
        exit()
    for opt, arg in opts:
        if opt == '-h':
            usage()
            exit()
        elif opt in ("-c", "--channel"):
            chnl = int(arg)
        elif opt in ("-f", "--timeformat"):
            tmfm = str(arg)
            if len(tmfm) > 5:
                tmfm = tmfm[0:5]

    device = devices[chnl]
    ics.open_device(device)
    if re.search('abs',tmfm,re.IGNORECASE):
        print('Time(abs)\tCAN\tID\tDir\tType\tDLC\tData',flush=True)
        dump_can_chnl(chnl,1)
    elif re.search('rel',tmfm,re.IGNORECASE):
        print('Time(rel)\tCAN\tID\tDir\tType\tDLC\tData',flush=True)
        dump_can_chnl(chnl,0)
    else:
        print('Time(abs)\tCAN\tID\tDir\tType\tDLC\tData',flush=True)
        dump_can_chnl(chnl,1)

Exemplo n.º 10
0
 def testOpenClose100Times(self):
     for x in range(100):
         ics.open_device(self.devices[0])
         ics.close_device(self.devices[0])
Exemplo n.º 11
0
 def testOpenCloseBySerial(self):
     # Open by serial number
     for device in self.devices:
         d = ics.open_device(device.SerialNumber)
         ics.close_device(d)
Exemplo n.º 12
0
 def testOpenCloseByFind(self):
     # Open by ics.NeoDevice
     for device in self.devices:
         ics.open_device(device)
         ics.close_device(device)
Exemplo n.º 13
0
 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]