scpi: Add function to fetch uint8_t.
This patch adds a function to read and parse a SCPI response which contains a comma separated list of unsignet 8-bit integer numbers (e.g "1,0,64"). This is particularly useful if the instrument sends digital measurement data in this format.
This commit is contained in:
parent
8acbb89a1d
commit
1a323dd887
|
@ -391,6 +391,65 @@ SR_PRIV int sr_scpi_get_floatv(struct sr_serial_dev_inst *serial,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 serial Previously initialized serial port structure.
|
||||||
|
* @param command The SCPI command to send to the device (can be NULL).
|
||||||
|
* @param 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.
|
||||||
|
*/
|
||||||
|
SR_PRIV int sr_scpi_get_uint8v(struct sr_serial_dev_inst *serial,
|
||||||
|
const char *command, GArray **scpi_response)
|
||||||
|
{
|
||||||
|
int tmp;
|
||||||
|
int ret;
|
||||||
|
char *response;
|
||||||
|
|
||||||
|
gchar **ptr;
|
||||||
|
gchar **tokens;
|
||||||
|
GArray *response_array;
|
||||||
|
|
||||||
|
ret = SR_OK;
|
||||||
|
response = NULL;
|
||||||
|
tokens = NULL;
|
||||||
|
|
||||||
|
if (sr_scpi_get_string(serial, command, &response) != SR_OK)
|
||||||
|
if (!response)
|
||||||
|
return SR_ERR;
|
||||||
|
|
||||||
|
tokens = g_strsplit(response, ",", 0);
|
||||||
|
ptr = tokens;
|
||||||
|
|
||||||
|
response_array = g_array_sized_new(TRUE, FALSE, sizeof(uint8_t), 256);
|
||||||
|
|
||||||
|
while(*ptr) {
|
||||||
|
if (sr_atoi(*ptr, &tmp) == SR_OK)
|
||||||
|
response_array = g_array_append_val(response_array,
|
||||||
|
tmp);
|
||||||
|
else
|
||||||
|
ret = SR_ERR;
|
||||||
|
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
g_strfreev(tokens);
|
||||||
|
g_free(response);
|
||||||
|
|
||||||
|
if (response_array->len == 0) {
|
||||||
|
g_array_free(response_array, TRUE);
|
||||||
|
*scpi_response = NULL;
|
||||||
|
return SR_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
*scpi_response = response_array;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the *IDN? SCPI command, receive the reply, parse it and store the
|
* 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.
|
* reply as a sr_scpi_hw_info structure in the supplied scpi_response pointer.
|
||||||
|
|
|
@ -291,6 +291,8 @@ SR_PRIV int sr_scpi_get_double(struct sr_serial_dev_inst *serial,
|
||||||
SR_PRIV int sr_scpi_get_opc(struct sr_serial_dev_inst *serial);
|
SR_PRIV int sr_scpi_get_opc(struct sr_serial_dev_inst *serial);
|
||||||
SR_PRIV int sr_scpi_get_floatv(struct sr_serial_dev_inst *serial,
|
SR_PRIV int sr_scpi_get_floatv(struct sr_serial_dev_inst *serial,
|
||||||
const char *command, GArray **scpi_response);
|
const char *command, GArray **scpi_response);
|
||||||
|
SR_PRIV int sr_scpi_get_uint8v(struct sr_serial_dev_inst *serial,
|
||||||
|
const char *command, GArray **scpi_response);
|
||||||
SR_PRIV int sr_scpi_get_hw_id(struct sr_serial_dev_inst *serial,
|
SR_PRIV int sr_scpi_get_hw_id(struct sr_serial_dev_inst *serial,
|
||||||
struct sr_scpi_hw_info **scpi_reponse);
|
struct sr_scpi_hw_info **scpi_reponse);
|
||||||
SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info);
|
SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info);
|
||||||
|
|
Loading…
Reference in New Issue