X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fscpi%2Fscpi_serial.c;h=c73d1b4841a70ae434f50a6222d3555d881828ee;hb=92499a9c78b63e6a93d67de1883180d40fee7739;hp=6811ad3688345ad81a5d93b81732d6ab5d761df1;hpb=9ea4018f2f7c3bac99f738334ebd57b1e6ae0a2c;p=libsigrok.git diff --git a/src/scpi/scpi_serial.c b/src/scpi/scpi_serial.c index 6811ad36..c73d1b48 100644 --- a/src/scpi/scpi_serial.c +++ b/src/scpi/scpi_serial.c @@ -28,9 +28,11 @@ #define LOG_PREFIX "scpi_serial" +#ifdef HAVE_SERIAL_COMM + struct scpi_serial { struct sr_serial_dev_inst *serial; - char got_newline; + gboolean got_newline; }; static const struct { @@ -93,7 +95,18 @@ static int scpi_serial_open(struct sr_scpi_dev_inst *scpi) if (serial_flush(serial) != SR_OK) return SR_ERR; - sscpi->got_newline = 0; + sscpi->got_newline = FALSE; + + return SR_OK; +} + +static int scpi_serial_connection_id(struct sr_scpi_dev_inst *scpi, + char **connection_id) +{ + struct scpi_serial *sscpi = scpi->priv; + struct sr_serial_dev_inst *serial = sscpi->serial; + + *connection_id = g_strdup(serial->port); return SR_OK; } @@ -117,20 +130,15 @@ static int scpi_serial_source_remove(struct sr_session *session, void *priv) static int scpi_serial_send(void *priv, const char *command) { - int len, result, written; + int result; struct scpi_serial *sscpi = priv; struct sr_serial_dev_inst *serial = sscpi->serial; - len = strlen(command); - written = 0; - while (written < len) { - result = serial_write_nonblocking(serial, - command + written, len - written); - if (result < 0) { - sr_err("Error while sending SCPI command: '%s'.", command); - return SR_ERR; - } - written += result; + result = serial_write_blocking(serial, command, strlen(command), 0); + if (result < 0) { + sr_err("Error while sending SCPI command '%s': %d.", + command, result); + return SR_ERR; } sr_spew("Successfully sent SCPI command: '%s'.", command); @@ -141,7 +149,7 @@ static int scpi_serial_send(void *priv, const char *command) static int scpi_serial_read_begin(void *priv) { struct scpi_serial *sscpi = priv; - sscpi->got_newline = 0; + sscpi->got_newline = FALSE; return SR_OK; } @@ -158,13 +166,11 @@ static int scpi_serial_read_data(void *priv, char *buf, int maxlen) return ret; if (ret > 0) { - sr_spew("Read %d bytes into buffer.", ret); - if (buf[ret - 1] == '\n') { - sscpi->got_newline = 1; + sscpi->got_newline = TRUE; sr_spew("Received terminator"); } else { - sscpi->got_newline = 0; + sscpi->got_newline = FALSE; } } @@ -195,10 +201,12 @@ static void scpi_serial_free(void *priv) SR_PRIV const struct sr_scpi_dev_inst scpi_serial_dev = { .name = "serial", .prefix = "", + .transport = SCPI_TRANSPORT_SERIAL, .priv_size = sizeof(struct scpi_serial), .scan = scpi_serial_scan, .dev_inst_new = scpi_serial_dev_inst_new, .open = scpi_serial_open, + .connection_id = scpi_serial_connection_id, .source_add = scpi_serial_source_add, .source_remove = scpi_serial_source_remove, .send = scpi_serial_send, @@ -208,3 +216,5 @@ SR_PRIV const struct sr_scpi_dev_inst scpi_serial_dev = { .close = scpi_serial_close, .free = scpi_serial_free, }; + +#endif