]> sigrok.org Git - sigrok-cli.git/blobdiff - sigrok-cli.c
Fix error message
[sigrok-cli.git] / sigrok-cli.c
index 75015aa2b80bda18c11eb0000fc5ef78044d81f3..e0860aeaa43f7aaa40cfaaea1534d8ba9f67f9e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the sigrok-cli project.
  *
  * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
  *
@@ -344,18 +344,15 @@ static void show_dev_detail(void)
        num_devices = g_slist_length(devices);
        if (num_devices > 1) {
                g_critical("%d devices found. Use --list-devices to show them, "
-                               "and --device to select one.", num_devices);
+                               "and select one to show.", num_devices);
                return;
        }
 
        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;
        }
 
@@ -546,7 +543,6 @@ static void show_dev_detail(void)
                        g_variant_unref(gvar);
 
                } else if (srci->key == SR_CONF_DATALOG) {
-                       /* TODO test */
                        /* Turning on/off internal data logging. */
                        printf("    %s\t(on/off", srci->id);
                        if (sr_config_get(sdi->driver, SR_CONF_DATALOG,
@@ -563,7 +559,7 @@ static void show_dev_detail(void)
        }
        g_variant_unref(gvar_opts);
 
-       sr_session_destroy();
+       sr_dev_close(sdi);
 
 }
 
@@ -875,15 +871,15 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
                break;
        }
 
-       if (o && o->format->recv) {
-               out = o->format->recv(o, sdi, packet);
-               if (out && out->len) {
+       if (o && o->format->receive) {
+               if (o->format->receive(o, sdi, packet, &out) == SR_OK && out) {
                        fwrite(out->str, 1, out->len, outfile);
                        fflush(outfile);
+                       g_string_free(out, TRUE);
                }
        }
 
-       /* SR_DF_END needs to be handled after the output module's recv()
+       /* SR_DF_END needs to be handled after the output module's receive()
         * is called, so it can properly clean up that module etc. */
        if (packet->type == SR_DF_END) {
                g_debug("cli: Received SR_DF_END");
@@ -1531,15 +1527,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 +1603,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;
        }