This is a patch of code i added to sigrok-cli to help me when testing
HIDAPI implementation of HID serial bridge cp2110. If you find it useful
you could ad it to mainline.
Regards/// Carl-Fredrik Sundstrom
diff --git a/main.c b/main.c
index 94f1c0f..ee00f32 100644
--- a/main.c
+++ b/main.c
@@ -263,6 +263,8 @@ int main(int argc, char **argv)
set_options();
else if (opt_samples || opt_time || opt_frames || opt_continuous)
run_session();
+ else if (opt_serial)
+ show_serial_ports();
else
show_help();
diff --git a/options.c b/options.c
index 4d39847..b9aa0b8 100644
--- a/options.c
+++ b/options.c
@@ -48,6 +48,7 @@ gchar *opt_frames = NULL;
gboolean opt_continuous = FALSE;
gchar *opt_get = NULL;
gboolean opt_set = FALSE;
+gboolean opt_serial = FALSE;
/*
* Defines a callback function that generates an error if an
@@ -146,6 +147,7 @@ static const GOptionEntry optargs[] = {
"Sample continuously", NULL},
{"get", 0, 0, G_OPTION_ARG_CALLBACK, &check_opt_get, "Get device option
only", NULL},
{"set", 0, 0, G_OPTION_ARG_NONE, &opt_set, "Set device options only",
NULL},
+ {"serial", 0, 0, G_OPTION_ARG_NONE, &opt_serial, "List all available
serial ports", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
diff --git a/show.c b/show.c
index f09095a..d1f47f7 100644
--- a/show.c
+++ b/show.c
@@ -904,3 +904,23 @@ void show_transform(void)
}
g_strfreev(tok);
}
+
+void print_port(struct sr_serial_port *port)
+{
+ printf("\tname:'%s', description:'%s'\n", port->name, port->description);
+}
+
+void show_serial_ports()
+{
+ GSList *serial_ports;
+ struct sr_dev_driver *driver;
+
+ printf("Available serial ports:\n");
+
+ serial_ports = sr_serial_list(driver = NULL);
+ g_slist_foreach(serial_ports, (GFunc)print_port, NULL);
+ g_slist_foreach(serial_ports, (GFunc)g_free, NULL);
+ g_slist_free(serial_ports);
+
+}
+
diff --git a/sigrok-cli.h b/sigrok-cli.h
index d0b5872..e20b0a4 100644
--- a/sigrok-cli.h
+++ b/sigrok-cli.h
@@ -54,6 +54,7 @@ void show_pd_detail(void);
void show_input(void);
void show_output(void);
void show_transform(void);
+void show_serial_ports(void);
/* device.c */
GSList *device_scan(void);
@@ -125,6 +126,7 @@ extern gchar *opt_frames;
extern gboolean opt_continuous;
extern gchar *opt_get;
extern gboolean opt_set;
+extern gboolean opt_serial;
int parse_options(int argc, char **argv);
void show_help(void);
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel