/**
* Get the connection ID of the SCPI device.
*
- * @param scpi Previously initialized SCPI device structure.
- * @param connection_id Pointer where to store the connection ID. The caller
- * is responsible for g_free()ing the string when it is no longer needed.
+ * Callers must free the allocated memory regardless of the routine's
+ * return code. See @ref g_free().
+ *
+ * @param[in] scpi Previously initialized SCPI device structure.
+ * @param[out] connection_id Pointer where to store the connection ID.
*
* @return SR_OK on success, SR_ERR on failure.
*/
/**
* Send a SCPI command, receive the reply and store the reply in scpi_response.
*
- * @param scpi Previously initialised SCPI device structure.
- * @param command The SCPI command to send to the device (can be NULL).
- * @param scpi_response Pointer where to store the SCPI response.
+ * Callers must free the allocated memory regardless of the routine's
+ * return code. See @ref g_free().
+ *
+ * @param[in] scpi Previously initialised SCPI device structure.
+ * @param[in] command The SCPI command to send to the device (can be NULL).
+ * @param[out] scpi_response Pointer where to store the SCPI response.
*
* @return SR_OK on success, SR_ERR* on failure.
*/
const char *command, char **scpi_response)
{
GString *response;
- response = g_string_sized_new(1024);
+ *scpi_response = NULL;
+
+ response = g_string_sized_new(1024);
if (sr_scpi_get_data(scpi, command, &response) != SR_OK) {
if (response)
g_string_free(response, TRUE);
const char *command, int *scpi_response)
{
int ret;
+ struct sr_rational ret_rational;
char *response;
response = NULL;
if (ret != SR_OK && !response)
return ret;
- if (sr_atoi(response, scpi_response) == SR_OK)
- ret = SR_OK;
- else
+ ret = sr_parse_rational(response, &ret_rational);
+ if (ret == SR_OK && (ret_rational.p % ret_rational.q) == 0) {
+ *scpi_response = ret_rational.p / ret_rational.q;
+ } else {
+ sr_dbg("get_int: non-integer rational=%" PRId64 "/%" PRIu64,
+ ret_rational.p, ret_rational.q);
ret = SR_ERR_DATA;
+ }
g_free(response);
* Send a SCPI command, read the reply, parse it as comma separated list of
* floats and store the as an result in scpi_response.
*
- * @param scpi Previously initialised SCPI device structure.
- * @param command The SCPI command to send to the device (can be NULL).
- * @param scpi_response Pointer where to store the parsed result.
+ * Callers must free the allocated memory (unless it's NULL) regardless of
+ * the routine's return code. See @ref g_array_free().
+ *
+ * @param[in] scpi Previously initialised SCPI device structure.
+ * @param[in] command The SCPI command to send to the device (can be NULL).
+ * @param[out] scpi_response Pointer where to store the parsed result.
*
* @return SR_OK upon successfully parsing all values, SR_ERR* upon a parsing
- * error or upon no response. The allocated response must be freed by
- * the caller in the case of an SR_OK as well as in the case of
- * parsing error.
+ * error or upon no response.
*/
SR_PRIV int sr_scpi_get_floatv(struct sr_scpi_dev_inst *scpi,
const char *command, GArray **scpi_response)
gchar **ptr, **tokens;
GArray *response_array;
+ *scpi_response = NULL;
response = NULL;
tokens = NULL;
if (ret != SR_OK && response_array->len == 0) {
g_array_free(response_array, TRUE);
- *scpi_response = NULL;
return SR_ERR_DATA;
}
* Send a SCPI command, read the reply, parse it as comma separated list of
* unsigned 8 bit integers and store the as an result in scpi_response.
*
- * @param scpi Previously initialised SCPI device structure.
- * @param command The SCPI command to send to the device (can be NULL).
- * @param scpi_response Pointer where to store the parsed result.
+ * Callers must free the allocated memory (unless it's NULL) regardless of
+ * the routine's return code. See @ref g_array_free().
+ *
+ * @param[in] scpi Previously initialised SCPI device structure.
+ * @param[in] command The SCPI command to send to the device (can be NULL).
+ * @param[out] scpi_response Pointer where to store the parsed result.
*
* @return SR_OK upon successfully parsing all values, SR_ERR* upon a parsing
- * error or upon no response. The allocated response must be freed by
- * the caller in the case of an SR_OK as well as in the case of
- * parsing error.
+ * error or upon no response.
*/
SR_PRIV int sr_scpi_get_uint8v(struct sr_scpi_dev_inst *scpi,
const char *command, GArray **scpi_response)
gchar **ptr, **tokens;
GArray *response_array;
+ *scpi_response = NULL;
response = NULL;
tokens = NULL;
if (response_array->len == 0) {
g_array_free(response_array, TRUE);
- *scpi_response = NULL;
return SR_ERR_DATA;
}
* Send a SCPI command, read the reply, parse it as binary data with a
* "definite length block" header and store the as an result in scpi_response.
*
- * @param scpi Previously initialised SCPI device structure.
- * @param command The SCPI command to send to the device (can be NULL).
- * @param scpi_response Pointer where to store the parsed result.
+ * Callers must free the allocated memory (unless it's NULL) regardless of
+ * the routine's return code. See @ref g_byte_array_free().
+ *
+ * @param[in] scpi Previously initialised SCPI device structure.
+ * @param[in] command The SCPI command to send to the device (can be NULL).
+ * @param[out] scpi_response Pointer where to store the parsed result.
*
* @return SR_OK upon successfully parsing all values, SR_ERR* upon a parsing
- * error or upon no response. The allocated response must be freed by
- * the caller in the case of an SR_OK as well as in the case of
- * parsing error.
+ * error or upon no response.
*/
SR_PRIV int sr_scpi_get_block(struct sr_scpi_dev_inst *scpi,
const char *command, GByteArray **scpi_response)
long datalen;
gint64 timeout;
+ *scpi_response = NULL;
+
g_mutex_lock(&scpi->scpi_mutex);
if (command)
timeout = g_get_monotonic_time() + scpi->read_timeout_us;
- *scpi_response = NULL;
-
/* Get (the first chunk of) the response. */
do {
ret = scpi_read_response(scpi, response, timeout);
* Send the *IDN? SCPI command, receive the reply, parse it and store the
* reply as a sr_scpi_hw_info structure in the supplied scpi_response pointer.
*
- * The hw_info structure must be freed by the caller via sr_scpi_hw_info_free().
+ * Callers must free the allocated memory regardless of the routine's
+ * return code. See @ref sr_scpi_hw_info_free().
*
- * @param scpi Previously initialised SCPI device structure.
- * @param scpi_response Pointer where to store the hw_info structure.
+ * @param[in] scpi Previously initialised SCPI device structure.
+ * @param[out] scpi_response Pointer where to store the hw_info structure.
*
* @return SR_OK upon success, SR_ERR* on failure.
*/
struct sr_scpi_hw_info *hw_info;
gchar *idn_substr;
+ *scpi_response = NULL;
response = NULL;
tokens = NULL;