コード例 #1
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')
コード例 #2
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,
         ))
コード例 #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()
コード例 #4
0
ファイル: oxitopemu.py プロジェクト: waveform80/oxitopped
 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')
コード例 #5
0
ファイル: oxitopemu.py プロジェクト: waveform80/oxitopped
class EmuApplication(OxiTopApplication):
    """
    %prog [options] bottles-xml

    This utility emulates an OxiTop OC110 data dummy_logger for the purposes of
    easy development without access to an actual OC110. The bottle data served
    by the emulator is specified in an XML-based file which can be generated
    using oxitopdump or oxitopview with a real unit.
    """

    def __init__(self):
        super(EmuApplication, self).__init__()
        self.handle_sigint = None
        self.handle_sigterm = None
        self.parser.set_defaults(
            daemon=False,
            )
        self.parser.add_option(
            '-d', '--daemon', dest='daemon', action='store_true',
            help='if specified, start the emulator as a background daemon')

    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')

    def terminate(self, signum, frame):
        logging.info('Received SIGTERM')
        self.dummy_logger.terminated = True

    def interrupt(self, signum, frame):
        logging.info('Received SIGINT')
        self.dummy_logger.terminated = True
コード例 #6
0
class EmuApplication(OxiTopApplication):
    """
    %prog [options] bottles-xml

    This utility emulates an OxiTop OC110 data dummy_logger for the purposes of
    easy development without access to an actual OC110. The bottle data served
    by the emulator is specified in an XML-based file which can be generated
    using oxitopdump or oxitopview with a real unit.
    """
    def __init__(self):
        super(EmuApplication, self).__init__()
        self.handle_sigint = None
        self.handle_sigterm = None
        self.parser.set_defaults(daemon=False, )
        self.parser.add_option(
            '-d',
            '--daemon',
            dest='daemon',
            action='store_true',
            help='if specified, start the emulator as a background daemon')

    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')

    def terminate(self, signum, frame):
        logging.info('Received SIGTERM')
        self.dummy_logger.terminated = True

    def interrupt(self, signum, frame):
        logging.info('Received SIGINT')
        self.dummy_logger.terminated = True