Add sr_scpi_read() operation for reading arbitrary data.

This commit is contained in:
Martin Ling 2013-12-03 22:56:32 +00:00
parent 31034792da
commit a1ff9c1897
4 changed files with 34 additions and 0 deletions

View File

@ -146,6 +146,21 @@ SR_PRIV int sr_scpi_receive(struct sr_scpi_dev_inst *scpi,
return scpi->receive(scpi->priv, scpi_response);
}
/**
* Read part of a response from SCPI device.
*
* @param scpi Previously initialised SCPI device structure.
* @param buf Buffer to store result.
* @param maxlen Maximum number of bytes to read.
*
* @return Number of bytes read, or SR_ERR upon failure.
*/
SR_PRIV int sr_scpi_read(struct sr_scpi_dev_inst *scpi,
char *buf, int maxlen)
{
return scpi->read(scpi->priv, buf, maxlen);
}
/**
* Close SCPI device.
*

View File

@ -151,6 +151,7 @@ SR_PRIV struct sr_scpi_dev_inst *scpi_serial_dev_inst_new(const char *port,
scpi->source_remove = scpi_serial_source_remove;
scpi->send = scpi_serial_send;
scpi->receive = scpi_serial_receive;
scpi->read = serial_read;
scpi->close = serial_close;
scpi->free = sr_serial_dev_inst_free;
scpi->priv = serial;

View File

@ -111,6 +111,21 @@ SR_PRIV int scpi_usbtmc_receive(void *priv, char **scpi_response)
return SR_OK;
}
SR_PRIV int scpi_usbtmc_read(void *priv, unsigned char *buf, int maxlen)
{
struct sr_usbtmc_dev_inst *usbtmc = priv;
int len;
len = read(usbtmc->fd, buf, maxlen);
if (len < 0) {
sr_err("Read error: %s", strerror(errno));
return SR_ERR;
}
return len;
}
SR_PRIV int scpi_usbtmc_close(void *priv)
{
struct sr_usbtmc_dev_inst *usbtmc = priv;
@ -139,6 +154,7 @@ SR_PRIV struct sr_scpi_dev_inst *scpi_usbtmc_dev_inst_new(const char *device)
scpi->source_remove = scpi_usbtmc_source_remove;
scpi->send = scpi_usbtmc_send;
scpi->receive = scpi_usbtmc_receive;
scpi->read = scpi_usbtmc_read;
scpi->close = scpi_usbtmc_close;
scpi->free = sr_usbtmc_dev_inst_free;
scpi->priv = usbtmc;

View File

@ -292,6 +292,7 @@ struct sr_scpi_dev_inst {
int (*source_remove)(void *priv);
int (*send)(void *priv, const char *command);
int (*receive)(void *priv, char **scpi_response);
int (*read)(void *priv, char *buf, int maxlen);
int (*close)(void *priv);
void (*free)(void *priv);
void *priv;
@ -305,6 +306,7 @@ SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi,
const char *command);
SR_PRIV int sr_scpi_receive(struct sr_scpi_dev_inst *scpi,
char **scpi_response);
SR_PRIV int sr_scpi_read(struct sr_scpi_dev_inst *scpi, char *buf, int maxlen);
SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi);
SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi);