def get_image(self):
     """
     Prompts the Ximea camera to capture a photo after the next GPI spike.
     """
     try:
         self.camera.get_image(self.image)
         return self.image.get_image_data_numpy()
     except xiapi.Xi_error:
         Interface.choose_print(self.gui, 'camera', 'Xi_error: ERROR 10: Timeout')
         Main.abort_session()
         return None
 def write_value(self,value):
     """
     Write a value to the Arduino over Serial.
         :argument value: Value to be written to Arduino
         :type value: string, int, float
         :argument pause: Amount of time spent paused in seconds
         :type pause: int, float
     """
     Interface.choose_print(self.gui, 'arduino', 'Writing "{}"...'.format(value))
     try:
         self.serial.write('{}'.format(value))
         self.serial.readline()
         Interface.choose_print(self.gui, 'arduino', 'Wrote: {}'.format(value))
     except serial.SerialException:
         Interface.choose_print(self.gui,
                                'arduino',
                                'SerialException: WriteFile failed')
         Main.abort_session()
 def __init__(self,com_number,gui=None):
     """
     Initializes an instance of ArduinoController.
         :argument com_number: Port number of the Arduino.
         :type com_number: int
         :keyword gui: Optional interface used to print(default None).
         :type gui: Interface.ScarberryGui
     """
     self.gui = gui
     try:
         self.serial = serial.Serial('COM{}'.format(com_number),115200)
         Interface.choose_print(gui, 'arduino', 'Waiting for COM{}...'.format(com_number))
         print('Waiting for COM{}...'.format(com_number))
         time.sleep(ArduinoController.INITIAL_SLEEP);
         Interface.choose_print(gui, 'arduino', 'Connected to COM{}.'.format(com_number))
         print('Connected to COM{}.'.format(com_number))
     except serial.SerialException:
         Interface.choose_print(self.gui,
                                'arduino',
                                'SerialException: could not open COM{}'.format(com_number))
         Main.abort_session()
    def __init__(self,framerate,gain=0,gui=None):
        """
        Initializes an instance of XimeaCamera.
            :argument framerate: Number of pictures taken a second.
            :type framerate: int
            :keyword gain: Brightness modifier of pictures taken.
            type gain: int, float [0 to 6](default 0)
            :keyword gui: Optional interface used to print(default None).
            :type gui: Interface.ScarberryGui
        """
        self.gui = gui
        self.image = xiapi.Image()

        self.camera = xiapi.Camera()
        Interface.choose_print(gui, 'camera', 'Opening camera...')
        try:
            self.camera.open_device()

            exposure = (1000000 / (int(framerate)))
            exposure -= math.pow(10, math.floor(math.log(exposure, 10)) - 1)
            self.camera.set_exposure(int(exposure))

            if gain < 0:
                gain = 0
            if gain > 6:
                gain = 6
            self.camera.set_gain(float(gain))

            self.camera.set_trigger_source('XI_TRG_EDGE_RISING')
            self.camera.set_gpi_mode('XI_GPI_TRIGGER')
            self.camera.set_gpo_selector('XI_GPO_PORT1')
            self.camera.set_gpo_mode('XI_GPO_FRAME_TRIGGER_WAIT')
            self.camera.set_imgdataformat('XI_MONO8')
        except xiapi.Xi_error:
            Interface.choose_print(gui, 'camera', 'Xi_error: ERROR 56: No Devices Found')
            Main.abort_session()