Esempio n. 1
0
 def main(self, options, args):
     self.progress_visible = (options.loglevel == logging.INFO)
     if options.port == 'TEST':
         data_logger_port, dummy_logger_port = null_modem(
             baudrate=9600, bytesize=serial.EIGHTBITS,
             parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
             timeout=options.timeout, rtscts=True)
         with io.open(
                 os.path.join(os.path.dirname(__file__),
                     'example.xml'), 'r') as bottles_file:
             bottles_xml = fromstring(bottles_file.read())
         self.dummy_logger = DummyLogger(dummy_logger_port, [
             Bottle.from_xml(tostring(bottle))
             for bottle in bottles_xml.findall('bottle')
             ])
     else:
         data_logger_port = serial.Serial(
             options.port, baudrate=9600, bytesize=serial.EIGHTBITS,
             parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
             timeout=options.timeout, rtscts=True)
     self.data_logger = DataLogger(data_logger_port, progress=(
         self.progress_start,
         self.progress_update,
         self.progress_finish,
         ))
Esempio n. 2
0
 def main(self, options, args):
     if options.port == 'TEST':
         self.parser.error('Cannot use TEST serial port with the emulator')
     if not args:
         # Use a default bottles definition file if none was specified
         args = [os.path.join(os.path.dirname(__file__), 'example.xml')]
     if len(args) == 1:
         with io.open(args[0], 'r') as bottles_file:
             bottles_xml = fromstring(bottles_file.read())
     else:
         self.parser.error(
             'You may only specify a single bottles definition file')
     bottles = [
         Bottle.from_xml(tostring(bottle))
         for bottle in bottles_xml.findall('bottle')
     ]
     logging.info('Opening serial port %s' % options.port)
     port = serial.Serial(options.port,
                          baudrate=9600,
                          bytesize=serial.EIGHTBITS,
                          parity=serial.PARITY_NONE,
                          stopbits=serial.STOPBITS_ONE,
                          timeout=5,
                          rtscts=True)
     files_preserve = [port]
     for handler in logging.getLogger().handlers:
         if isinstance(handler, logging.FileHandler):
             files_preserve.append(handler.stream)
     if not options.daemon:
         files_preserve.append(sys.stderr)
     with DaemonContext(
             files_preserve=files_preserve,
             # The following odd construct is to ensure detachment only
             # where sensible (see default setting of detach_process)
             detach_process=None if options.daemon else False,
             stdout=None if options.daemon else sys.stdout,
             stderr=None if options.daemon else sys.stderr,
             signal_map={
                 signal.SIGTERM: self.terminate,
                 signal.SIGINT: self.interrupt,
             }):
         logging.info('Starting emulator loop')
         self.dummy_logger = DummyLogger(port, bottles)
         # Loop around waiting for the dummy logger thread to terminate. If
         # we attempt to simply join() here then the thread blocks and the
         # signal handlers below never get a chance to execute
         try:
             while self.dummy_logger.is_alive():
                 self.dummy_logger.join(0.1)
         except (SystemExit, KeyboardInterrupt) as exc:
             pass
         logging.info('Waiting for emulator loop to finish')
         self.dummy_logger.join()
         logging.info('Exiting')
