]> sigrok.org Git - libsigrok.git/blobdiff - src/scpi/scpi_serial.c
scpi: Rephrase buffer resize for free space during SCPI read, add comments
[libsigrok.git] / src / scpi / scpi_serial.c
index 68a684c2d40fd4758c34f5a6d4b93d29ef76a836..02242ef66b5dc86d36502e6b352e9e6b5b1079b1 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <glib.h>
 #include <stdlib.h>
 #include <string.h>
-#include "libsigrok.h"
+#include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
+#include "scpi.h"
 
 #define LOG_PREFIX "scpi_serial"
 
@@ -42,6 +44,7 @@ static const struct {
 } scpi_serial_usb_ids[] = {
        { 0x0403, 0xed72, "115200/8n1/flow=1" }, /* Hameg HO720 */
        { 0x0403, 0xed73, "115200/8n1/flow=1" }, /* Hameg HO730 */
+       { 0x0aad, 0x0118, "115200/8n1" },        /* R&S HMO1002 */
 };
 
 static GSList *scpi_serial_scan(struct drv_context *drvc)
@@ -83,9 +86,9 @@ static int scpi_serial_dev_inst_new(void *priv, struct drv_context *drvc,
        return SR_OK;
 }
 
-static int scpi_serial_open(void *priv)
+static int scpi_serial_open(struct sr_scpi_dev_inst *scpi)
 {
-       struct scpi_serial *sscpi = priv;
+       struct scpi_serial *sscpi = scpi->priv;
        struct sr_serial_dev_inst *serial = sscpi->serial;
 
        if (serial_open(serial, SERIAL_RDWR) != SR_OK)
@@ -120,26 +123,21 @@ 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;
-       gchar *terminated_command;
        struct scpi_serial *sscpi = priv;
        struct sr_serial_dev_inst *serial = sscpi->serial;
 
-       terminated_command = g_strconcat(command, "\n", NULL);
-       len = strlen(terminated_command);
+       len = strlen(command);
        written = 0;
        while (written < len) {
                result = serial_write_nonblocking(serial,
-                               terminated_command + written, len - written);
+                               command + written, len - written);
                if (result < 0) {
                        sr_err("Error while sending SCPI command: '%s'.", command);
-                       g_free(terminated_command);
                        return SR_ERR;
                }
                written += result;
        }
 
-       g_free(terminated_command);
-
        sr_spew("Successfully sent SCPI command: '%s'.", command);
 
        return SR_OK;
@@ -161,7 +159,7 @@ static int scpi_serial_read_data(void *priv, char *buf, int maxlen)
 
        /* Try to read new data into the buffer if there is space. */
        if (len > 0) {
-               ret = serial_read_nonblocking(sscpi->serial, sscpi->buffer + sscpi->read,
+               ret = serial_read_nonblocking(sscpi->serial, sscpi->buffer + sscpi->count,
                                BUFFER_SIZE - sscpi->count);
 
                if (ret < 0)
@@ -207,9 +205,9 @@ static int scpi_serial_read_complete(void *priv)
        }
 }
 
-static int scpi_serial_close(void *priv)
+static int scpi_serial_close(struct sr_scpi_dev_inst *scpi)
 {
-       struct scpi_serial *sscpi = priv;
+       struct scpi_serial *sscpi = scpi->priv;
 
        return serial_close(sscpi->serial);
 }