]>
Commit | Line | Data |
---|---|---|
e93cdf42 | 1 | /* |
50985c20 | 2 | * This file is part of the libsigrok project. |
e93cdf42 BV |
3 | * |
4 | * Copyright (C) 2012 Bert Vermeulen <bert@biot.com> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
6ec6c43b | 20 | #include <config.h> |
e93cdf42 | 21 | #include <glib.h> |
e93cdf42 BV |
22 | #include <sys/types.h> |
23 | #include <sys/stat.h> | |
24 | #include <fcntl.h> | |
25 | #include <string.h> | |
c1aae900 | 26 | #include <libsigrok/libsigrok.h> |
6f22a8ef | 27 | #include "libsigrok-internal.h" |
6cf1a87b | 28 | #include "protocol.h" |
e93cdf42 | 29 | |
a0e0bb41 | 30 | static const uint32_t scanopts[] = { |
1953564a BV |
31 | SR_CONF_CONN, |
32 | SR_CONF_SERIALCOMM, | |
e93cdf42 BV |
33 | }; |
34 | ||
f9dada0b | 35 | static const uint32_t drvopts[] = { |
1953564a | 36 | SR_CONF_MULTIMETER, |
f9dada0b BV |
37 | }; |
38 | ||
39 | static const uint32_t devopts[] = { | |
e91bb0a6 | 40 | SR_CONF_CONTINUOUS, |
5827f61b BV |
41 | SR_CONF_LIMIT_SAMPLES | SR_CONF_SET, |
42 | SR_CONF_LIMIT_MSEC | SR_CONF_SET, | |
e93cdf42 BV |
43 | }; |
44 | ||
f857bd92 | 45 | extern const struct agdmm_job agdmm_jobs_u12xx[]; |
8c0152f2 | 46 | extern const struct agdmm_recv agdmm_recvs_u123x[]; |
4edba404 | 47 | extern const struct agdmm_recv agdmm_recvs_u124x[]; |
8c0152f2 | 48 | extern const struct agdmm_recv agdmm_recvs_u125x[]; |
43185ed3 | 49 | extern const struct agdmm_recv agdmm_recvs_u128x[]; |
e93cdf42 | 50 | |
74ac7d7f BV |
51 | /* This works on all the Agilent U12xxA series, although the |
52 | * U127xA can apparently also run at 19200/8n1. */ | |
53 | #define SERIALCOMM "9600/8n1" | |
54 | ||
e93cdf42 | 55 | static const struct agdmm_profile supported_agdmm[] = { |
d822726d AJ |
56 | { AGILENT_U1231, "U1231A", 1, agdmm_jobs_u12xx, agdmm_recvs_u123x }, |
57 | { AGILENT_U1232, "U1232A", 1, agdmm_jobs_u12xx, agdmm_recvs_u123x }, | |
58 | { AGILENT_U1233, "U1233A", 1, agdmm_jobs_u12xx, agdmm_recvs_u123x }, | |
59 | ||
60 | { AGILENT_U1241, "U1241A", 2, agdmm_jobs_u12xx, agdmm_recvs_u124x }, | |
61 | { AGILENT_U1242, "U1242A", 2, agdmm_jobs_u12xx, agdmm_recvs_u124x }, | |
62 | { AGILENT_U1241, "U1241B", 2, agdmm_jobs_u12xx, agdmm_recvs_u124x }, | |
63 | { AGILENT_U1242, "U1242B", 2, agdmm_jobs_u12xx, agdmm_recvs_u124x }, | |
64 | ||
65 | { AGILENT_U1251, "U1251A", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x }, | |
66 | { AGILENT_U1252, "U1252A", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x }, | |
67 | { AGILENT_U1253, "U1253A", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x }, | |
68 | { AGILENT_U1251, "U1251B", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x }, | |
69 | { AGILENT_U1252, "U1252B", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x }, | |
70 | { AGILENT_U1253, "U1253B", 3, agdmm_jobs_u12xx, agdmm_recvs_u125x }, | |
71 | ||
72 | { KEYSIGHT_U1281, "U1281A", 3, agdmm_jobs_u12xx, agdmm_recvs_u128x }, | |
73 | { KEYSIGHT_U1282, "U1282A", 3, agdmm_jobs_u12xx, agdmm_recvs_u128x }, | |
f857bd92 | 74 | ALL_ZERO |
e93cdf42 BV |
75 | }; |
76 | ||
4f840ce9 | 77 | static GSList *scan(struct sr_dev_driver *di, GSList *options) |
e93cdf42 BV |
78 | { |
79 | struct sr_dev_inst *sdi; | |
e93cdf42 | 80 | struct dev_context *devc; |
1987b8d6 | 81 | struct sr_config *src; |
109a3ba4 | 82 | struct sr_serial_dev_inst *serial; |
e93cdf42 | 83 | GSList *l, *devices; |
109a3ba4 | 84 | int len, i; |
e93cdf42 BV |
85 | const char *conn, *serialcomm; |
86 | char *buf, **tokens; | |
87 | ||
e93cdf42 BV |
88 | devices = NULL; |
89 | conn = serialcomm = NULL; | |
90 | for (l = options; l; l = l->next) { | |
1987b8d6 BV |
91 | src = l->data; |
92 | switch (src->key) { | |
1953564a | 93 | case SR_CONF_CONN: |
e44ac12a | 94 | conn = g_variant_get_string(src->data, NULL); |
e93cdf42 | 95 | break; |
1953564a | 96 | case SR_CONF_SERIALCOMM: |
e44ac12a | 97 | serialcomm = g_variant_get_string(src->data, NULL); |
e93cdf42 BV |
98 | break; |
99 | } | |
100 | } | |
74ac7d7f | 101 | if (!conn) |
e93cdf42 | 102 | return NULL; |
109a3ba4 BV |
103 | if (!serialcomm) |
104 | serialcomm = SERIALCOMM; | |
e93cdf42 | 105 | |
91219afc | 106 | serial = sr_serial_dev_inst_new(conn, serialcomm); |
e93cdf42 | 107 | |
64c536be | 108 | if (serial_open(serial, SERIAL_RDWR) != SR_OK) |
e93cdf42 | 109 | return NULL; |
e93cdf42 | 110 | |
109a3ba4 | 111 | serial_flush(serial); |
95779b43 | 112 | if (serial_write_blocking(serial, "*IDN?\r\n", 7, SERIAL_WRITE_TIMEOUT_MS) < 7) { |
081c214e | 113 | sr_err("Unable to send identification string."); |
e93cdf42 BV |
114 | return NULL; |
115 | } | |
116 | ||
117 | len = 128; | |
a95f142e | 118 | buf = g_malloc(len); |
ee2bcdfc | 119 | serial_readline(serial, &buf, &len, 250); |
e93cdf42 BV |
120 | if (!len) |
121 | return NULL; | |
122 | ||
123 | tokens = g_strsplit(buf, ",", 4); | |
9ae544b6 AJ |
124 | if ((!strcmp("Agilent Technologies", tokens[0]) || |
125 | !strcmp("Keysight Technologies", tokens[0])) | |
fbf07e02 | 126 | && tokens[1] && tokens[2] && tokens[3]) { |
e93cdf42 BV |
127 | for (i = 0; supported_agdmm[i].model; i++) { |
128 | if (strcmp(supported_agdmm[i].modelname, tokens[1])) | |
129 | continue; | |
aac29cc1 | 130 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be | 131 | sdi->status = SR_ST_INACTIVE; |
9ae544b6 | 132 | sdi->vendor = g_strdup(tokens[0][0] == 'A' ? "Agilent" : "Keysight"); |
0af636be UH |
133 | sdi->model = g_strdup(tokens[1]); |
134 | sdi->version = g_strdup(tokens[3]); | |
f57d8ffe | 135 | devc = g_malloc0(sizeof(struct dev_context)); |
5b6829ea | 136 | sr_sw_limits_init(&devc->limits); |
e93cdf42 | 137 | devc->profile = &supported_agdmm[i]; |
d822726d AJ |
138 | if (supported_agdmm[i].nb_channels > 1) { |
139 | int temp_chan = supported_agdmm[i].nb_channels - 1; | |
140 | devc->cur_mq[temp_chan] = SR_MQ_TEMPERATURE; | |
141 | devc->cur_unit[temp_chan] = SR_UNIT_CELSIUS; | |
142 | devc->cur_digits[temp_chan] = 1; | |
143 | devc->cur_encoding[temp_chan] = 2; | |
144 | } | |
fb3a1505 BV |
145 | sdi->inst_type = SR_INST_SERIAL; |
146 | sdi->conn = serial; | |
e93cdf42 | 147 | sdi->priv = devc; |
5e23fcab | 148 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); |
d822726d AJ |
149 | if (supported_agdmm[i].nb_channels > 1) |
150 | sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "P2"); | |
151 | if (supported_agdmm[i].nb_channels > 2) | |
152 | sr_channel_new(sdi, 2, SR_CHANNEL_ANALOG, TRUE, "P3"); | |
e93cdf42 BV |
153 | devices = g_slist_append(devices, sdi); |
154 | break; | |
155 | } | |
156 | } | |
157 | g_strfreev(tokens); | |
158 | g_free(buf); | |
159 | ||
109a3ba4 BV |
160 | serial_close(serial); |
161 | if (!devices) | |
162 | sr_serial_dev_inst_free(serial); | |
e93cdf42 | 163 | |
15a5bfe4 | 164 | return std_scan_complete(di, devices); |
e93cdf42 BV |
165 | } |
166 | ||
584560f1 | 167 | static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, |
53b4680f | 168 | const struct sr_channel_group *cg) |
e93cdf42 BV |
169 | { |
170 | struct dev_context *devc; | |
171 | ||
53b4680f | 172 | (void)cg; |
8f996b89 | 173 | |
e93cdf42 | 174 | if (sdi->status != SR_ST_ACTIVE) |
e73ffd42 | 175 | return SR_ERR_DEV_CLOSED; |
e93cdf42 | 176 | |
b0baddef | 177 | devc = sdi->priv; |
e93cdf42 | 178 | |
5b6829ea | 179 | return sr_sw_limits_config_set(&devc->limits, key, data); |
e93cdf42 BV |
180 | } |
181 | ||
584560f1 | 182 | static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
53b4680f | 183 | const struct sr_channel_group *cg) |
a1c743fc | 184 | { |
53b4680f | 185 | (void)cg; |
a1c743fc BV |
186 | |
187 | switch (key) { | |
0d485e30 | 188 | case SR_CONF_SCAN_OPTIONS: |
584560f1 | 189 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
a0e0bb41 | 190 | scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); |
0d485e30 | 191 | break; |
9a6517d1 | 192 | case SR_CONF_DEVICE_OPTIONS: |
ce4bd052 BV |
193 | if (!sdi) |
194 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
f9dada0b | 195 | drvopts, ARRAY_SIZE(drvopts), sizeof(uint32_t)); |
ce4bd052 BV |
196 | else |
197 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, | |
f9dada0b | 198 | devopts, ARRAY_SIZE(devopts), sizeof(uint32_t)); |
9a6517d1 | 199 | break; |
a1c743fc | 200 | default: |
bd6fbf62 | 201 | return SR_ERR_NA; |
a1c743fc BV |
202 | } |
203 | ||
204 | return SR_OK; | |
205 | } | |
206 | ||
695dc859 | 207 | static int dev_acquisition_start(const struct sr_dev_inst *sdi) |
e93cdf42 | 208 | { |
5b6829ea | 209 | struct dev_context *devc = sdi->priv; |
fb3a1505 | 210 | struct sr_serial_dev_inst *serial; |
e93cdf42 | 211 | |
e73ffd42 BV |
212 | if (sdi->status != SR_ST_ACTIVE) |
213 | return SR_ERR_DEV_CLOSED; | |
214 | ||
d822726d AJ |
215 | devc->cur_channel = sr_next_enabled_channel(sdi, NULL); |
216 | devc->cur_conf = sr_next_enabled_channel(sdi, NULL); | |
217 | devc->cur_mq[0] = -1; | |
218 | if (devc->profile->nb_channels > 2) | |
219 | devc->cur_mq[1] = -1; | |
220 | ||
5b6829ea | 221 | sr_sw_limits_acquisition_start(&devc->limits); |
bee2b016 | 222 | std_session_send_df_header(sdi); |
e93cdf42 | 223 | |
e93cdf42 | 224 | /* Poll every 100ms, or whenever some data comes in. */ |
fb3a1505 | 225 | serial = sdi->conn; |
102f1239 BV |
226 | serial_source_add(sdi->session, serial, G_IO_IN, 100, |
227 | agdmm_receive_data, (void *)sdi); | |
e93cdf42 BV |
228 | |
229 | return SR_OK; | |
230 | } | |
231 | ||
dd5c48a6 | 232 | static struct sr_dev_driver agdmm_driver_info = { |
e93cdf42 BV |
233 | .name = "agilent-dmm", |
234 | .longname = "Agilent U12xx series DMMs", | |
235 | .api_version = 1, | |
c2fdcc25 | 236 | .init = std_init, |
700d6b64 | 237 | .cleanup = std_cleanup, |
6078d2c9 | 238 | .scan = scan, |
c01bf34c | 239 | .dev_list = std_dev_list, |
a6630742 | 240 | .dev_clear = NULL, |
6fab7b8f | 241 | .config_get = NULL, |
035a1078 | 242 | .config_set = config_set, |
a1c743fc | 243 | .config_list = config_list, |
854434de | 244 | .dev_open = std_serial_dev_open, |
bf2c987f | 245 | .dev_close = std_serial_dev_close, |
6078d2c9 | 246 | .dev_acquisition_start = dev_acquisition_start, |
4b1a9d5d | 247 | .dev_acquisition_stop = std_serial_dev_acquisition_stop, |
41812aca | 248 | .context = NULL, |
e93cdf42 | 249 | }; |
dd5c48a6 | 250 | SR_REGISTER_DEV_DRIVER(agdmm_driver_info); |