Esempio n. 3
0
 def connect_logger(self):
     "Handler for the File/Connect action"
     dialog = ConnectDialog(self)
     if dialog.exec_():
         for window in self.ui.mdi_area.subWindowList():
             if isinstance(window.widget(), DataLoggerWindow) and (
                     window.widget().data_logger.port.port
                     == dialog.com_port):
                 self.ui.mdi_area.setActiveSubWindow(window)
                 return
         window = None
         try:
             if dialog.com_port == 'TEST':
                 data_logger_port, dummy_logger_port = null_modem(
                     baudrate=9600,
                     bytesize=serial.EIGHTBITS,
                     parity=serial.PARITY_NONE,
                     stopbits=serial.STOPBITS_ONE,
                     timeout=5,
                     rtscts=True)
                 if self.dummy_logger:
                     # If there's a prior instance of dummy logger (the user
                     # has previously opened and closed a TEST window), tell
                     # it to terminate before we replace it
                     self.dummy_logger.terminated = True
                 with io.open(
                         os.path.join(os.path.dirname(__file__), '..',
                                      'example.xml'), 'r') as bottles_file:
                     bottles_xml = fromstring(bottles_file.read())
                 self.dummy_logger = DummyLogger(dummy_logger_port, [
                     Bottle.from_xml(tostring(bottle))
                     for bottle in bottles_xml.findall('bottle')
                 ])
             else:
                 data_logger_port = serial.Serial(
                     dialog.com_port,
                     baudrate=9600,
                     bytesize=serial.EIGHTBITS,
                     parity=serial.PARITY_NONE,
                     stopbits=serial.STOPBITS_ONE,
                     timeout=5,
                     rtscts=True)
             window = self.ui.mdi_area.addSubWindow(
                 DataLoggerWindow(
                     DataLogger(data_logger_port,
                                progress=(self.progress_start,
                                          self.progress_update,
                                          self.progress_finish))))
             window.show()
         except KeyboardInterrupt:
             if window is not None:
                 window.close()
Esempio n. 4
0
 def bottles(self):
     """
     Return all bottles stored on the connected device.
     """
     if self._bottles is None:
         # Use the GAPB command to retrieve the details of all bottles
         # stored in the device
         data = self._GAPB()
         self._bottles = []
         bottle = ''
         # Split the response into individual bottles and their head line(s)
         for line in data.split('\r')[:-1]:
             if not line.startswith(','):
                 if bottle:
                     self._bottles.append(
                         Bottle.from_string(bottle, logger=self))
                 bottle = line + '\r'
             else:
                 bottle += line + '\r'
         if bottle:
             self._bottles.append(Bottle.from_string(bottle, logger=self))
     return self._bottles
Esempio n. 5
0
 def main(self, options, args):
     if options.port == 'TEST':
         self.parser.error('Cannot use TEST serial port with the emulator')
     if not args:
         # Use a default bottles definition file if none was specified
         args = [os.path.join(os.path.dirname(__file__), 'example.xml')]
     if len(args) == 1:
         with io.open(args[0], 'r') as bottles_file:
             bottles_xml = fromstring(bottles_file.read())
     else:
         self.parser.error(
             'You may only specify a single bottles definition file')
     bottles = [
         Bottle.from_xml(tostring(bottle))
         for bottle in bottles_xml.findall('bottle')
         ]
     logging.info('Opening serial port %s' % options.port)
     port = serial.Serial(
         options.port, baudrate=9600, bytesize=serial.EIGHTBITS,
         parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
         timeout=5, rtscts=True)
     files_preserve = [port]
     for handler in logging.getLogger().handlers:
         if isinstance(handler, logging.FileHandler):
             files_preserve.append(handler.stream)
     if not options.daemon:
         files_preserve.append(sys.stderr)
     with DaemonContext(
             files_preserve=files_preserve,
             # The following odd construct is to ensure detachment only
             # where sensible (see default setting of detach_process)
             detach_process=None if options.daemon else False,
             stdout=None if options.daemon else sys.stdout,
             stderr=None if options.daemon else sys.stderr,
             signal_map={
                 signal.SIGTERM: self.terminate,
                 signal.SIGINT: self.interrupt,
                 }):
         logging.info('Starting emulator loop')
         self.dummy_logger = DummyLogger(port, bottles)
         # Loop around waiting for the dummy logger thread to terminate. If
         # we attempt to simply join() here then the thread blocks and the
         # signal handlers below never get a chance to execute
         try:
             while self.dummy_logger.is_alive():
                 self.dummy_logger.join(0.1)
         except (SystemExit, KeyboardInterrupt) as exc:
             pass
         logging.info('Waiting for emulator loop to finish')
         self.dummy_logger.join()
         logging.info('Exiting')
