]>
Commit | Line | Data |
---|---|---|
7b4edcb6 MH |
1 | /* |
2 | * This file is part of the libsigrok project. | |
3 | * | |
c90beca7 | 4 | * Copyright (C) 2013, 2014 Matthias Heidbrink <m-sigrok@heidbrink.biz> |
7b4edcb6 MH |
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 | ||
6392d599 MH |
20 | /** @file |
21 | * Gossen Metrawatt Metrahit 1x/2x drivers | |
c90beca7 | 22 | * @internal |
6392d599 MH |
23 | */ |
24 | ||
6ec6c43b | 25 | #include <config.h> |
f5792417 | 26 | #include <string.h> |
7b4edcb6 MH |
27 | #include "protocol.h" |
28 | ||
f5792417 MH |
29 | /* Serial communication parameters for Metrahit 1x/2x with 'RS232' adaptor */ |
30 | #define SERIALCOMM_1X_RS232 "8228/6n1/dtr=1/rts=1/flow=0" /* =8192, closer with divider */ | |
31 | #define SERIALCOMM_2X_RS232 "9600/6n1/dtr=1/rts=1/flow=0" | |
6392d599 | 32 | #define SERIALCOMM_2X "9600/8n1/dtr=1/rts=1/flow=0" |
f5792417 MH |
33 | #define VENDOR_GMC "Gossen Metrawatt" |
34 | ||
7b4edcb6 | 35 | SR_PRIV struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info; |
c90beca7 | 36 | SR_PRIV struct sr_dev_driver gmc_mh_2x_bd232_driver_info; |
7b4edcb6 | 37 | |
a0e0bb41 | 38 | static const uint32_t scanopts[] = { |
f5792417 MH |
39 | SR_CONF_CONN, |
40 | SR_CONF_SERIALCOMM, | |
41 | }; | |
42 | ||
c90beca7 | 43 | /** Hardware capabilities for Metrahit 1x/2x devices in send mode. */ |
f254bc4b | 44 | static const uint32_t devopts_sm[] = { |
f5792417 | 45 | SR_CONF_MULTIMETER, |
6392d599 | 46 | SR_CONF_THERMOMETER, /**< All GMC 1x/2x multimeters seem to support this */ |
f5792417 | 47 | SR_CONF_CONTINUOUS, |
5827f61b BV |
48 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, |
49 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
f5792417 MH |
50 | }; |
51 | ||
c90beca7 | 52 | /** Hardware capabilities for Metrahit 2x devices in bidirectional Mode. */ |
f254bc4b | 53 | static const uint32_t devopts_bd[] = { |
c90beca7 MH |
54 | SR_CONF_MULTIMETER, |
55 | SR_CONF_THERMOMETER, /**< All GMC 1x/2x multimeters seem to support this */ | |
c90beca7 | 56 | SR_CONF_CONTINUOUS, |
5827f61b BV |
57 | SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET, |
58 | SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET, | |
59 | SR_CONF_POWER_OFF | SR_CONF_GET | SR_CONF_SET, | |
c90beca7 MH |
60 | }; |
61 | ||
6392d599 MH |
62 | /* TODO: |
63 | * - For the 29S SR_CONF_ENERGYMETER, too. | |
64 | * - SR_CONF_PATTERN_MODE for some 2x devices | |
65 | * - SR_CONF_DATALOG for 22M, 26M, 29S and storage adaptors. | |
66 | * Need to implement device-specific lists. | |
67 | */ | |
68 | ||
4f840ce9 | 69 | static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) |
c90beca7 | 70 | { |
c45c32ce | 71 | return std_init(di, sr_ctx); |
7b4edcb6 MH |
72 | } |
73 | ||
fc348b77 UH |
74 | /** |
75 | * Read single byte from serial port. | |
76 | * | |
77 | * @retval -1 Timeout or error. | |
78 | * @retval other Byte. | |
f5792417 MH |
79 | */ |
80 | static int read_byte(struct sr_serial_dev_inst *serial, gint64 timeout) | |
7b4edcb6 | 81 | { |
fc348b77 | 82 | uint8_t result = 0; |
f5792417 MH |
83 | int rc = 0; |
84 | ||
85 | for (;;) { | |
0714a010 | 86 | rc = serial_read_nonblocking(serial, &result, 1); |
f5792417 MH |
87 | if (rc == 1) { |
88 | sr_spew("read: 0x%02x/%d", result, result); | |
89 | return result; | |
90 | } | |
91 | if (g_get_monotonic_time() > timeout) | |
92 | return -1; | |
93 | g_usleep(2000); | |
94 | } | |
95 | } | |
96 | ||
fc348b77 UH |
97 | /** |
98 | * Try to detect GMC 1x/2x multimeter model in send mode for max. 1 second. | |
f5792417 | 99 | * |
fc348b77 UH |
100 | * @param serial Configured, open serial port. |
101 | * | |
102 | * @retval NULL Detection failed. | |
103 | * @retval other Model code. | |
f5792417 MH |
104 | */ |
105 | static enum model scan_model_sm(struct sr_serial_dev_inst *serial) | |
106 | { | |
107 | int byte, bytecnt, cnt; | |
108 | enum model model; | |
109 | gint64 timeout_us; | |
110 | ||
873e0c12 | 111 | model = METRAHIT_NONE; |
1a46cc62 | 112 | timeout_us = g_get_monotonic_time() + (1 * 1000 * 1000); |
f5792417 | 113 | |
fc348b77 UH |
114 | /* |
115 | * Try to find message consisting of device code and several | |
116 | * (at least 4) data bytes. | |
117 | */ | |
f5792417 MH |
118 | for (bytecnt = 0; bytecnt < 100; bytecnt++) { |
119 | byte = read_byte(serial, timeout_us); | |
120 | if ((byte == -1) || (timeout_us < g_get_monotonic_time())) | |
121 | break; | |
122 | if ((byte & MSGID_MASK) == MSGID_INF) { | |
873e0c12 | 123 | if (!(model = gmc_decode_model_sm(byte & MSGC_MASK))) |
f5792417 | 124 | break; |
fc348b77 | 125 | /* Now expect (at least) 4 data bytes. */ |
f5792417 MH |
126 | for (cnt = 0; cnt < 4; cnt++) { |
127 | byte = read_byte(serial, timeout_us); | |
128 | if ((byte == -1) || | |
c90beca7 | 129 | ((byte & MSGID_MASK) != MSGID_DATA)) |
f5792417 | 130 | { |
873e0c12 | 131 | model = METRAHIT_NONE; |
f5792417 MH |
132 | bytecnt = 100; |
133 | break; | |
134 | } | |
135 | } | |
136 | break; | |
137 | } | |
138 | } | |
7b4edcb6 | 139 | |
f5792417 MH |
140 | return model; |
141 | } | |
142 | ||
fc348b77 UH |
143 | /** |
144 | * Scan for Metrahit 1x and Metrahit 2x in send mode using Gossen Metrawatt | |
145 | * 'RS232' interface. | |
146 | * | |
147 | * The older 1x models use 8192 baud and the newer 2x 9600 baud. | |
148 | * The DMM usually sends up to about 20 messages per second. However, depending | |
149 | * on configuration and measurement mode the intervals can be much larger and | |
150 | * then the detection might not work. | |
f5792417 | 151 | */ |
4f840ce9 | 152 | static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) |
f5792417 MH |
153 | { |
154 | struct sr_dev_inst *sdi; | |
155 | struct drv_context *drvc; | |
156 | struct dev_context *devc; | |
157 | struct sr_config *src; | |
f5792417 MH |
158 | struct sr_serial_dev_inst *serial; |
159 | GSList *l, *devices; | |
160 | const char *conn, *serialcomm; | |
161 | enum model model; | |
162 | gboolean serialcomm_given; | |
7b4edcb6 MH |
163 | |
164 | devices = NULL; | |
41812aca | 165 | drvc = di->context; |
7b4edcb6 | 166 | drvc->instances = NULL; |
f5792417 | 167 | conn = serialcomm = NULL; |
f5792417 MH |
168 | serialcomm_given = FALSE; |
169 | ||
c90beca7 | 170 | sr_spew("scan_1x_2x_rs232() called!"); |
f5792417 MH |
171 | |
172 | for (l = options; l; l = l->next) { | |
173 | src = l->data; | |
174 | switch (src->key) { | |
175 | case SR_CONF_CONN: | |
176 | conn = g_variant_get_string(src->data, NULL); | |
177 | break; | |
178 | case SR_CONF_SERIALCOMM: | |
179 | serialcomm = g_variant_get_string(src->data, NULL); | |
180 | serialcomm_given = TRUE; | |
181 | break; | |
182 | } | |
183 | } | |
184 | if (!conn) | |
185 | return NULL; | |
186 | if (!serialcomm) | |
187 | serialcomm = SERIALCOMM_2X_RS232; | |
188 | ||
91219afc | 189 | serial = sr_serial_dev_inst_new(conn, serialcomm); |
f5792417 | 190 | |
e13e354f | 191 | if (serial_open(serial, SERIAL_RDWR) != SR_OK) { |
f5792417 MH |
192 | sr_serial_dev_inst_free(serial); |
193 | return NULL; | |
194 | } | |
7b4edcb6 | 195 | |
f5792417 MH |
196 | serial_flush(serial); |
197 | ||
198 | model = scan_model_sm(serial); | |
199 | ||
fc348b77 UH |
200 | /* |
201 | * If detection failed and no user-supplied parameters, | |
202 | * try second baud rate. | |
203 | */ | |
873e0c12 | 204 | if ((model == METRAHIT_NONE) && !serialcomm_given) { |
f5792417 MH |
205 | serialcomm = SERIALCOMM_1X_RS232; |
206 | g_free(serial->serialcomm); | |
207 | serial->serialcomm = g_strdup(serialcomm); | |
208 | if (serial_set_paramstr(serial, serialcomm) == SR_OK) { | |
209 | serial_flush(serial); | |
210 | model = scan_model_sm(serial); | |
211 | } | |
212 | } | |
213 | ||
873e0c12 UH |
214 | if (model != METRAHIT_NONE) { |
215 | sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(model)); | |
aac29cc1 | 216 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
217 | sdi->status = SR_ST_INACTIVE; |
218 | sdi->vendor = g_strdup(VENDOR_GMC); | |
219 | sdi->model = g_strdup(gmc_model_str(model)); | |
f57d8ffe | 220 | devc = g_malloc0(sizeof(struct dev_context)); |
f5792417 MH |
221 | devc->model = model; |
222 | devc->limit_samples = 0; | |
223 | devc->limit_msec = 0; | |
224 | devc->num_samples = 0; | |
225 | devc->elapsed_msec = g_timer_new(); | |
226 | devc->settings_ok = FALSE; | |
f5792417 MH |
227 | sdi->conn = serial; |
228 | sdi->priv = devc; | |
4f840ce9 | 229 | sdi->driver = di; |
5e23fcab | 230 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); |
f5792417 MH |
231 | drvc->instances = g_slist_append(drvc->instances, sdi); |
232 | devices = g_slist_append(devices, sdi); | |
233 | } | |
7b4edcb6 MH |
234 | |
235 | return devices; | |
236 | } | |
237 | ||
1a863916 UH |
238 | /** |
239 | * Scan for Metrahit 2x in a bidirectional mode using Gossen Metrawatt | |
240 | * 'BD 232' interface. | |
c90beca7 | 241 | */ |
4f840ce9 | 242 | static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) |
c90beca7 MH |
243 | { |
244 | struct sr_dev_inst *sdi; | |
245 | struct drv_context *drvc; | |
246 | struct dev_context *devc; | |
247 | struct sr_config *src; | |
c90beca7 MH |
248 | struct sr_serial_dev_inst *serial; |
249 | GSList *l, *devices; | |
250 | const char *conn, *serialcomm; | |
251 | int cnt, byte; | |
252 | gint64 timeout_us; | |
253 | ||
254 | sdi = NULL; | |
255 | devc = NULL; | |
256 | conn = serialcomm = NULL; | |
257 | devices = NULL; | |
258 | ||
41812aca | 259 | drvc = di->context; |
c90beca7 MH |
260 | drvc->instances = NULL; |
261 | ||
262 | sr_spew("scan_2x_bd232() called!"); | |
263 | ||
264 | for (l = options; l; l = l->next) { | |
265 | src = l->data; | |
266 | switch (src->key) { | |
267 | case SR_CONF_CONN: | |
268 | conn = g_variant_get_string(src->data, NULL); | |
269 | break; | |
270 | case SR_CONF_SERIALCOMM: | |
271 | serialcomm = g_variant_get_string(src->data, NULL); | |
272 | break; | |
273 | } | |
274 | } | |
275 | if (!conn) | |
276 | return NULL; | |
277 | if (!serialcomm) | |
278 | serialcomm = SERIALCOMM_2X; | |
279 | ||
91219afc | 280 | serial = sr_serial_dev_inst_new(conn, serialcomm); |
c90beca7 | 281 | |
e13e354f | 282 | if (serial_open(serial, SERIAL_RDWR) != SR_OK) |
c90beca7 MH |
283 | goto exit_err; |
284 | ||
f57d8ffe | 285 | devc = g_malloc0(sizeof(struct dev_context)); |
c90beca7 | 286 | |
aac29cc1 | 287 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
288 | sdi->status = SR_ST_INACTIVE; |
289 | sdi->vendor = g_strdup(VENDOR_GMC); | |
c90beca7 MH |
290 | sdi->priv = devc; |
291 | ||
292 | /* Send message 03 "Query multimeter version and status" */ | |
293 | sdi->conn = serial; | |
c90beca7 MH |
294 | if (req_stat14(sdi, TRUE) != SR_OK) |
295 | goto exit_err; | |
296 | ||
297 | /* Wait for reply from device(s) for up to 2s. */ | |
1a46cc62 | 298 | timeout_us = g_get_monotonic_time() + (2 * 1000 * 1000); |
c90beca7 MH |
299 | |
300 | while (timeout_us > g_get_monotonic_time()) { | |
301 | /* Receive reply (14 bytes) */ | |
302 | devc->buflen = 0; | |
07ffa5b3 | 303 | for (cnt = 0; cnt < GMC_REPLY_SIZE; cnt++) { |
c90beca7 MH |
304 | byte = read_byte(serial, timeout_us); |
305 | if (byte != -1) | |
306 | devc->buf[devc->buflen++] = (byte & MASK_6BITS); | |
307 | } | |
308 | ||
07ffa5b3 | 309 | if (devc->buflen != GMC_REPLY_SIZE) |
c90beca7 MH |
310 | continue; |
311 | ||
312 | devc->addr = devc->buf[0]; | |
313 | process_msg14(sdi); | |
314 | devc->buflen = 0; | |
315 | ||
316 | if (devc->model != METRAHIT_NONE) { | |
317 | sr_spew("%s %s detected!", VENDOR_GMC, gmc_model_str(devc->model)); | |
c90beca7 | 318 | devc->elapsed_msec = g_timer_new(); |
c90beca7 MH |
319 | sdi->model = g_strdup(gmc_model_str(devc->model)); |
320 | sdi->version = g_strdup_printf("Firmware %d.%d", devc->fw_ver_maj, devc->fw_ver_min); | |
321 | sdi->conn = serial; | |
322 | sdi->priv = devc; | |
4f840ce9 | 323 | sdi->driver = di; |
5e23fcab | 324 | sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); |
c90beca7 MH |
325 | drvc->instances = g_slist_append(drvc->instances, sdi); |
326 | devices = g_slist_append(devices, sdi); | |
f57d8ffe | 327 | devc = g_malloc0(sizeof(struct dev_context)); |
aac29cc1 | 328 | sdi = g_malloc0(sizeof(struct sr_dev_inst)); |
0af636be UH |
329 | sdi->status = SR_ST_INACTIVE; |
330 | sdi->vendor = g_strdup(VENDOR_GMC); | |
c90beca7 MH |
331 | } |
332 | }; | |
333 | ||
334 | /* Free last alloc if no device found */ | |
335 | if (devc->model == METRAHIT_NONE) { | |
336 | g_free(devc); | |
337 | sr_dev_inst_free(sdi); | |
338 | } | |
339 | ||
340 | return devices; | |
341 | ||
342 | exit_err: | |
343 | sr_info("scan_2x_bd232(): Error!"); | |
344 | ||
345 | if (serial) | |
346 | sr_serial_dev_inst_free(serial); | |
b1f83103 | 347 | g_free(devc); |
c90beca7 MH |
348 | if (sdi) |
349 | sr_dev_inst_free(sdi); | |
350 | ||
351 | return NULL; | |
352 | } | |
353 | ||
7b4edcb6 MH |
354 | static int dev_close(struct sr_dev_inst *sdi) |
355 | { | |
f5792417 | 356 | struct dev_context *devc; |
7b4edcb6 | 357 | |
bf2c987f | 358 | std_serial_dev_close(sdi); |
7b4edcb6 MH |
359 | |
360 | sdi->status = SR_ST_INACTIVE; | |
361 | ||
f5792417 MH |
362 | /* Free dynamically allocated resources. */ |
363 | if ((devc = sdi->priv) && devc->elapsed_msec) { | |
364 | g_timer_destroy(devc->elapsed_msec); | |
365 | devc->elapsed_msec = NULL; | |
873e0c12 | 366 | devc->model = METRAHIT_NONE; |
f5792417 MH |
367 | } |
368 | ||
7b4edcb6 MH |
369 | return SR_OK; |
370 | } | |
371 | ||
584560f1 BV |
372 | static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
373 | const struct sr_channel_group *cg) | |
7b4edcb6 MH |
374 | { |
375 | int ret; | |
fadd0707 | 376 | struct dev_context *devc; |
c90beca7 | 377 | |
53b4680f | 378 | (void)cg; |
c90beca7 | 379 | |
6392d599 MH |
380 | if (!sdi || !(devc = sdi->priv)) |
381 | return SR_ERR_ARG; | |
382 | ||
7b4edcb6 MH |
383 | ret = SR_OK; |
384 | switch (key) { | |
6392d599 MH |
385 | case SR_CONF_LIMIT_SAMPLES: |
386 | *data = g_variant_new_uint64(devc->limit_samples); | |
387 | break; | |
388 | case SR_CONF_LIMIT_MSEC: | |
389 | *data = g_variant_new_uint64(devc->limit_msec); | |
390 | break; | |
c90beca7 MH |
391 | case SR_CONF_POWER_OFF: |
392 | *data = g_variant_new_boolean(FALSE); | |
393 | break; | |
7b4edcb6 MH |
394 | default: |
395 | return SR_ERR_NA; | |
396 | } | |
397 | ||
398 | return ret; | |
399 | } | |
400 | ||
1a863916 | 401 | /** Implementation of config_list, auxiliary function for common parts. */ |
584560f1 BV |
402 | static int config_list_common(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
403 | const struct sr_channel_group *cg) | |
7b4edcb6 | 404 | { |
c90beca7 | 405 | (void)sdi; |
53b4680f | 406 | (void)cg; |
7b4edcb6 | 407 | |
7b4edcb6 | 408 | switch (key) { |
c90beca7 | 409 | case SR_CONF_SCAN_OPTIONS: |
584560f1 | 410 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
5827f61b | 411 | scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t)); |
f5792417 | 412 | break; |
7b4edcb6 | 413 | default: |
f5792417 | 414 | return SR_ERR_NA; |
7b4edcb6 MH |
415 | } |
416 | ||
f5792417 | 417 | return SR_OK; |
7b4edcb6 MH |
418 | } |
419 | ||
c90beca7 | 420 | /** Implementation of config_list for Metrahit 1x/2x send mode */ |
584560f1 | 421 | static int config_list_sm(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
53b4680f | 422 | const struct sr_channel_group *cg) |
7b4edcb6 | 423 | { |
7b4edcb6 | 424 | switch (key) { |
c90beca7 | 425 | case SR_CONF_DEVICE_OPTIONS: |
584560f1 | 426 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
5827f61b | 427 | devopts_sm, ARRAY_SIZE(devopts_sm), sizeof(uint32_t)); |
f5792417 | 428 | break; |
c90beca7 | 429 | default: |
53b4680f | 430 | return config_list_common(key, data, sdi, cg); |
c90beca7 MH |
431 | } |
432 | ||
433 | return SR_OK; | |
434 | } | |
435 | ||
436 | /** Implementation of config_list for Metrahit 2x bidirectional mode */ | |
584560f1 | 437 | static int config_list_bd(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, |
53b4680f | 438 | const struct sr_channel_group *cg) |
c90beca7 | 439 | { |
c90beca7 | 440 | switch (key) { |
f5792417 | 441 | case SR_CONF_DEVICE_OPTIONS: |
584560f1 | 442 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32, |
5827f61b | 443 | devopts_bd, ARRAY_SIZE(devopts_bd), sizeof(uint32_t)); |
f5792417 | 444 | break; |
7b4edcb6 | 445 | default: |
53b4680f | 446 | return config_list_common(key, data, sdi, cg); |
7b4edcb6 MH |
447 | } |
448 | ||
f5792417 | 449 | return SR_OK; |
7b4edcb6 MH |
450 | } |
451 | ||
695dc859 | 452 | static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi) |
7b4edcb6 | 453 | { |
f5792417 MH |
454 | struct dev_context *devc; |
455 | struct sr_serial_dev_inst *serial; | |
456 | ||
7b4edcb6 MH |
457 | if (sdi->status != SR_ST_ACTIVE) |
458 | return SR_ERR_DEV_CLOSED; | |
459 | ||
208c1d35 | 460 | devc = sdi->priv; |
f5792417 MH |
461 | devc->settings_ok = FALSE; |
462 | devc->buflen = 0; | |
463 | ||
695dc859 | 464 | std_session_send_df_header(sdi, LOG_PREFIX); |
f5792417 MH |
465 | |
466 | /* Start timer, if required. */ | |
467 | if (devc->limit_msec) | |
468 | g_timer_start(devc->elapsed_msec); | |
469 | ||
470 | /* Poll every 40ms, or whenever some data comes in. */ | |
471 | serial = sdi->conn; | |
102f1239 BV |
472 | serial_source_add(sdi->session, serial, G_IO_IN, 40, |
473 | gmc_mh_1x_2x_receive_data, (void *)sdi); | |
7b4edcb6 MH |
474 | |
475 | return SR_OK; | |
476 | } | |
477 | ||
695dc859 | 478 | static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi) |
c90beca7 MH |
479 | { |
480 | struct dev_context *devc; | |
481 | struct sr_serial_dev_inst *serial; | |
482 | ||
c90beca7 MH |
483 | if (sdi->status != SR_ST_ACTIVE) |
484 | return SR_ERR_DEV_CLOSED; | |
485 | ||
208c1d35 | 486 | devc = sdi->priv; |
c90beca7 MH |
487 | devc->settings_ok = FALSE; |
488 | devc->buflen = 0; | |
489 | ||
695dc859 | 490 | std_session_send_df_header(sdi, LOG_PREFIX); |
c90beca7 MH |
491 | |
492 | /* Start timer, if required. */ | |
493 | if (devc->limit_msec) | |
494 | g_timer_start(devc->elapsed_msec); | |
495 | ||
496 | /* Poll every 40ms, or whenever some data comes in. */ | |
497 | serial = sdi->conn; | |
102f1239 BV |
498 | serial_source_add(sdi->session, serial, G_IO_IN, 40, |
499 | gmc_mh_2x_receive_data, (void *)sdi); | |
c90beca7 MH |
500 | |
501 | /* Send start message */ | |
502 | return req_meas14(sdi); | |
503 | } | |
504 | ||
695dc859 | 505 | static int dev_acquisition_stop(struct sr_dev_inst *sdi) |
7b4edcb6 | 506 | { |
f5792417 | 507 | struct dev_context *devc; |
7b4edcb6 | 508 | |
f5792417 MH |
509 | /* Stop timer, if required. */ |
510 | if (sdi && (devc = sdi->priv) && devc->limit_msec) | |
511 | g_timer_stop(devc->elapsed_msec); | |
7b4edcb6 | 512 | |
6525d819 | 513 | return std_serial_dev_acquisition_stop(sdi, dev_close, |
f5792417 | 514 | sdi->conn, LOG_PREFIX); |
7b4edcb6 MH |
515 | } |
516 | ||
517 | SR_PRIV struct sr_dev_driver gmc_mh_1x_2x_rs232_driver_info = { | |
518 | .name = "gmc-mh-1x-2x-rs232", | |
a90061e5 | 519 | .longname = "Gossen Metrawatt Metrahit 1x/2x, RS232 interface", |
7b4edcb6 | 520 | .api_version = 1, |
4f840ce9 | 521 | .init = init, |
700d6b64 | 522 | .cleanup = std_cleanup, |
c90beca7 | 523 | .scan = scan_1x_2x_rs232, |
c01bf34c | 524 | .dev_list = std_dev_list, |
a6630742 | 525 | .dev_clear = NULL, |
c90beca7 MH |
526 | .config_get = config_get, |
527 | .config_set = config_set, | |
528 | .config_list = config_list_sm, | |
529 | .dev_open = std_serial_dev_open, | |
530 | .dev_close = dev_close, | |
531 | .dev_acquisition_start = dev_acquisition_start_1x_2x_rs232, | |
532 | .dev_acquisition_stop = dev_acquisition_stop, | |
41812aca | 533 | .context = NULL, |
c90beca7 MH |
534 | }; |
535 | ||
536 | SR_PRIV struct sr_dev_driver gmc_mh_2x_bd232_driver_info = { | |
537 | .name = "gmc-mh-2x-bd232", | |
a90061e5 | 538 | .longname = "Gossen Metrawatt Metrahit 2x, BD232/SI232-II interface", |
c90beca7 | 539 | .api_version = 1, |
4f840ce9 | 540 | .init = init, |
700d6b64 | 541 | .cleanup = std_cleanup, |
c90beca7 | 542 | .scan = scan_2x_bd232, |
c01bf34c | 543 | .dev_list = std_dev_list, |
a6630742 | 544 | .dev_clear = NULL, |
7b4edcb6 MH |
545 | .config_get = config_get, |
546 | .config_set = config_set, | |
c90beca7 | 547 | .config_list = config_list_bd, |
854434de | 548 | .dev_open = std_serial_dev_open, |
7b4edcb6 | 549 | .dev_close = dev_close, |
c90beca7 | 550 | .dev_acquisition_start = dev_acquisition_start_2x_bd232, |
27fd2eaa | 551 | .dev_acquisition_stop = dev_acquisition_stop, |
41812aca | 552 | .context = NULL, |
7b4edcb6 | 553 | }; |