def find_first_device_or_simulate(self):
        simulated_device = SimulatedUSB()
        try:
            fd = FindDevices()
            result, usb_info = fd.list_usb()
            log.debug(" USB ID strings: %s" % usb_info[0])
            (vid, pid) = usb_info[0].split(':')[0:2]
        except:
            log.debug("Error find devices: %s" % str(sys.exc_info()))
            

        try:
            real_device = CameraUSB()
            log.debug("Attempt real device connection")
            if real_device.connect(9386, pid):
                log.debug("Succesfull connection to: %s" % pid)
                return real_device
        except:
            log.debug("Exception %s" % str(sys.exc_info()))
            pass

        log.debug("Return simulated device")
        simulated_device.assign("Stroker785L")
        simulated_device.serial_number = "Simulated Stroker785L"
        return simulated_device            
    def test_single_line_internal_trigger(self):
        ud = CameraUSB()
        vid = 0x24aa
        pid = 0x0009
        result = ud.connect(vid, pid)
        self.assertTrue(result, msg="Connection failure")

        result, pixel_data = ud.get_line()
        self.assertTrue(result)
        self.assertEquals(len(pixel_data), 1024)
        self.assertTrue(ud.disconnect())
    def test_get_device_firmware_revisions(self):
        ud = CameraUSB()
        vid = 0x24aa
        pid = 0x0009
        result = ud.connect(vid, pid)
        self.assertTrue(result, msg="Connection failure")

        result, sw_code = ud.get_sw_code()
        self.assertTrue(result)
        self.assertEquals(sw_code, '1.000')

        result, fpga_code = ud.get_fpga_code()
        self.assertTrue(result)
        self.assertEquals(fpga_code, '007-007')
        self.assertTrue(ud.disconnect())
    def test_no_device_connection(self):
        # Devices are on from setup, turn off manually here and wait
        self.ensure_all_off(self.phd_relay)
        time.sleep(1)

        ud = CameraUSB()
        vid = 0x24aa
        pid = 0x0009
        result = ud.connect(vid, pid)
        self.assertFalse(result)

        fd = FindDevices()
        result, serial = fd.get_serial(vid, pid)
        self.assertFalse(result)
        self.assertTrue(ud.disconnect())