* Send a SCPI command.
*
* @param scpi Previously initialized SCPI device structure.
- * @param command The SCPI command to send to the device.
+ * @param format Format string, to be followed by any necessary arguments.
*
* @return SR_OK on success, SR_ERR on failure.
*/
SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi,
- const char *command)
+ const char *format, ...)
{
- return scpi->send(scpi->priv, command);
+ va_list args;
+ int ret;
+
+ va_start(args, format);
+ ret = sr_scpi_send_variadic(scpi, format, args);
+ va_end(args);
+
+ return ret;
+}
+
+/**
+ * Send a SCPI command with a variadic argument list.
+ *
+ * @param scpi Previously initialized SCPI device structure.
+ * @param format Format string.
+ * @param args Argument list.
+ *
+ * @return SR_OK on success, SR_ERR on failure.
+ */
+SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi,
+ const char *format, va_list args)
+{
+ va_list args_copy;
+ char *buf;
+ int len, ret;
+
+ /* Get length of buffer required. */
+ va_copy(args_copy, args);
+ len = vsnprintf(NULL, 0, format, args_copy);
+ va_end(args_copy);
+
+ /* Allocate buffer and write out command. */
+ buf = g_malloc(len + 1);
+ vsprintf(buf, format, args);
+
+ /* Send command. */
+ ret = scpi->send(scpi->priv, buf);
+
+ /* Free command buffer. */
+ g_free(buf);
+
+ return ret;
}
/**