Esempio n. 1
0
    def connect_cam(cls, cam):

        cls.logger.info("Beginning banana scan... ")
        ArducamSDK.Py_ArduCam_scan()

        ret = -1
        for i in range(3):
            time.sleep(5)
            ret, cam.handle, rtn_cfg = ArducamSDK.Py_ArduCam_open(cam.cam_config, cam.dev_id)
            if ret == 0:
                cam.usb_version = rtn_cfg['usbType']
                return
        raise AssertionError("Failed to connect to camera - error code: {}".format(ret))
Esempio n. 2
0
def camera_initFromFile(fialeName):
    global acfg, handle, Width, Height, color_mode, save_raw
    # load config file
    z = handle
    config = json.load(open(fialeName, "r"))
    print(fialeName)
    #    print(config)

    camera_parameter = config["camera_parameter"]
    Width = int(camera_parameter["SIZE"][0])
    Height = int(camera_parameter["SIZE"][1])

    BitWidth = camera_parameter["BIT_WIDTH"]
    ByteLength = 1
    if BitWidth > 8 and BitWidth <= 16:
        ByteLength = 2
        save_raw = True
    FmtMode = int(camera_parameter["FORMAT"][0])
    color_mode = (int)(camera_parameter["FORMAT"][1])

    print(camera_parameter)
    print(Width)
    print(Height)

    print(BitWidth)
    print(FmtMode)
    #    print(BitWidth)
    print("color mode", color_mode)

    I2CMode = camera_parameter["I2C_MODE"]
    I2cAddr = int(camera_parameter["I2C_ADDR"], 16)
    TransLvl = int(camera_parameter["TRANS_LVL"])
    acfg = {
        "u32CameraType": 0x4D091031,
        "u32Width": Width,
        "u32Height": Height,
        "usbType": 0,
        "u8PixelBytes": ByteLength,
        "u16Vid": 0,
        "u32Size": 0,
        "u8PixelBits": BitWidth,
        "u32I2cAddr": I2cAddr,
        "emI2cMode": I2CMode,
        "emImageFmtMode": FmtMode,
        "u32TransLvl": TransLvl
    }

    print("\nbanana\n")
    #    usb_version = rtn_acfg['usbType']
    #    print(usb_version)

    # Return vale: number of supported cameras,indexs,serials
    #    a, b, c = ArducamSDK.Py_ArduCam_scan()
    #    print(a) #2
    #    print(b) #[0,1]
    #    print(c)

    #    camnum = ArducamSDK.Py_ArduCam_scan()
    #    print(camnum)
    #    print(camnum[1][0])
    #    print(camnum[1][1])

    #    input("p")

    # Serial: AU3S-1830-0003 <= USB 3.0 MT9J001
    # Bus 001 Device 009: ID 04b4:03f1 Cypress Semiconductor Corp.

    # Serial: AU2S-1843-0016
    # Bus 001 Device 010: ID 52cb:52cb

    # 4.2.1.3 Py_ArduCam_open( acfg,index)
    # Param 1: ArduCamCfg structure instance
    # Param 2: index of the camera, handle,acfg

    ArducamSDK.Py_ArduCam_scan()
    print("scanning")
    time.sleep(3)
    ret, handle, rtn_cfg = ArducamSDK.Py_ArduCam_open(acfg, cameraID)
    time.sleep(3)

    #    ret = ArducamSDK.Py_ArduCam_open(acfg,1)
    #    print(ret)
    #    input("p")

    # 4.2.1.1 Py_ArduCam_autoopen(acfg )
    # Return vale: error code, handle,acfg
    #    ret,handle,rtn_cfg = ArducamSDK.Py_ArduCam_autoopen(acfg)

    print(ret)
    print(handle)
    print(rtn_cfg)
    if ret == 0:

        # ArducamSDK.Py_ArduCam_writeReg_8_8(handle,0x46,3,0x00)
        usb_version = rtn_cfg['usbType']
        print("USB VERSION:", usb_version)
        # config board param
        configBoard(config["board_parameter"])

        if usb_version == ArducamSDK.USB_1 or usb_version == ArducamSDK.USB_2:
            configBoard(config["board_parameter_dev2"])
        if usb_version == ArducamSDK.USB_3:
            configBoard(config["board_parameter_dev3_inf3"])
        if usb_version == ArducamSDK.USB_3_2:
            configBoard(config["board_parameter_dev3_inf2"])

        writeSensorRegs(config["register_parameter"])

        if usb_version == ArducamSDK.USB_3:
            writeSensorRegs(config["register_parameter_dev3_inf3"])
        if usb_version == ArducamSDK.USB_3_2:
            writeSensorRegs(config["register_parameter_dev3_inf2"])

        rtn_val, datas = ArducamSDK.Py_ArduCam_readUserData(
            handle, 0x400 - 16, 16)
        print("Serial: %c%c%c%c-%c%c%c%c-%c%c%c%c" %
              (datas[0], datas[1], datas[2], datas[3], datas[4], datas[5],
               datas[6], datas[7], datas[8], datas[9], datas[10], datas[11]))

        return True
    else:
        print("open fail,rtn_val = ", ret)
        return False