if (!sdi || !sdi->driver || !sdi->driver->dev_close)
return SR_ERR;
+ if (sdi->status != SR_ST_ACTIVE) {
+ sr_err("%s: Device instance not active, can't close.",
+ sdi->driver->name);
+ return SR_ERR_DEV_CLOSED;
+ }
+
+ sr_dbg("%s: Closing device.", sdi->driver->name)
+
ret = sdi->driver->dev_close(sdi);
return ret;
devc = sdi->priv;
- /* TODO */
- if (sdi->status == SR_ST_ACTIVE)
- ftdi_usb_close(&devc->ftdic);
+ ftdi_usb_close(&devc->ftdic);
sdi->status = SR_ST_INACTIVE;
{
struct dev_context *devc = sdi->priv;
- if (sdi->status == SR_ST_ACTIVE) {
- /* Close the memory mapping and the file */
- beaglelogic_munmap(devc);
- beaglelogic_close(devc);
- }
+ /* Close the memory mapping and the file */
+ beaglelogic_munmap(devc);
+ beaglelogic_close(devc);
+
sdi->status = SR_ST_INACTIVE;
+
return SR_OK;
}
struct dev_context *devc;
int ret;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
usb = sdi->conn;
devc = sdi->priv;
int ret;
struct dev_context *devc;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_OK;
-
devc = sdi->priv;
if (devc->ftdic && (ret = ftdi_usb_close(devc->ftdic)) < 0)
sr_err("Failed to close FTDI device (%d): %s.",
ret, ftdi_get_error_string(devc->ftdic));
+
sdi->status = SR_ST_INACTIVE;
return SR_OK;
std_serial_dev_close(sdi);
- sdi->status = SR_ST_INACTIVE;
if ((devc = sdi->priv))
devc->model = METRAHIT_NONE;
{
struct sr_scpi_dev_inst *scpi;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
scpi = sdi->conn;
if (scpi) {
if (sr_scpi_close(scpi) < 0)
static int dev_close(struct sr_dev_inst *sdi)
{
- if (sdi->status == SR_ST_INACTIVE)
- return SR_OK;
-
sr_scpi_close(sdi->conn);
sdi->status = SR_ST_INACTIVE;
{
struct sr_scpi_dev_inst *scpi = sdi->conn;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
/* Disable scan-advance (preserve relay life). */
sr_scpi_send(scpi, "SADV HOLD");
/* Switch back to auto-triggering. */
{
struct dev_context *devc = sdi->priv;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_OK;
-
g_free(devc->samples);
hung_chang_dso_2100_reset_port(sdi->conn);
ieee1284_release(sdi->conn);
ieee1284_close(sdi->conn);
+
sdi->status = SR_ST_INACTIVE;
return SR_OK;
std_session_send_df_end(sdi);
- sdi->driver->dev_close(sdi);
+ sr_dev_close(sdi);
}
static void buffer_sample_data(const struct sr_dev_inst *sdi)
static int dev_close(struct sr_dev_inst *sdi)
{
- int ret;
struct dev_context *devc;
- ret = SR_OK;
devc = sdi->priv;
- if (sdi->status == SR_ST_ACTIVE) {
- sr_dbg("Status ACTIVE, closing device.");
- ret = scanaplus_close(devc);
- } else {
- sr_spew("Status not ACTIVE, nothing to do.");
- }
-
sdi->status = SR_ST_INACTIVE;
- return ret;
+ return scanaplus_close(devc);
}
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
static int dev_close(struct sr_dev_inst *sdi)
{
- if (sdi->status == SR_ST_INACTIVE)
- return SR_OK;
-
sr_scpi_close(sdi->conn);
sdi->status = SR_ST_INACTIVE;
struct dev_context *devc;
struct sr_modbus_dev_inst *modbus;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
modbus = sdi->conn;
if (modbus) {
static int dev_close(struct sr_dev_inst *sdi)
{
- int ret;
struct dev_context *devc;
- ret = SR_OK;
devc = sdi->priv;
- if (sdi->status == SR_ST_ACTIVE) {
- sr_dbg("Status ACTIVE, closing device.");
- ret = p_ols_close(devc);
- } else {
- sr_spew("Status not ACTIVE, nothing to do.");
- }
-
sdi->status = SR_ST_INACTIVE;
- return ret;
+ return p_ols_close(devc);
}
static int set_trigger(const struct sr_dev_inst *sdi, int stage)
struct sr_scpi_dev_inst *scpi;
struct dev_context *devc;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
scpi = sdi->conn;
devc = sdi->priv;
static int dev_close(struct sr_dev_inst *sdi)
{
- if (sdi->status == SR_ST_INACTIVE)
- return SR_OK;
-
sr_scpi_close(sdi->conn);
sdi->status = SR_ST_INACTIVE;
struct sr_scpi_dev_inst *scpi;
struct dev_context *devc;
- if (sdi->status != SR_ST_ACTIVE)
- return SR_ERR_DEV_CLOSED;
-
devc = sdi->priv;
scpi = sdi->conn;
if (scpi) {
devc = sdi->priv;
usb = sdi->conn;
- if (sdi->status == SR_ST_INACTIVE) {
- sr_dbg("Device already closed.");
- return SR_OK;
- }
if (devc->acquisition) {
sr_err("Cannot close device during acquisition!");
/* Request stop, leak handle, and prepare for the worst. */
/* Got a complete packet. */
break;
}
- sdi->driver->dev_close(sdi);
+ sr_dev_close(sdi);
if (packet[6] > MAX_CHANNELS) {
sr_err("Device says it has %d channels!", packet[6]);
static int dev_close(struct sr_dev_inst *sdi)
{
- if (sdi->status == SR_ST_INACTIVE)
- return SR_OK;
-
sr_scpi_close(sdi->conn);
sdi->status = SR_ST_INACTIVE;
SR_MHZ(200),
};
-static int dev_close(struct sr_dev_inst *sdi);
-
SR_PRIV int zp_set_samplerate(struct dev_context *devc, uint64_t samplerate)
{
int i;
* to SR_ST_INACTIVE.
*
* @retval SR_OK Success.
+ * @retval SR_ERR_ARG Invalid arguments.
*/
SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi)
{
struct sr_serial_dev_inst *serial;
+ sdi->status = SR_ST_INACTIVE;
+
serial = sdi->conn;
- if (serial && sdi->status == SR_ST_ACTIVE) {
- serial_close(serial);
- sdi->status = SR_ST_INACTIVE;
+ if (!serial) {
+ sr_err("%s: Can't close invalid serial port.", sdi->driver->name);
+ return SR_ERR_ARG;
}
+ serial_close(serial);
+
return SR_OK;
}
return ret;
}
- if ((ret = sdi->driver->dev_close(sdi)) < 0) {
+ if ((ret = sr_dev_close(sdi)) < 0) {
sr_err("%s: Failed to close device: %d.", prefix, ret);
return ret;
}