2 * This file is part of the libsigrok project.
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
5 * Copyright (C) 2017 John Chajecki <subs@qcontinuum.plus.com>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/types.h>
29 #include <libsigrok/libsigrok.h>
30 #include "libsigrok-internal.h"
34 static const uint32_t scanopts[] = {
39 static const uint32_t drvopts[] = {
43 static const uint32_t devopts[] = {
45 SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
46 SR_CONF_LIMIT_MSEC | SR_CONF_SET,
49 /* Vendor, model, number of channels, poll period */
50 static const struct fluke_scpi_dmm_model supported_models[] = {
51 { "FLUKE", "45", 2, 0 },
54 static struct sr_dev_driver fluke_45_driver_info;
56 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
58 struct dev_context *devc;
59 struct sr_dev_inst *sdi;
60 struct sr_scpi_hw_info *hw_info;
61 const struct scpi_command *cmdset = fluke_45_cmdset;
63 const struct fluke_scpi_dmm_model *model = NULL;
67 sdi = g_malloc0(sizeof(struct sr_dev_inst));
70 /* Test for serial port ECHO enabled. */
71 sr_scpi_get_string(scpi, "ECHO-TEST", &response);
72 if (strcmp(response, "ECHO-TEST") == 0) {
73 sr_err("Serial port ECHO is ON. Please turn it OFF!");
78 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
79 sr_info("Couldn't get IDN response, retrying.");
82 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
83 sr_info("Couldn't get IDN response.");
89 for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
90 if (!g_ascii_strcasecmp(hw_info->manufacturer,
91 supported_models[i].vendor) &&
92 !strcmp(hw_info->model, supported_models[i].model)) {
93 model = &supported_models[i];
98 sr_scpi_hw_info_free(hw_info);
102 /* Set up device parameters. */
103 sdi->vendor = g_strdup(model->vendor);
104 sdi->model = g_strdup(model->model);
105 sdi->version = g_strdup(hw_info->firmware_version);
106 sdi->serial_num = g_strdup(hw_info->serial_number);
108 sdi->driver = &fluke_45_driver_info;
109 sdi->inst_type = SR_INST_SCPI;
111 devc = g_malloc0(sizeof(struct dev_context));
112 devc->num_channels = model->num_channels;
113 devc->cmdset = cmdset;
115 /* Create channels. */
116 for (i = 0; i < devc->num_channels; i++) {
117 channel_name = g_strdup_printf("P%d", i + 1);
118 sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, channel_name);
126 static GSList *scan(struct sr_dev_driver *di, GSList *options)
128 return sr_scpi_scan(di->context, options, probe_device);
131 static int dev_open(struct sr_dev_inst *sdi)
133 struct sr_scpi_dev_inst *scpi;
138 if ((ret = sr_scpi_open(scpi) < 0)) {
139 sr_err("Failed to open SCPI device: %s.", sr_strerror(ret));
146 static int dev_close(struct sr_dev_inst *sdi)
148 struct sr_scpi_dev_inst *scpi;
155 return sr_scpi_close(scpi);
158 static int config_set(uint32_t key, GVariant *data,
159 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
161 struct dev_context *devc;
167 return sr_sw_limits_config_set(&devc->limits, key, data);
170 static int config_list(uint32_t key, GVariant **data,
171 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
173 return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
176 static int config_get(uint32_t key, GVariant **data,
177 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
179 struct dev_context *devc = sdi->priv;
183 return sr_sw_limits_config_get(&devc->limits, key, data);
186 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
188 struct sr_scpi_dev_inst *scpi;
189 struct dev_context *devc;
195 sr_sw_limits_acquisition_start(&devc->limits);
196 std_session_send_df_header(sdi);
198 if ((ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10,
199 fl45_scpi_receive_data, (void *)sdi)) != SR_OK)
205 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
207 struct sr_scpi_dev_inst *scpi;
213 * A requested value is certainly on the way. Retrieve it now,
214 * to avoid leaving the device in a state where it's not expecting
217 sr_scpi_get_double(scpi, NULL, &d);
218 sr_scpi_source_remove(sdi->session, scpi);
220 std_session_send_df_end(sdi);
225 static struct sr_dev_driver fluke_45_driver_info = {
227 .longname = "Fluke 45",
230 .cleanup = std_cleanup,
232 .dev_list = std_dev_list,
233 .dev_clear = std_dev_clear,
234 .config_get = config_get,
235 .config_set = config_set,
236 .config_list = config_list,
237 .dev_open = dev_open,
238 .dev_close = dev_close,
239 .dev_acquisition_start = dev_acquisition_start,
240 .dev_acquisition_stop = dev_acquisition_stop,
243 SR_REGISTER_DEV_DRIVER(fluke_45_driver_info);