Beispiel #1
0
int
main (int argc, char **argv)
{
    GPPort *p;
    KncCntrl *c;
    KncCamRes r;
    KncInfo ki;
    KncImageInfo kii;
    KncBitRate br;
    KncBitFlag bf;
    GPPortSettings s;

    printf ("Connecting to camera...\n");
    c = gpknc_cntrl_new_from_path ("serial:/dev/ttyS0");
    if (!c) {
        printf ("... failed.\n");
        return 1;
    }
    knc_cntrl_set_func_data (c, test_data, NULL);
    knc_cntrl_set_func_log  (c, test_log , NULL);
    printf ("... done.\n");

    printf ("Setting speed to 115200...\n");
    p = gpknc_cntrl_get_port (c);
    br = KNC_BIT_RATE_115200;
    bf = KNC_BIT_FLAG_8_BITS;
    CR (knc_set_io_pref (c, NULL, &br, &bf));
    gp_port_get_settings (p, &s);
    s.serial.speed = 115200;
    gp_port_set_settings (p, s);

    printf ("Requesting information about the camera...\n");
    CR (knc_get_info (c, &r, &ki));
    if (r) printf ("### Error %i: '%s'!\n", r, knc_cam_res_name (r));
    else {
        printf (" - Model '%s'\n", ki.model);
        printf (" - Serial number '%s'\n", ki.serial_number);
        printf (" - Name '%s'\n", ki.name);
        printf (" - Manufacturer '%s'\n", ki.manufacturer);
    }

    printf ("Capturing preview...\n");
    CR (knc_get_preview (c, &r, KNC_PREVIEW_NO));

    printf ("Requesting information about the first image...\n");
    CR (knc_get_image_info (c, &r, 1, &kii));
    if (r) printf ("### Error 0x%04x: '%s!\n", r, knc_cam_res_name (r));
    else {
        printf (" - ID %li\n", kii.id);
        printf (" - Size %i\n", kii.size);
        printf (" - Protected: %s\n", kii.prot ? "yes" : "no");
    }

    printf ("Downloading preview of first image...\n");
    CR (knc_get_image (c, NULL, kii.id, KNC_SOURCE_CARD, KNC_IMAGE_THUMB));
    knc_cntrl_unref (c);

    return 0;
}
Beispiel #2
0
static int
set_speed (Camera *camera, int speed, GPContext *context)
{
        GPPortSettings s;
	KncCamRes cr;
        KncBitRate br;
        KncBitFlag bf;
        int i;
        int speeds[] = {300, 600, 1200, 2400, 4800, 9600, 19200,
                                 38400, 57600, 115200};

        C (gp_port_get_settings (camera->port, &s));
        if ((s.serial.speed == speed) || (s.serial.speed == 115200))
                return (GP_OK);

        switch (speed) {
        case 0:

                /* Set the highest possible speed */
                CR (knc_get_io_pref (camera->pl->c, &cr, &br, &bf), context);
		CCR (cr, context);
                for (i = 9; i >= 0; i--) if ((1 << i) & br) break;
                if (i < 0) return (GP_ERROR_IO_SERIAL_SPEED);
		speed = speeds[i];
                     br = 1 << i;  break;
        case 300   : br = 1 << 0; break;
        case 600   : br = 1 << 1; break;
        case 1200  : br = 1 << 2; break;
        case 2400  : br = 1 << 3; break;
        case 4800  : br = 1 << 4; break;
        case 9600  : br = 1 << 5; break;
        case 19200 : br = 1 << 6; break;
        case 38400 : br = 1 << 7; break;
        case 57600 : br = 1 << 8; break;
        case 115200: br = 1 << 9; break;
        default: return (GP_ERROR_IO_SERIAL_SPEED);
        }

        /* Request the new speed */
        bf = KNC_BIT_FLAG_8_BITS;
        CR (knc_set_io_pref (camera->pl->c, &cr, &br, &bf), context);
	CCR (cr, context);
        s.serial.speed = speed;
        C (gp_port_set_settings (camera->port, s));

        return (GP_OK);
}