Пример #1
0
def arduinoRelayMfcControllerWebserver():
    global ARMC
    ARMC = None

    parser = argparse.ArgumentParser(description='Arduino Relay Mfc Controller Webserver')
    parser.add_argument('-d', '--debug',
                        help='start the server in local-only debug mode',
                        action='store_true')
    args = parser.parse_args()

    server = 'remote'
    debug = False
    if args.debug:
        server = 'local'
        debug = True

    # Open connection to device
    arduino_device_ports = findArduinoDevicePorts()
    arduino_relay_mfc_controller_port = None
    for port in arduino_device_ports:
        port_info = arduino_device_ports[port]
        if isArduinoRelayMfcControllerPortInfo(port_info):
            arduino_relay_mfc_controller_port = port

    if arduino_relay_mfc_controller_port is not None:
        ARMC = ArduinoRelayMfcController(port=arduino_relay_mfc_controller_port)

    if server == 'local':
        print(' * using debug server - localhost only')
        app.run(port=network_port,debug=debug)
    else:
        print(' * using builtin server - remote access possible')
        app.run(host='0.0.0.0',port=network_port)
Пример #2
0
def findArduinoOlfactometerPort(baudrate=None,
                                serial_number=None,
                                try_ports=None,
                                debug=DEBUG):
    arduino_olfactometer_ports = findArduinoOlfactometerPorts(
        baudrate=baudrate,
        serial_number=serial_number,
        try_ports=try_ports,
        debug=debug)
    if len(arduino_olfactometer_ports) == 1:
        return arduino_olfactometer_ports.keys()[0]
    elif len(arduino_olfactometer_ports) == 0:
        arduino_device_ports = findArduinoDevicePorts(
            baudrate=baudrate,
            model_number=DEVICE_MODEL_NUMBER,
            serial_number=serial_number,
            try_ports=try_ports,
            debug=debug)
        err_str = 'Could not find Arduino olfactometers. Check connections and permissions.\n'
        err_str += 'Tried ports: ' + str(arduino_device_ports)
        raise RuntimeError(err_str)
    else:
        err_str = 'Found more than one Arduino olfactometer. Specify port or serial_number.\n'
        err_str += 'Matching ports: ' + str(arduino_olfactometer_ports)
        raise RuntimeError(err_str)
Пример #3
0
def findArduinoOlfactometerPorts(baudrate=None,
                                 serial_number=None,
                                 try_ports=None,
                                 debug=DEBUG):
    arduino_device_ports = findArduinoDevicePorts(
        baudrate=baudrate,
        model_number=DEVICE_MODEL_NUMBER,
        serial_number=serial_number,
        try_ports=try_ports,
        debug=debug)

    if type(serial_number) is int:
        serial_number = [serial_number]

    arduino_olfactometer_ports = {}
    for port in arduino_device_ports:
        try:
            dev_serial_number = arduino_device_ports[port]['serial_number']
        except KeyError:
            break
        if (serial_number is None) or (dev_serial_number in serial_number):
            arduino_olfactometer_ports[port] = {
                'serial_number': dev_serial_number
            }
    return arduino_olfactometer_ports
Пример #4
0
    def __init__(self,*args,**kwargs):
        t_start = time.time()
        pwm_controller_port = None
        olfactometer_ports = []
        current_controller_port = None
        self.pwm_controller = None
        self.olfactometers = None
        self.current_controller = None
        arduino_device_ports = findArduinoDevicePorts()
        for port in arduino_device_ports:
            port_info = arduino_device_ports[port]
            if isPwmControllerPortInfo(port_info):
                pwm_controller_port = port
            elif isOlfactometerPortInfo(port_info):
                olfactometer_ports.append(port)
            elif isCurrentControllerPortInfo(port_info):
                current_controller_port = port
        if pwm_controller_port is not None:
            self.pwm_controller = PwmController(port=pwm_controller_port)
            self.pwm_controller.setDeviceName('pwm_controller')
        if len(olfactometer_ports) != 0:
            self.olfactometers = ArduinoOlfactometers(use_ports=olfactometer_ports)
            self.olfactometers.sortBySerialNumber()
            try:
                self.olfactometers[0].setDeviceName('olfactometer_odor1')
                self.olfactometers[1].setDeviceName('olfactometer_odor2')
                self.olfactometers[2].setDeviceName('olfactometer_ethanol')
            except IndexError:
                pass
        if current_controller_port is not None:
            self.current_controller = CurrentController(port=current_controller_port)
            self.current_controller.setDeviceName('current_controller')

        t_end = time.time()
        print('Initialization time =', (t_end - t_start))