Esempio n. 6
0
 def bottles(self):
     """
     Return all bottles stored on the connected device.
     """
     if self._bottles is None:
         # Use the GAPB command to retrieve the details of all bottles
         # stored in the device
         data = self._GAPB()
         self._bottles = []
         bottle = ''
         # Split the response into individual bottles and their head line(s)
         for line in data.split('\r')[:-1]:
             if not line.startswith(','):
                 if bottle:
                     self._bottles.append(
                         Bottle.from_string(bottle, logger=self))
                 bottle = line + '\r'
             else:
                 bottle += line + '\r'
         if bottle:
             self._bottles.append(
                 Bottle.from_string(bottle, logger=self))
     return self._bottles
Esempio n. 7
0
 def connect_logger(self):
     "Handler for the File/Connect action"
     dialog = ConnectDialog(self)
     if dialog.exec_():
         for window in self.ui.mdi_area.subWindowList():
             if isinstance(window.widget(), DataLoggerWindow) and (
                     window.widget().data_logger.port.port == dialog.com_port):
                 self.ui.mdi_area.setActiveSubWindow(window)
                 return
         window = None
         try:
             if dialog.com_port == 'TEST':
                 data_logger_port, dummy_logger_port = null_modem(
                     baudrate=9600, bytesize=serial.EIGHTBITS,
                     parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
                     timeout=5, rtscts=True)
                 if self.dummy_logger:
                     # If there's a prior instance of dummy logger (the user
                     # has previously opened and closed a TEST window), tell
                     # it to terminate before we replace it
                     self.dummy_logger.terminated = True
                 with io.open(
                         os.path.join(os.path.dirname(__file__),
                             '..', 'example.xml'), 'r') as bottles_file:
                     bottles_xml = fromstring(bottles_file.read())
                 self.dummy_logger = DummyLogger(dummy_logger_port, [
                     Bottle.from_xml(tostring(bottle))
                     for bottle in bottles_xml.findall('bottle')
                     ])
             else:
                 data_logger_port = serial.Serial(
                     dialog.com_port, baudrate=9600, bytesize=serial.EIGHTBITS,
                     parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
                     timeout=5, rtscts=True)
             window = self.ui.mdi_area.addSubWindow(
                 DataLoggerWindow(DataLogger(
                     data_logger_port, progress=(
                         self.progress_start,
                         self.progress_update,
                         self.progress_finish
                         ))))
             window.show()
         except KeyboardInterrupt:
             if window is not None:
                 window.close()
Esempio n. 8
0
    def bottle(self, serial):
        """
        Return a bottle with a specific serial number.

        `serial` : the serial number of the bottle to retrieve
        """
        # Check for the specific serial number without refreshing the entire
        # list. If it's there, return it from the list.
        if self._bottles is not None:
            for bottle in self._bottles:
                if bottle.serial == serial:
                    return bottle
        # Otherwise, use the GPRB to retrieve individual bottle details. Note
        # that we DON'T add it to the list in this case as the list may be
        # uninitialized at this point. Even if we initialized it, a future call
        # would have no idea the list was only partially populated
        data = self._GPRB(serial)
        return Bottle.from_string(data, logger=self)
Esempio n. 9
0
    def bottle(self, serial):
        """
        Return a bottle with a specific serial number.

        `serial` : the serial number of the bottle to retrieve
        """
        # Check for the specific serial number without refreshing the entire
        # list. If it's there, return it from the list.
        if self._bottles is not None:
            for bottle in self._bottles:
                if bottle.serial == serial:
                    return bottle
        # Otherwise, use the GPRB to retrieve individual bottle details. Note
        # that we DON'T add it to the list in this case as the list may be
        # uninitialized at this point. Even if we initialized it, a future call
        # would have no idea the list was only partially populated
        data = self._GPRB(serial)
        return Bottle.from_string(data, logger=self)