def listen(): logging.basicConfig(level=logging.WARNING) logger = logging.getLogger(__name__) signal.signal(signal.SIGINT, signal_handler) print('Press Ctrl+C to exit') logger.info('starting time_device') # create a server, attach a device, and start a thread to listen for requests instr_server = Vxi11.InstrumentServer() print(instr_server) instr_server.add_device_handler(ServiceDevice, 'SERV') instr_server.add_device_handler(MoveDevice, 'MOVE') instr_server.listen()
def signal_handler(signal, frame): logger.info('Handling Ctrl+C!') instr_server.close() sys.exit(0) class TimeDevice(Vxi11.InstrumentDevice): def device_init(self): print('TimeDevice: device_init()') return if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) signal.signal(signal.SIGINT, signal_handler) print('Press Ctrl+C to exit') logger.info('starting time_device') # create a server, attach a device, and start a thread to listen for requests instr_server = Vxi11.InstrumentServer() #name = 'TIME' name = 'inst1' instr_server.add_device_handler(TimeDevice, name) instr_server.listen() # sleep (or do foreground work) while the Instrument threads do their job while True: time.sleep(1)
"Set the devices idn string etc here. Called immediately after instance creation." self.idn = 'my instrument zero' self.result = 'empty' return class InstrumentRemote_1(InstrumentRemote): def device_init(self): "Set the devices idn string etc here. Called immediately after instance creation." self.idn = 'my instrument one' self.result = 'empty' return if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) signal.signal(signal.SIGINT, signal_handler) print('Press Ctrl+C to exit') logger.info('starting time_device') # create a server, attach a device, and start a thread to listen for requests instr_server = Vxi11.InstrumentServer(InstrumentRemote_0) instr_server.add_device_handler(InstrumentRemote_1, 'inst1') instr_server.listen() # sleep (or do foreground work) while the Instrument threads do their job while True: time.sleep(1)