On Thu, Apr 23, 2015 at 7:14 PM, Martin Ling <martin-sig...@earth.li> wrote: > On Thu, Apr 23, 2015 at 05:17:33PM -0400, Cody P Schafer wrote: >> >> Do note that the lack of posix-like blocking behavior (ie: read at >> least 1 byte but up to N bytes) means one must either read one byte at >> a time or wire up the sp_event_set infra to do "read until X". > > How and why would you use the sp_event_set infrastructure for this? >
So in posix I'd do something like the following (buffer fullness & error checking omitted): int b_fd = open_and_configure_port_as_blocking(); uint8_t buf[1024]; size_t used = 0; for (;;) { ssize_t r = read(b_fd, buf + used, sizeof(buf) - used); /* scan for 'X', if found break */ if (memchr(buf + used, 'X', r)) break; used += r; } With libserialport to get the same behaviour I need to: struct sp_port *p = open_and_configure_port(); uint8_t buf[1024]; size_t used = 0; struct sp_event_set *ev; sp_new_event_set(&ev); sp_add_port_events(ev, p, SP_EVENT_RX_READY); for (;;) { sp_wait(ev, 0); sp_nonblocking_read(p, buf + used, sizeof(buf) - used); /* scan for 'X', if found break */ if (memchr(buf + used, 'X', r)) break; used += r; } Because sp_blocking_read() doesn't return early (like posix read does). [Both of these examples were put together directly in this email, they are untested, and they lack handling of buffer fullness & errors, no _not_ use them directly without fixing those weaknesses] ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel