From: Bert Vermeulen Date: Mon, 22 Apr 2013 23:15:32 +0000 (+0200) Subject: Open device before adding it to the session X-Git-Tag: sigrok-cli-0.4.0~9 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0687f23db01dae4bb7d7f4398126ef6fab0402b0;p=sigrok-cli.git Open device before adding it to the session --- diff --git a/sigrok-cli.c b/sigrok-cli.c index a37b19d..ade15cd 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -351,11 +351,8 @@ static void show_dev_detail(void) sdi = devices->data; print_dev_line(sdi); - /* This properly opens and initializes the device, so we can get - * current settings. */ - sr_session_new(); - if (sr_session_dev_add(sdi) != SR_OK) { - g_critical("Failed to use device."); + if (sr_dev_open(sdi) != SR_OK) { + g_critical("Failed to open device."); return; } @@ -563,7 +560,7 @@ static void show_dev_detail(void) } g_variant_unref(gvar_opts); - sr_session_destroy(); + sr_dev_close(sdi); } @@ -1531,15 +1528,14 @@ static void set_options(void) } sdi = devices->data; - sr_session_new(); - if (sr_session_dev_add(sdi) != SR_OK) { - g_critical("Failed to use device."); + if (sr_dev_open(sdi) != SR_OK) { + g_critical("Failed to open device."); return; } set_dev_options(sdi, devargs); - sr_session_destroy(); + sr_dev_close(sdi); g_slist_free(devices); g_hash_table_destroy(devargs); @@ -1608,8 +1604,13 @@ static void run_session(void) sr_session_new(); sr_session_datafeed_callback_add(datafeed_in, NULL); + if (sr_dev_open(sdi) != SR_OK) { + g_critical("Failed to open device."); + return; + } + if (sr_session_dev_add(sdi) != SR_OK) { - g_critical("Failed to use device."); + g_critical("Failed to add device to session."); sr_session_destroy(); return; }