2 * This file is part of the libsigrok project.
4 * Copyright (C) 2012-2013 Uwe Hermann <uwe@hermann-uwe.de>
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 2 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <libsigrok/libsigrok.h>
24 #include "libsigrok-internal.h"
27 #define UNI_T_UT_D04_NEW "1a86.e008"
29 static const uint32_t scanopts[] = {
33 static const uint32_t devopts[] = {
36 SR_CONF_LIMIT_SAMPLES | SR_CONF_SET,
37 SR_CONF_LIMIT_MSEC | SR_CONF_SET,
41 * Note 1: The actual baudrate of the Cyrustek ES519xx chip used in this DMM
42 * is 19230. However, the WCH CH9325 chip (UART to USB/HID) used in (some
43 * versions of) the UNI-T UT-D04 cable doesn't support 19230 baud. It only
44 * supports 19200, and setting an unsupported baudrate will result in the
45 * default of 2400 being used (which will not work with this DMM, of course).
48 static int dev_clear(const struct sr_dev_driver *di)
50 return std_dev_clear(di, NULL);
53 static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx)
55 return std_init(sr_ctx, di, LOG_PREFIX);
58 static GSList *scan(struct sr_dev_driver *di, GSList *options)
60 GSList *usb_devices, *devices, *l;
61 struct sr_dev_inst *sdi;
62 struct dev_context *devc;
63 struct drv_context *drvc;
65 struct sr_usb_dev_inst *usb;
66 struct sr_config *src;
70 dmm = (struct dmm_info *)di;
73 for (l = options; l; l = l->next) {
77 conn = g_variant_get_string(src->data, NULL);
85 if (!(usb_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn))) {
86 g_slist_free_full(usb_devices, g_free);
90 for (l = usb_devices; l; l = l->next) {
92 devc = g_malloc0(sizeof(struct dev_context));
93 devc->first_run = TRUE;
94 sdi = g_malloc0(sizeof(struct sr_dev_inst));
95 sdi->status = SR_ST_INACTIVE;
96 sdi->vendor = g_strdup(dmm->vendor);
97 sdi->model = g_strdup(dmm->device);
100 sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1");
101 sdi->inst_type = SR_INST_USB;
103 drvc->instances = g_slist_append(drvc->instances, sdi);
104 devices = g_slist_append(devices, sdi);
110 static GSList *dev_list(const struct sr_dev_driver *di)
112 return ((struct drv_context *)(di->context))->instances;
115 static int dev_open(struct sr_dev_inst *sdi)
117 struct sr_dev_driver *di;
118 struct drv_context *drvc;
119 struct sr_usb_dev_inst *usb;
126 if ((ret = sr_usb_open(drvc->sr_ctx->libusb_ctx, usb)) == SR_OK)
127 sdi->status = SR_ST_ACTIVE;
132 static int dev_close(struct sr_dev_inst *sdi)
136 sdi->status = SR_ST_INACTIVE;
141 static int cleanup(const struct sr_dev_driver *di)
143 return dev_clear(di);
146 static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
147 const struct sr_channel_group *cg)
149 struct dev_context *devc;
156 case SR_CONF_LIMIT_MSEC:
157 devc->limit_msec = g_variant_get_uint64(data);
159 case SR_CONF_LIMIT_SAMPLES:
160 devc->limit_samples = g_variant_get_uint64(data);
169 static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
170 const struct sr_channel_group *cg)
176 case SR_CONF_SCAN_OPTIONS:
177 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
178 scanopts, ARRAY_SIZE(scanopts), sizeof(uint32_t));
180 case SR_CONF_DEVICE_OPTIONS:
181 *data = g_variant_new_fixed_array(G_VARIANT_TYPE_UINT32,
182 devopts, ARRAY_SIZE(devopts), sizeof(uint32_t));
191 static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
193 struct dev_context *devc;
197 devc->cb_data = cb_data;
199 devc->starttime = g_get_monotonic_time();
201 /* Send header packet to the session bus. */
202 std_session_send_df_header(sdi, LOG_PREFIX);
204 sr_session_source_add(sdi->session, -1, 0, 10 /* poll_timeout */,
205 uni_t_dmm_receive_data, (void *)sdi);
210 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
212 struct sr_datafeed_packet packet;
216 sr_dbg("Stopping acquisition.");
218 /* Send end packet to the session bus. */
219 sr_dbg("Sending SR_DF_END.");
220 packet.type = SR_DF_END;
221 sr_session_send(sdi, &packet);
223 sr_session_source_remove(sdi->session, -1);
228 #define DMM(ID, CHIPSET, VENDOR, MODEL, BAUDRATE, PACKETSIZE, \
229 VALID, PARSE, DETAILS) \
230 &(struct dmm_info) { \
233 .longname = VENDOR " " MODEL, \
236 .cleanup = cleanup, \
238 .dev_list = dev_list, \
239 .dev_clear = dev_clear, \
240 .config_get = NULL, \
241 .config_set = config_set, \
242 .config_list = config_list, \
243 .dev_open = dev_open, \
244 .dev_close = dev_close, \
245 .dev_acquisition_start = dev_acquisition_start, \
246 .dev_acquisition_stop = dev_acquisition_stop, \
249 VENDOR, MODEL, BAUDRATE, PACKETSIZE, \
250 VALID, PARSE, DETAILS, sizeof(struct CHIPSET##_info) \
253 SR_PRIV const struct dmm_info *uni_t_dmm_drivers[] = {
255 "tecpel-dmm-8061", fs9721,
256 "Tecpel", "DMM-8061", 2400,
258 sr_fs9721_packet_valid, sr_fs9721_parse,
262 "uni-t-ut372", ut372,
263 "UNI-T", "UT372", 2400,
265 sr_ut372_packet_valid, sr_ut372_parse,
269 "uni-t-ut60a", fs9721,
270 "UNI-T", "UT60A", 2400,
272 sr_fs9721_packet_valid, sr_fs9721_parse,
276 "uni-t-ut60e", fs9721,
277 "UNI-T", "UT60E", 2400,
279 sr_fs9721_packet_valid, sr_fs9721_parse,
283 "uni-t-ut60g", es519xx,
284 /* The baudrate is actually 19230, see "Note 1" below. */
285 "UNI-T", "UT60G", 19200,
286 ES519XX_11B_PACKET_SIZE,
287 sr_es519xx_19200_11b_packet_valid, sr_es519xx_19200_11b_parse,
291 "uni-t-ut61b", fs9922,
292 "UNI-T", "UT61B", 2400,
294 sr_fs9922_packet_valid, sr_fs9922_parse,
298 "uni-t-ut61c", fs9922,
299 "UNI-T", "UT61C", 2400,
301 sr_fs9922_packet_valid, sr_fs9922_parse,
305 "uni-t-ut61d", fs9922,
306 "UNI-T", "UT61D", 2400,
308 sr_fs9922_packet_valid, sr_fs9922_parse,
312 "uni-t-ut61e", es519xx,
313 /* The baudrate is actually 19230, see "Note 1" below. */
314 "UNI-T", "UT61E", 19200,
315 ES519XX_14B_PACKET_SIZE,
316 sr_es519xx_19200_14b_packet_valid, sr_es519xx_19200_14b_parse,
320 "uni-t-ut71a", ut71x,
321 "UNI-T", "UT71A", 2400, UT71X_PACKET_SIZE,
322 sr_ut71x_packet_valid, sr_ut71x_parse, NULL
325 "uni-t-ut71b", ut71x,
326 "UNI-T", "UT71B", 2400, UT71X_PACKET_SIZE,
327 sr_ut71x_packet_valid, sr_ut71x_parse, NULL
330 "uni-t-ut71c", ut71x,
331 "UNI-T", "UT71C", 2400, UT71X_PACKET_SIZE,
332 sr_ut71x_packet_valid, sr_ut71x_parse, NULL
335 "uni-t-ut71d", ut71x,
336 "UNI-T", "UT71D", 2400, UT71X_PACKET_SIZE,
337 sr_ut71x_packet_valid, sr_ut71x_parse, NULL
340 "uni-t-ut71e", ut71x,
341 "UNI-T", "UT71E", 2400, UT71X_PACKET_SIZE,
342 sr_ut71x_packet_valid, sr_ut71x_parse, NULL
345 "voltcraft-vc820", fs9721,
346 "Voltcraft", "VC-820", 2400,
348 sr_fs9721_packet_valid, sr_fs9721_parse,
352 "voltcraft-vc830", fs9922,
354 * Note: The VC830 doesn't set the 'volt' and 'diode' bits of
355 * the FS9922 protocol. Instead, it only sets the user-defined
356 * bit "z1" to indicate "diode mode" and "voltage".
358 "Voltcraft", "VC-830", 2400,
360 sr_fs9922_packet_valid, sr_fs9922_parse,
364 "voltcraft-vc840", fs9721,
365 "Voltcraft", "VC-840", 2400,
367 sr_fs9721_packet_valid, sr_fs9721_parse,
371 "voltcraft-vc870", vc870,
372 "Voltcraft", "VC-870", 9600, VC870_PACKET_SIZE,
373 sr_vc870_packet_valid, sr_vc870_parse, NULL
376 "voltcraft-vc920", ut71x,
377 "Voltcraft", "VC-920", 2400, UT71X_PACKET_SIZE,
378 sr_ut71x_packet_valid, sr_ut71x_parse, NULL
381 "voltcraft-vc940", ut71x,
382 "Voltcraft", "VC-940", 2400, UT71X_PACKET_SIZE,
383 sr_ut71x_packet_valid, sr_ut71x_parse, NULL
386 "voltcraft-vc960", ut71x,
387 "Voltcraft", "VC-960", 2400, UT71X_PACKET_SIZE,
388 sr_ut71x_packet_valid, sr_ut71x_parse, NULL
391 "tenma-72-7745", es519xx,
392 "Tenma", "72-7745", 2400,
394 sr_fs9721_packet_valid, sr_fs9721_parse,
398 "tenma-72-7750", es519xx,
399 /* The baudrate is actually 19230, see "Note 1" below. */
400 "Tenma", "72-7750", 19200,
401 ES519XX_11B_PACKET_SIZE,
402 sr_es519xx_19200_11b_packet_valid, sr_es519xx_19200_11b_parse,