def _create_devices(self): logger.debug("creando dispositivos") self.printer = Printer(self.buffer) self.power_manager = PowerManager(self.buffer) self.rfid = RFID(self.buffer) self.backlight = Backlight(self.buffer) self.fancoolers = FanCoolers(self.buffer) self.pir = PIR(self.buffer) self.device = Device(self.buffer)
if not port: port = '/tmp/ttyACM0' # pruebo un puerto remoto channel = Serial(port, timeout=3) if not channel.isOpen(): channel.open() channel.flushInput() channel.flushOutput() # Objetos disponibles dev = Device(channel) agent = Agent(channel) batt = PowerManager(channel) printer = Printer(channel) rfid = RFID(channel) backlight = Backlight(channel) fan = FanCoolers(channel) pir = PIR(channel) buzzer = Buzzer(channel) print """\nObjetos disponibles: - agent - batt - printer - rfid - backlight - fan - pir - buzzer Funcion r() lee los mensajes en el channel."""
def test_eventos(): channel = init_channel() device = Device(channel) agent = Agent(channel) batt = PowerManager(channel) printer = Printer(channel) rfid = RFID(channel) pir = PIR(channel) batt.register_battery_discharge() batt.register_battery_unplugged() batt.register_switch_ac() batt.register_battery_empty() batt.register_battery_level_critical() batt.register_battery_level_max() batt.register_battery_level_min() printer.register_paper_eject() printer.register_paper_start() printer.register_paper_inserted() printer.register_paper_out_1() printer.register_paper_out_2() printer.register_lever_open() pir.register_detected() pir.register_not_detected() rfid.register_new_tag(100) try: while True: event = agent.list_events() if event is not None: if hasattr(event[0], "event"): event = event[0].event #print "eventos", event status = batt.get_status()[0]['batt_data'][0] #print status print "remaining %s/%s (%s)" % (status['remaining'], status['full_charge'], status['corriente']) ret = device.read() if ret is not None: print ret print "device", device._devices.get(ret[1]) print device.get_device_instance(ret[1])._command_dict.get( ret[2]) #sleep(2) except KeyboardInterrupt: print "Desregistrando eventos" batt.unregister_battery_discharge() batt.unregister_battery_unplugged() batt.unregister_switch_ac() batt.unregister_battery_empty() batt.unregister_battery_level_critical() batt.unregister_battery_level_max() batt.unregister_battery_level_min() printer.unregister_paper_eject() printer.unregister_paper_start() printer.unregister_paper_inserted() printer.unregister_paper_out_1() printer.unregister_paper_out_2() printer.unregister_lever_open() pir.unregister_detected() pir.unregister_not_detected() rfid.unregister_new_tag() sleep(2) print "eventos", agent.list_events()[0].event agent.unregister_events() sleep(2) print "eventos", agent.list_events()[0].event
def loop(): """Loop de pruebas de los comandos.""" channel = StringIO() device = Device(channel) print "Enviando comandos de bateria" batt = PowerManager(channel) print "\nEnviando Comando consulta fuente de bateria actual (7.1)" batt.get_power_source() #read_and_process(device, channel) print "\nEnviando Comando consulta baterias conectadas (7.2)" batt.get_connected_batteries() read_and_process(device, channel) print "\nEnviando Comando consulta estado de funcionamiento (7.3)" batt.get_status() read_and_process(device, channel) print "\nEnviando Comando consulta de parametros de diseño (7.4)" batt.get_params() read_and_process(device, channel) print "\nEnviando Comando consulta funcionamiento convertidor DC/DC (7.5)" batt.check_voltages() read_and_process(device, channel) print "\n Enviando comando seleccion de modo de control de modo de alimentacion (7.6)" batt.power_source_control_mode() read_and_process(device, channel) print "\n Enviando comando de control de modo de alimentacion (7.7)" batt.power_source_control(True, True, True, True) read_and_process(device, channel) print "\nRegistrando evento bateria descargandose (7.8)" batt.register_battery_discharge() read_and_process(device, channel) print "\nRegistrando evento bateria nivel minimo (7.9)" batt.register_battery_level_min() read_and_process(device, channel) print "\nRegistrando evento bateria nivel critico (7.10)" batt.register_battery_level_critical() read_and_process(device, channel) print "\nRegistrando evento bateria nivel maximo (7.11)" batt.register_battery_level_max() read_and_process(device, channel) print "\nRegistrando evento switch AC (7.12)" batt.register_switch_ac() read_and_process(device, channel) print "\nRegistrando evento Bateria Desconectada (7.13)" batt.register_battery_unplugged() read_and_process(device, channel) print "\nRegistrando evento Bateria Agotada (7.14)" batt.register_battery_empty() read_and_process(device, channel) return print "\n---------\nEnviando comandos de impresion" printer = Printer(channel) print "\nEnviando comando consulta estado sensores (8.1)" printer.get_status() read_and_process(device, channel) print "\nEnviando comando mover motor (8.2)" printer.move(500) read_and_process(device, channel) print "\nEnviando comando (8.3)" printer.load_buffer("\x00\x01" * 500) read_and_process(device, channel) print "\nEnviando comando (8.4)" printer.do_print() read_and_process(device, channel) print "\nEnviando comando (8.5)" printer.clear_buffer() read_and_process(device, channel) print "\nEnviando comando (8.6)" printer.paper_eject() read_and_process(device, channel) print "\nEnviando comando (8.7)" printer.paper_start() read_and_process(device, channel) print "\nEnviando comando (8.8)" printer.get_autofeed() read_and_process(device, channel) print "\nEnviando comando (8.9)" printer.set_autofeed(-120) read_and_process(device, channel) print "\nEnviando comando (8.10)" printer.register_paper_inserted() read_and_process(device, channel) print "\nEnviando comando (8.11)" printer.register_paper_out_1() read_and_process(device, channel) print "\nEnviando comando (8.12)" printer.register_paper_out_2() read_and_process(device, channel) print "\nEnviando comando (8.13)" printer.register_lever_open read_and_process(device, channel) print "\n---------\nEnviando comandos de RFID" rfid = RFID(channel) print "\nEnviando comando obtener tags (9.1)" rfid.get_tags() read_and_process(device, channel) print "\nEnviando comando seleccionar tag(9.2)" rfid.select_tag("\x00\x01\x02\x03\x04\x05\x06\x07") read_and_process(device, channel) print "\nEnviando comando leer bloque(9.3)" rfid.read_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1) read_and_process(device, channel) print "\nEnviando comando leer multiples bloques (9.4)" rfid.read_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 5) read_and_process(device, channel) print "\nEnviando comando escribir bloque (9.5)" rfid.write_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1, "\x00\x01\x02\x03") read_and_process(device, channel) print "\nEnviando comando escribir bloques (9.6)" blocks = [ "\x00\x01\x02\x03", "\x00\x01\x02\x03", "\x00\x01\x02\x03", "\x00\x01\x02\x03" ] rfid.write_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 4, blocks) read_and_process(device, channel) print "\nEnviando comando consulta tag solo lectura (9.7)" rfid.is_read_only("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 4) read_and_process(device, channel) print "\nEnviando comando establecer tag de solo lectura (9.8)" rfid.set_read_only_block("\x00\x01\x02\x03\x04\x05\x06\x07", 1) read_and_process(device, channel) print "\nEnviando comando establecer tag de solo lectura (9.9)" rfid.set_read_only_blocks("\x00\x01\x02\x03\x04\x05\x06\x07", 1, 5) read_and_process(device, channel) print "\nEnviando comando limpiar buffer(9.10)" rfid.clear_buffer() read_and_process(device, channel) print "\nEnviando comando consulta nivel de potencia antena (9.11)" rfid.get_antenna_level() read_and_process(device, channel) print "\nEnviando comando establecer nivel de potencia antena (9.12)" rfid.set_antenna_level(255) read_and_process(device, channel) # print "\nEnviando comando establecer led de encendido maquina ON/OFF (9.13)" # rfid.set_power_led(True) # read_and_process(device, channel) print "\nEnviando evento new tag" rfid.register_new_tag(100) read_and_process(device, channel) print "\n---------\nEnviando comandos de Backlight" backlight = Backlight(channel) print "\nEnviando comando obtener brillo (10.1)" backlight.get_brighthess() read_and_process(device, channel) print "\nEnviando comando establecer brillo (10.2)" backlight.set_brighthess(100, True) read_and_process(device, channel) print "\nEnviando obtener Backlight encendido/apagado (10.3)" backlight.get_status() read_and_process(device, channel) print "\nEnviando obtener Backlight encendido/apagado (10.4)" backlight.set_status(True) read_and_process(device, channel) print "\n---------\nEnviando comandos de Fan Coolers" fan = FanCoolers(channel) print "\nEnviando comando obtener velocidad (11.1)" fan.get_speed() read_and_process(device, channel) print "\nEnviando comando obtener velocidad (11.2)" fan.set_speed(50) read_and_process(device, channel) print "\n---------\nEnviando comandos de PIR" pir = PIR(channel) print "\nEnviando comando obtener velocidad (12.1)" pir.register_detected() read_and_process(device, channel) print "\nEnviando comando obtener velocidad (12.2)" pir.register_not_detected() read_and_process(device, channel) print "\n---------\nEnviando comandos de Buzzer" buzzer = Buzzer(channel) print "\nEnviando comando obtener velocidad (11.1)" buzzer.buzz("\x00\x50") read_and_process(device, channel)