]> sigrok.org Git - libsigrok.git/blobdiff - src/scpi/scpi.c
SCPI: add sr_scpi_write_data()
[libsigrok.git] / src / scpi / scpi.c
index a3a16ebd382e3ef92807709dda601c56206763ab..48e6a48495c9bfaba591147a12f715b67fe0b493 100644 (file)
@@ -337,6 +337,21 @@ SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi,
        return scpi->read_data(scpi->priv, buf, maxlen);
 }
 
+/**
+ * Send data to SCPI device.
+ *
+ * @param scpi Previously initialised SCPI device structure.
+ * @param buf Buffer with data to send.
+ * @param len Number of bytes to send.
+ *
+ * @return Number of bytes read, or SR_ERR upon failure.
+ */
+SR_PRIV int sr_scpi_write_data(struct sr_scpi_dev_inst *scpi,
+                       char *buf, int maxlen)
+{
+       return scpi->write_data(scpi->priv, buf, maxlen);
+}
+
 /**
  * Check whether a complete SCPI response has been received.
  *
@@ -364,12 +379,14 @@ SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi)
 /**
  * Free SCPI device.
  *
- * @param scpi Previously initialized SCPI device structure.
- *
- * @return SR_OK on success, SR_ERR on failure.
+ * @param scpi Previously initialized SCPI device structure. If NULL,
+ *             this function does nothing.
  */
 SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi)
 {
+       if (!scpi)
+               return;
+
        scpi->free(scpi->priv);
        g_free(scpi->priv);
        g_free(scpi);
@@ -934,17 +951,17 @@ SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi,
 /**
  * Free a sr_scpi_hw_info struct.
  *
- * @param hw_info Pointer to the struct to free.
- *
- * This function is safe to call with a NULL pointer.
+ * @param hw_info Pointer to the struct to free. If NULL, this
+ *                function does nothing.
  */
 SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info)
 {
-       if (hw_info) {
-               g_free(hw_info->manufacturer);
-               g_free(hw_info->model);
-               g_free(hw_info->serial_number);
-               g_free(hw_info->firmware_version);
-               g_free(hw_info);
-       }
+       if (!hw_info)
+               return;
+
+       g_free(hw_info->manufacturer);
+       g_free(hw_info->model);
+       g_free(hw_info->serial_number);
+       g_free(hw_info->firmware_version);
+       g_free(hw_info);
 }