Ejemplo n.º 1
0
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	int ret;
	struct dev_context *devc;

	(void)cg;

	if (!sdi)
		return SR_ERR_ARG;

	devc = sdi->priv;

	ret = SR_OK;
	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		return sr_sw_limits_config_get(&devc->limits, key, data);
	case SR_CONF_POWER_OFF:
		*data = g_variant_new_boolean(FALSE);
		break;
	default:
		return SR_ERR_NA;
	}

	return ret;
}
Ejemplo n.º 2
0
static int config_get(uint32_t key, GVariant **data,
	const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
	struct dev_context *devc;

	(void)cg;

	if (!sdi || !data)
		return SR_ERR_ARG;

	devc = sdi->priv;

	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		return sr_sw_limits_config_get(&devc->limits, key, data);
	case SR_CONF_VOLTAGE:
		*data = g_variant_new_double(devc->voltage);
		break;
	case SR_CONF_VOLTAGE_TARGET:
		*data = g_variant_new_double(devc->voltage_max);
		break;
	case SR_CONF_CURRENT:
		*data = g_variant_new_double(devc->current);
		break;
	case SR_CONF_CURRENT_LIMIT:
		*data = g_variant_new_double(devc->current_max);
		break;
	case SR_CONF_ENABLED:
		*data = g_variant_new_boolean(devc->output_enabled);
		break;
	case SR_CONF_REGULATION:
		/* Dual channel not supported. */
		*data = g_variant_new_string((devc->cc_mode[0]) ? "CC" : "CV");
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(devc->ocp_enabled);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(devc->ovp_enabled);
		break;
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}
Ejemplo n.º 3
0
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc = sdi->priv;

	(void)cg;

	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		return sr_sw_limits_config_get(&devc->limits, key, data);
	case SR_CONF_DATA_SOURCE:
		*data = g_variant_new_string(data_sources[devc->data_source]);
		break;
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}
Ejemplo n.º 4
0
static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;

	(void)cg;

	if (!sdi)
		return SR_ERR_ARG;

	devc = sdi->priv;

	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		return sr_sw_limits_config_get(&devc->limits, key, data);
	case SR_CONF_VOLTAGE:
		*data = g_variant_new_double(devc->voltage);
		break;
	case SR_CONF_VOLTAGE_TARGET:
		*data = g_variant_new_double(devc->voltage_max);
		break;
	case SR_CONF_CURRENT:
		*data = g_variant_new_double(devc->current);
		break;
	case SR_CONF_CURRENT_LIMIT:
		*data = g_variant_new_double(devc->current_max);
		break;
	case SR_CONF_ENABLED:
		*data = g_variant_new_boolean(devc->output_enabled);
		break;
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}
Ejemplo n.º 5
0
static int config_get(uint32_t key, GVariant **data,
	const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	int ret;
	float fvalue;

	(void)cg;

	devc = sdi->priv;

	/*
	 * These features/keys are not supported by the hardware:
	 *  - SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE
	 *  - SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD
	 *  - SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE
	 *  - SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD
	 *  - SR_CONF_ENABLED (state cannot be queried, only set)
	 */

	ret = SR_OK;
	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		return sr_sw_limits_config_get(&devc->limits, key, data);
	case SR_CONF_REGULATION:
		*data = g_variant_new_string("CC"); /* Always CC mode. */
		break;
	case SR_CONF_VOLTAGE:
		if (reloadpro_get_voltage_current(sdi, &fvalue, NULL) < 0)
			return SR_ERR;
		*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_CURRENT:
		if (reloadpro_get_voltage_current(sdi, NULL, &fvalue) < 0)
			return SR_ERR;
		*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_CURRENT_LIMIT:
		if (reloadpro_get_current_limit(sdi, &fvalue) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(TRUE); /* Always on. */
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(TRUE); /* Always on. */
		break;
	case SR_CONF_OVER_TEMPERATURE_PROTECTION:
		*data = g_variant_new_boolean(TRUE); /* Always on. */
		break;
	case SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE:
		*data = g_variant_new_boolean(devc->otp_active);
		break;
	case SR_CONF_UNDER_VOLTAGE_CONDITION:
		*data = g_variant_new_boolean(TRUE); /* Always on. */
		break;
	case SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE:
		*data = g_variant_new_boolean(devc->uvc_active);
		break;
	default:
		return SR_ERR_NA;
	}

	return ret;
}
Ejemplo n.º 6
0
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
	struct sr_config default_serialcomm = {
	    .key = SR_CONF_SERIALCOMM,
	    .data = g_variant_new_string("9600/8n1"),
	};
	struct sr_config default_modbusaddr = {
	    .key = SR_CONF_MODBUSADDR,
	    .data = g_variant_new_uint64(1),
	};
	GSList *opts = options, *devices;

	if (!g_slist_find_custom(options, &default_serialcomm, config_compare))
		opts = g_slist_prepend(opts, &default_serialcomm);
	if (!g_slist_find_custom(options, &default_modbusaddr, config_compare))
		opts = g_slist_prepend(opts, &default_modbusaddr);

	devices = sr_modbus_scan(di->context, opts, probe_device);

	while (opts != options)
		opts = g_slist_delete_link(opts, opts);
	g_variant_unref(default_serialcomm.data);
	g_variant_unref(default_modbusaddr.data);

	return devices;
}

