Esempio n. 1
0
 def watch_connection_state(should_run):
     while not should_run.is_set():
         socketio.emit('event', {
             'type': 'connection_status',
             'is_connected': robot.is_connected()
         })
         socketio.sleep(1.5)
Esempio n. 2
0
async def _update_firmware(filename, loop):
    """
    This method remains in the API currently because of its use of the robot
    singleton's copy of the driver. This should move to the server lib project
    eventually and use its own driver object (preferably involving moving the
    drivers themselves to the serverlib)
    """
    # ensure there is a reference to the port
    if not robot.is_connected():
        robot.connect()

    # get port name
    port = str(robot._driver.port)
    # set smoothieware into programming mode
    robot._driver._smoothie_programming_mode()
    # close the port so other application can access it
    robot._driver._connection.close()

    # run lpc21isp, THIS WILL TAKE AROUND 1 MINUTE TO COMPLETE
    update_cmd = 'lpc21isp -wipe -donotstart {0} {1} {2} 12000'.format(
        filename, port, robot.config.serial_speed)
    proc = await asyncio.create_subprocess_shell(
        update_cmd, stdout=asyncio.subprocess.PIPE, loop=loop)
    rd = await proc.stdout.read()
    res = rd.decode().strip()
    await proc.wait()

    # re-open the port
    robot._driver._connection.open()
    # reset smoothieware
    robot._driver._smoothie_reset()
    # run setup gcodes
    robot._driver._setup()

    return res
Esempio n. 3
0
 def run(self):
     self.default_setup()
     while not self.stop.is_set():
         if self.disconnect.is_set():
             if robot.is_connected():
                 robot.disconnect()
                 logging.debug('OT-2 robot disconnected')
             self.disconnect.clear()
         try:
             command = command_queue.get(block=True, timeout=0.01)
             missive = command['missive']
         except Empty:
             continue
         with stdout_redirect() as out:
             try:
                 print(missive)
                 retval = eval(missive, self.global_context,
                               self.local_context)
                 if retval:
                     print(retval)
             except SyntaxError:
                 try:
                     exec(missive, self.global_context, self.local_context)
                 except Exception as E:
                     print('EXEC Caught an "%s" exception: %s' %
                           (type(E).__name__, str(E)))
                     print(traceback.format_exc())
                     # pdb.post_mortem()
             except Exception as e:
                 print('EVAL Caught an "%s" exception: %s' %
                       (type(e).__name__, str(e)))
                 print(traceback.format_exc())
                 # pdb.post_mortem()
         if len(out.getvalue()) > 0:
             command['missive'] = str(out.getvalue())
         else:
             command['missive'] = 'ACK'
         response_queue.put(command)
         command_queue.task_done()
     if robot.is_connected():
         robot.disconnect()
         logging.debug('OT-2 robot disconnected')
Esempio n. 4
0
async def _update_firmware(filename, loop):
    """
    Currently uses the robot singleton from the API server to connect to
    Smoothie. Those calls should be separated out from the singleton so it can
    be used directly without requiring a full initialization of the API robot.
    """
    try:
        from opentrons import robot
    except ModuleNotFoundError:
        res = "Unable to find module `opentrons`--not updating firmware"
        rc = 1
        log.error(res)
    else:
        # ensure there is a reference to the port
        if not robot.is_connected():
            robot.connect()

        # get port name
        port = str(robot._driver.port)
        # set smoothieware into programming mode
        robot._driver._smoothie_programming_mode()
        # close the port so other application can access it
        robot._driver._connection.close()

        # run lpc21isp, THIS WILL TAKE AROUND 1 MINUTE TO COMPLETE
        update_cmd = 'lpc21isp -wipe -donotstart {0} {1} {2} 12000'.format(
            filename, port, robot.config.serial_speed)
        proc = await asyncio.create_subprocess_shell(
            update_cmd,
            stdout=asyncio.subprocess.PIPE,
            loop=loop)
        rd = await proc.stdout.read()
        res = rd.decode().strip()
        await proc.communicate()
        rc = proc.returncode

        if rc == 0:
            # re-open the port
            robot._driver._connection.open()
            # reset smoothieware
            robot._driver._smoothie_reset()
            # run setup gcodes
            robot._driver._setup()

    return res, rc
Esempio n. 5
0
from opentrons import robot, containers, instruments
import opentrons
import curses
import time

from curses import wrapper
from equipment import getEquipment
movementamounts= {1:0.1, 2:0.5, 3:1, 4:5, 5:10,6:20,7:40,8:80}
equipment=getEquipment()

robot.connect(robot.get_serial_ports_list()[0])
if not robot.is_connected():
        raise Exception('Did not connect')

input("Robot will now home, press enter to continue.")
robot.home()

placeables = {}
pipettes = {}
for key, value in equipment.items():

     if hasattr(value, 'axis'):
          
          pipettes[key]=value
     else:
          placeables[key]=value
     
placeableNames=sorted(list(placeables.keys()))
pipetteNames=sorted(list(pipettes.keys()))
def main(stdscr):
Esempio n. 6
0
    def _run(self):
        def on_command(message):
            if message['$'] == 'before':
                self.log_append()
            if message['name'] == command_types.PAUSE:
                self.set_state('paused')
            if message['name'] == command_types.RESUME:
                self.set_state('running')

        self._reset()

        _unsubscribe = self._broker.subscribe(command_types.COMMAND,
                                              on_command)

        self.startTime = now()
        self.set_state('running')

        try:
            if self._use_v2:
                self.resume()
                self._pre_run_hooks()
                self._hardware.cache_instruments()
                ctx = ProtocolContext.build_using(self._protocol,
                                                  loop=self._loop,
                                                  broker=self._broker,
                                                  extra_labware=getattr(
                                                      self._protocol,
                                                      'extra_labware', {}))
                ctx.connect(self._hardware)
                ctx.home()
                run_protocol(self._protocol, context=ctx)
            else:
                robot.broker = self._broker
                assert isinstance(self._protocol, PythonProtocol),\
                    'Internal error: v1 should only be used for python'
                if not robot.is_connected():
                    robot.connect()
                self.resume()
                self._pre_run_hooks()
                robot.cache_instrument_models()
                robot.discover_modules()
                exec(self._protocol.contents, {})

            # If the last command in a protocol was a pause, the protocol
            # will immediately finish executing because there's no smoothie
            # command to block... except the home that's about to happen,
            # which will confuse the app and lock it up. So we need to
            # do our own pause here, and sleep the thread until/unless the
            # app resumes us.
            #
            # Cancelling from the app during this pause will result in the
            # smoothie giving us an error during the subsequent home, which
            # is tragic but expected.
            while self.state == 'paused':
                sleep(0.1)
            self.set_state('finished')
            self._hw_iface().home()
        except SmoothieAlarm:
            log.info("Protocol cancelled")
        except Exception as e:
            log.exception("Exception during run:")
            self.error_append(e)
            self.set_state('error')
            raise e
        finally:
            _unsubscribe()
Esempio n. 7
0
def is_connected():
    robot = Robot.get_instance()
    return flask.jsonify({
        'is_connected': robot.is_connected(),
        'port': robot.get_connected_port()
    })
Esempio n. 8
0
def initall():
    robot.connect(robot.get_serial_ports_list()[0])
    robot.is_connected()
    robot.home()