scpi: Add a function to read and wait on a *OPC? reply.
The SCPI standard specifies the "*OPC?" command (Operation complete query) which queries the instrument for its operative state. When all pending operations are complete, the instrument responds with a "1". Some manufacturers block before completing all operations and don't respond with anything and some of them respond with a "0". This function handles both cases uniformly.
This commit is contained in:
parent
d730f70e06
commit
f5922adef5
|
@ -307,6 +307,31 @@ SR_PRIV int sr_scpi_get_double(struct sr_serial_dev_inst *serial,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a SCPI *OPC? command, read the reply and return the result of the
|
||||||
|
* command.
|
||||||
|
*
|
||||||
|
* @param serial Previously initialized serial port structure.
|
||||||
|
*
|
||||||
|
* @return SR_OK on success, SR_ERR on failure.
|
||||||
|
*/
|
||||||
|
SR_PRIV int sr_scpi_get_opc(struct sr_serial_dev_inst *serial)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
gboolean opc;
|
||||||
|
|
||||||
|
for (i = 0; i < SCPI_READ_RETRIES; ++i) {
|
||||||
|
sr_scpi_get_bool(serial, SCPI_CMD_OPC, &opc);
|
||||||
|
|
||||||
|
if (opc)
|
||||||
|
return SR_OK;
|
||||||
|
|
||||||
|
g_usleep(SCPI_READ_RETRY_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SR_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|
|
@ -288,6 +288,7 @@ SR_PRIV int sr_scpi_get_float(struct sr_serial_dev_inst *serial,
|
||||||
const char *command, float *scpi_response);
|
const char *command, float *scpi_response);
|
||||||
SR_PRIV int sr_scpi_get_double(struct sr_serial_dev_inst *serial,
|
SR_PRIV int sr_scpi_get_double(struct sr_serial_dev_inst *serial,
|
||||||
const char *command, double *scpi_response);
|
const char *command, double *scpi_response);
|
||||||
|
SR_PRIV int sr_scpi_get_opc(struct sr_serial_dev_inst *serial);
|
||||||
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