static int dev_open(struct sr_dev_inst *sdi)
{
	struct sr_modbus_dev_inst *modbus = sdi->conn;

	if (sr_modbus_open(modbus) < 0)
		return SR_ERR;

	sdi->status = SR_ST_ACTIVE;

	maynuo_m97_set_bit(modbus, PC1, 1);

	return SR_OK;
}

static int dev_close(struct sr_dev_inst *sdi)
{
	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) {
		devc = sdi->priv;
		if (devc->expecting_registers) {
			/* Wait for the last data that was requested from the device. */
			uint16_t registers[devc->expecting_registers];
			sr_modbus_read_holding_registers(modbus, -1,
			                                 devc->expecting_registers,
			                                 registers);
		}

		maynuo_m97_set_bit(modbus, PC1, 0);

		if (sr_modbus_close(modbus) < 0)
			return SR_ERR;
		sdi->status = SR_ST_INACTIVE;
	}

	return SR_OK;
}

static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	struct sr_modbus_dev_inst *modbus;
	enum maynuo_m97_mode mode;
	int ret, ivalue;
	float fvalue;

	(void)cg;

	modbus = sdi->conn;
	devc = sdi->priv;

	ret = SR_OK;
	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		ret = sr_sw_limits_config_get(&devc->limits, key, data);
		break;
	case SR_CONF_ENABLED:
		if ((ret = maynuo_m97_get_bit(modbus, ISTATE, &ivalue)) == SR_OK)
			*data = g_variant_new_boolean(ivalue);
		break;
	case SR_CONF_REGULATION:
		if ((ret = maynuo_m97_get_bit(modbus, UNREG, &ivalue)) != SR_OK)
			break;
		if (ivalue)
			*data = g_variant_new_string("UR");
		else if ((ret = maynuo_m97_get_mode(modbus, &mode)) == SR_OK)
			*data = g_variant_new_string(maynuo_m97_mode_to_str(mode));
		break;
	case SR_CONF_VOLTAGE:
		if ((ret = maynuo_m97_get_float(modbus, U, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_VOLTAGE_TARGET:
		if ((ret = maynuo_m97_get_float(modbus, UFIX, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_CURRENT:
		if ((ret = maynuo_m97_get_float(modbus, I, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_CURRENT_LIMIT:
		if ((ret = maynuo_m97_get_float(modbus, IFIX, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(TRUE);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE:
		if ((ret = maynuo_m97_get_bit(modbus, UOVER, &ivalue)) == SR_OK)
			*data = g_variant_new_boolean(ivalue);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD:
		if ((ret = maynuo_m97_get_float(modbus, UMAX, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(TRUE);
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE:
		if ((ret = maynuo_m97_get_bit(modbus, IOVER, &ivalue)) == SR_OK)
			*data = g_variant_new_boolean(ivalue);
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD:
		if ((ret = maynuo_m97_get_float(modbus, IMAX, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_OVER_TEMPERATURE_PROTECTION:
		*data = g_variant_new_boolean(TRUE);
		break;
	case SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE:
		if ((ret = maynuo_m97_get_bit(modbus, HEAT, &ivalue)) == SR_OK)
			*data = g_variant_new_boolean(ivalue);
		break;
	default:
		return SR_ERR_NA;
	}

	return ret;
}

static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	struct sr_modbus_dev_inst *modbus;
	int ret;

	(void)cg;

	if (sdi->status != SR_ST_ACTIVE)
		return SR_ERR_DEV_CLOSED;

	modbus = sdi->conn;
	devc = sdi->priv;

	ret = SR_OK;
	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		ret = sr_sw_limits_config_set(&devc->limits, key, data);
		break;
	case SR_CONF_ENABLED:
		ret = maynuo_m97_set_input(modbus, g_variant_get_boolean(data));
		break;
	case SR_CONF_VOLTAGE_TARGET:
		ret = maynuo_m97_set_float(modbus, UFIX, g_variant_get_double(data));
		break;
	case SR_CONF_CURRENT_LIMIT:
		ret = maynuo_m97_set_float(modbus, IFIX, g_variant_get_double(data));
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD:
		ret = maynuo_m97_set_float(modbus, UMAX, g_variant_get_double(data));
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD:
		ret = maynuo_m97_set_float(modbus, IMAX, g_variant_get_double(data));
		break;
	default:
		ret = SR_ERR_NA;
	}

	return ret;
}

static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
		const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	GVariantBuilder gvb;
	int ret;

	/* Always available, even without sdi. */
	if (key == SR_CONF_SCAN_OPTIONS) {
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
				scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
		return SR_OK;
	} else if (key == SR_CONF_DEVICE_OPTIONS && !sdi) {
		*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
				drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t));
		return SR_OK;
	}

	if (!sdi)
		return SR_ERR_ARG;
	devc = sdi->priv;

	ret = SR_OK;
	if (!cg) {
		/* No channel group: global options. */
		switch (key) {
		case SR_CONF_DEVICE_OPTIONS:
			*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
					devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
			break;
		default:
			return SR_ERR_NA;
		}
	} else {
		switch (key) {
		case SR_CONF_DEVICE_OPTIONS:
			*data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
					devopts_cg, ARRAY_SIZE(devopts_cg), sizeof(uint32_t));
			break;
		case SR_CONF_VOLTAGE_TARGET:
			g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
			/* Min, max, write resolution. */
			g_variant_builder_add_value(&gvb, g_variant_new_double(0.0));
			g_variant_builder_add_value(&gvb, g_variant_new_double(devc->model->max_voltage));
			g_variant_builder_add_value(&gvb, g_variant_new_double(0.001));
			*data = g_variant_builder_end(&gvb);
			break;
		case SR_CONF_CURRENT_LIMIT:
			g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY);
			/* Min, max, step. */
			g_variant_builder_add_value(&gvb, g_variant_new_double(0.0));
			g_variant_builder_add_value(&gvb, g_variant_new_double(devc->model->max_current));
			g_variant_builder_add_value(&gvb, g_variant_new_double(0.0001));
			*data = g_variant_builder_end(&gvb);
			break;
		default:
			return SR_ERR_NA;
		}
	}

	return ret;
}

static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
	struct dev_context *devc;
	struct sr_modbus_dev_inst *modbus;
	int ret;

	if (sdi->status != SR_ST_ACTIVE)
		return SR_ERR_DEV_CLOSED;

	modbus = sdi->conn;
	devc = sdi->priv;

	if ((ret = sr_modbus_source_add(sdi->session, modbus, G_IO_IN, 10,
			maynuo_m97_receive_data, (void *)sdi)) != SR_OK)
		return ret;

	sr_sw_limits_acquisition_start(&devc->limits);
	std_session_send_df_header(sdi);

	return maynuo_m97_capture_start(sdi);
}

static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
	struct sr_modbus_dev_inst *modbus;

	if (sdi->status != SR_ST_ACTIVE)
		return SR_ERR_DEV_CLOSED;

	std_session_send_df_end(sdi);

	modbus = sdi->conn;
	sr_modbus_source_remove(sdi->session, modbus);

	return SR_OK;
}

static struct sr_dev_driver maynuo_m97_driver_info = {
	.name = "maynuo-m97",
	.longname = "maynuo M97/M98 series",
	.api_version = 1,
	.init = std_init,
	.cleanup = std_cleanup,
	.scan = scan,
	.dev_list = std_dev_list,
	.config_get = config_get,
	.config_set = config_set,
	.config_list = config_list,
	.dev_open = dev_open,
	.dev_close = dev_close,
	.dev_acquisition_start = dev_acquisition_start,
	.dev_acquisition_stop = dev_acquisition_stop,
	.context = NULL,
};
SR_REGISTER_DEV_DRIVER(maynuo_m97_driver_info);
Ejemplo n.º 7
0
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
	struct sr_config default_serialcomm = {
		.key = SR_CONF_SERIALCOMM,
		.data = g_variant_new_string("9600/8n1"),
	};
	struct sr_config default_modbusaddr = {
		.key = SR_CONF_MODBUSADDR,
		.data = g_variant_new_uint64(1),
	};
	GSList *opts = options, *devices;

	if (!g_slist_find_custom(options, &default_serialcomm, config_compare))
		opts = g_slist_prepend(opts, &default_serialcomm);
	if (!g_slist_find_custom(options, &default_modbusaddr, config_compare))
		opts = g_slist_prepend(opts, &default_modbusaddr);

	devices = sr_modbus_scan(di->context, opts, probe_device);

	while (opts != options)
		opts = g_slist_delete_link(opts, opts);
	g_variant_unref(default_serialcomm.data);
	g_variant_unref(default_modbusaddr.data);

	return devices;
}

static int dev_open(struct sr_dev_inst *sdi)
{
	struct sr_modbus_dev_inst *modbus = sdi->conn;

	if (sr_modbus_open(modbus) < 0)
		return SR_ERR;

	maynuo_m97_set_bit(modbus, PC1, 1);

	return SR_OK;
}

static int dev_close(struct sr_dev_inst *sdi)
{
	struct dev_context *devc;
	struct sr_modbus_dev_inst *modbus;

	modbus = sdi->conn;

	if (!modbus)
		return SR_ERR_BUG;

	devc = sdi->priv;

	if (devc->expecting_registers) {
		/* Wait for the last data that was requested from the device. */
		uint16_t registers[devc->expecting_registers];
		sr_modbus_read_holding_registers(modbus, -1,
			devc->expecting_registers, registers);
	}

	maynuo_m97_set_bit(modbus, PC1, 0);

	return sr_modbus_close(modbus);
}

static int config_get(uint32_t key, GVariant **data,
	const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	struct sr_modbus_dev_inst *modbus;
	enum maynuo_m97_mode mode;
	int ret, ivalue;
	float fvalue;

	(void)cg;

	modbus = sdi->conn;
	devc = sdi->priv;

	ret = SR_OK;
	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		ret = sr_sw_limits_config_get(&devc->limits, key, data);
		break;
	case SR_CONF_ENABLED:
		if ((ret = maynuo_m97_get_bit(modbus, ISTATE, &ivalue)) == SR_OK)
			*data = g_variant_new_boolean(ivalue);
		break;
	case SR_CONF_REGULATION:
		if ((ret = maynuo_m97_get_bit(modbus, UNREG, &ivalue)) != SR_OK)
			break;
		if (ivalue)
			*data = g_variant_new_string("UR");
		else if ((ret = maynuo_m97_get_mode(modbus, &mode)) == SR_OK)
			*data = g_variant_new_string(maynuo_m97_mode_to_str(mode));
		break;
	case SR_CONF_VOLTAGE:
		if ((ret = maynuo_m97_get_float(modbus, U, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_VOLTAGE_TARGET:
		if ((ret = maynuo_m97_get_float(modbus, UFIX, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_CURRENT:
		if ((ret = maynuo_m97_get_float(modbus, I, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_CURRENT_LIMIT:
		if ((ret = maynuo_m97_get_float(modbus, IFIX, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(TRUE);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE:
		if ((ret = maynuo_m97_get_bit(modbus, UOVER, &ivalue)) == SR_OK)
			*data = g_variant_new_boolean(ivalue);
		break;
	case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD:
		if ((ret = maynuo_m97_get_float(modbus, UMAX, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
		*data = g_variant_new_boolean(TRUE);
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE:
		if ((ret = maynuo_m97_get_bit(modbus, IOVER, &ivalue)) == SR_OK)
			*data = g_variant_new_boolean(ivalue);
		break;
	case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD:
		if ((ret = maynuo_m97_get_float(modbus, IMAX, &fvalue)) == SR_OK)
			*data = g_variant_new_double(fvalue);
		break;
	case SR_CONF_OVER_TEMPERATURE_PROTECTION:
		*data = g_variant_new_boolean(TRUE);
		break;
	case SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE:
		if ((ret = maynuo_m97_get_bit(modbus, HEAT, &ivalue)) == SR_OK)
			*data = g_variant_new_boolean(ivalue);
		break;
	default:
		return SR_ERR_NA;
	}

	return ret;
}

static int config_set(uint32_t key, GVariant *data,
	const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
	struct dev_context *devc;
	struct sr_modbus_dev_inst *modbus;

	(void)cg;

	modbus = sdi->conn;
	devc = sdi->priv;

	switch (key) {
	case SR_CONF_LIMIT_SAMPLES:
	case SR_CONF_LIMIT_MSEC:
		return sr_sw_limits_config_set(&devc->limits, key, data);
	case SR_CONF_ENABLED:
		return maynuo_m97_set_input(modbus, g_variant_get_boolean(data));
	case SR_CONF_VOLTAGE_TARGET:
		return maynuo_m97_set_float(modbus, UFIX, g_variant_get_double(data));
	case SR_CONF_CURRENT_LIMIT:
		return maynuo_m97_set_float(modbus, IFIX, g_variant_get_double(data));
	case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD:
		return maynuo_m97_set_float(modbus, UMAX, g_variant_get_double(data));
	case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD:
		return maynuo_m97_set_float(modbus, IMAX, g_variant_get_double(data));
	default:
		return SR_ERR_NA;
	}

	return SR_OK;
}

static int config_list(uint32_t key, GVariant **data,
	const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
	struct dev_context *devc;

	devc = (sdi) ? sdi->priv : NULL;

	if (!cg) {
		return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
	} else {
		switch (key) {
		case SR_CONF_DEVICE_OPTIONS:
			*data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg));
			break;
		case SR_CONF_VOLTAGE_TARGET:
			if (!devc || !devc->model)
				return SR_ERR_ARG;
			*data = std_gvar_min_max_step(0.0, devc->model->max_voltage, 0.001);
			break;
		case SR_CONF_CURRENT_LIMIT:
			if (!devc || !devc->model)
				return SR_ERR_ARG;
			*data = std_gvar_min_max_step(0.0, devc->model->max_current, 0.0001);
			break;
		default:
			return SR_ERR_NA;
		}
	}

	return SR_OK;
}

static int dev_acquisition_start(const struct sr_dev_inst *sdi)
{
	struct dev_context *devc;
	struct sr_modbus_dev_inst *modbus;
	int ret;

	modbus = sdi->conn;
	devc = sdi->priv;

	if ((ret = sr_modbus_source_add(sdi->session, modbus, G_IO_IN, 10,
			maynuo_m97_receive_data, (void *)sdi)) != SR_OK)
		return ret;

	sr_sw_limits_acquisition_start(&devc->limits);
	std_session_send_df_header(sdi);

	return maynuo_m97_capture_start(sdi);
}

static int dev_acquisition_stop(struct sr_dev_inst *sdi)
{
	struct sr_modbus_dev_inst *modbus;

	std_session_send_df_end(sdi);

	modbus = sdi->conn;
	sr_modbus_source_remove(sdi->session, modbus);

	return SR_OK;
}

static struct sr_dev_driver maynuo_m97_driver_info = {
	.name = "maynuo-m97",
	.longname = "maynuo M97/M98 series",
	.api_version = 1,
	.init = std_init,
	.cleanup = std_cleanup,
	.scan = scan,
	.dev_list = std_dev_list,
	.dev_clear = std_dev_clear,
	.config_get = config_get,
	.config_set = config_set,
	.config_list = config_list,
	.dev_open = dev_open,
	.dev_close = dev_close,
	.dev_acquisition_start = dev_acquisition_start,
	.dev_acquisition_stop = dev_acquisition_stop,
	.context = NULL,
};
SR_REGISTER_DEV_DRIVER(maynuo_m97_driver_info);