def findCurrentControllerPorts(baudrate=None, serial_number=None, try_ports=None, debug=DEBUG):
    arduino_device_ports = findArduinoDevicePorts(baudrate=baudrate,
                                                  model_number=DEVICE_MODEL_NUMBER,
                                                  serial_number=serial_number,
                                                  try_ports=try_ports,
                                                  debug=debug)

    if type(serial_number) is int:
        serial_number = [serial_number]

    controller_ports = {}
    for port in arduino_device_ports:
        try:
            dev_serial_number = arduino_device_ports[port]['serial_number']
        except KeyError:
            break
        if (serial_number is None) or (dev_serial_number in serial_number):
            controller_ports[port] = {'serial_number': dev_serial_number}
    return controller_ports
def findCurrentControllerPort(baudrate=None, serial_number=None, try_ports=None, debug=DEBUG):
    controller_ports = findCurrentControllerPorts(baudrate=baudrate,
                                                  serial_number=serial_number,
                                                  try_ports=try_ports,
                                                  debug=debug)
    if len(controller_ports) == 1:
        return controller_ports.keys()[0]
    elif len(controller_ports) == 0:
        arduino_device_ports = findArduinoDevicePorts(baudrate=baudrate,
                                                      model_number=DEVICE_MODEL_NUMBER,
                                                      serial_number=serial_number,
                                                      try_ports=try_ports,
                                                      debug=debug)
        err_str = 'Could not find current controller. Check connections and permissions.\n'
        err_str += 'Tried ports: ' + str(arduino_device_ports)
        raise RuntimeError(err_str)
    else:
        err_str = 'Found more than one current controller. Specify port or serial_number.\n'
        err_str += 'Matching ports: ' + str(controller_ports)
        raise RuntimeError(err_str)
Пример #7
0
def findArduinoRelayControllerPort(baudrate=None, serial_number=None, try_ports=None, debug=DEBUG):
    arduino_relay_controller_ports = findArduinoRelayControllerPorts(
        baudrate=baudrate, serial_number=serial_number, try_ports=try_ports, debug=debug
    )
    if len(arduino_relay_controller_ports) == 1:
        return arduino_relay_controller_ports.keys()[0]
    elif len(arduino_relay_controller_ports) == 0:
        arduino_device_ports = findArduinoDevicePorts(
            baudrate=baudrate,
            model_number=DEVICE_MODEL_NUMBER,
            serial_number=serial_number,
            try_ports=try_ports,
            debug=debug,
        )
        err_str = "Could not find Arduino relay controllers. Check connections and permissions.\n"
        err_str += "Tried ports: " + str(arduino_device_ports)
        raise RuntimeError(err_str)
    else:
        err_str = "Found more than one Arduino relay controller. Specify port or serial_number.\n"
        err_str += "Matching ports: " + str(arduino_relay_controller_ports)
        raise RuntimeError(err_str)
    def __init__(self, *args, **kwargs):
        t_start = time.time()
        pwm_controller_port = None
        olfactometer_ports = []
        current_controller_port = None
        self.pwm_controller = None
        self.olfactometers = None
        self.current_controller = None
        arduino_device_ports = findArduinoDevicePorts()
        for port in arduino_device_ports:
            port_info = arduino_device_ports[port]
            if isPwmControllerPortInfo(port_info):
                pwm_controller_port = port
            elif isOlfactometerPortInfo(port_info):
                olfactometer_ports.append(port)
            elif isCurrentControllerPortInfo(port_info):
                current_controller_port = port
        if pwm_controller_port is not None:
            self.pwm_controller = PwmController(port=pwm_controller_port)
            self.pwm_controller.setDeviceName('pwm_controller')
        if len(olfactometer_ports) != 0:
            self.olfactometers = ArduinoOlfactometers(
                use_ports=olfactometer_ports)
            self.olfactometers.sortBySerialNumber()
            try:
                self.olfactometers[0].setDeviceName('olfactometer_odor1')
                self.olfactometers[1].setDeviceName('olfactometer_odor2')
                self.olfactometers[2].setDeviceName('olfactometer_ethanol')
            except IndexError:
                pass
        if current_controller_port is not None:
            self.current_controller = CurrentController(
                port=current_controller_port)
            self.current_controller.setDeviceName('current_controller')

        t_end = time.time()
        print('Initialization time =', (t_end - t_start))