serial-dmm: Implemented support for Voltcraft M-3650CR (driver voltcraft-m3650cr).

This commit is contained in:
Matthias Heidbrink 2014-03-24 21:50:07 +01:00 committed by Uwe Hermann
parent 1656e47def
commit e83437ae20
6 changed files with 69 additions and 25 deletions

View File

@ -18,9 +18,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
/**
* @file
*
* Metex 14-bytes ASCII protocol parser.
*
* @internal
* This should work for various multimeters which use this kind of protocol,
* even though there is some variation in which modes each DMM supports.
*
@ -36,7 +39,9 @@
#define LOG_PREFIX "metex14"
static int parse_value(const uint8_t *buf, float *result)
/** Parse value from buf, byte 2-8. */
static int parse_value(const uint8_t *buf, struct metex14_info *info,
float *result)
{
int i, is_ol, cnt;
char valstr[7 + 1];
@ -64,6 +69,21 @@ static int parse_value(const uint8_t *buf, float *result)
return SR_OK;
}
/* Logic functions */
if (!strcmp((const char *)&valstr, "READY") ||
!strcmp((const char *)&valstr, "FLOAT")) {
*result = INFINITY;
info->is_logic = TRUE;
} else if (!strcmp((const char *)&valstr, "Hi")) {
*result = 1.0;
info->is_logic = TRUE;
} else if (!strcmp((const char *)&valstr, "Lo")) {
*result = 0.0;
info->is_logic = TRUE;
}
if (info->is_logic)
return SR_OK;
/* Bytes 2-8: Sign, value (up to 5 digits) and decimal point */
sscanf((const char *)&valstr, "%f", result);
@ -78,25 +98,9 @@ static void parse_flags(const char *buf, struct metex14_info *info)
char unit[4 + 1];
const char *u;
/* Bytes 0-1: Measurement mode */
/* Note: Protocol doesn't distinguish "resistance" from "beep" mode. */
info->is_ac = !strncmp(buf, "AC", 2);
info->is_dc = !strncmp(buf, "DC", 2);
info->is_resistance = !strncmp(buf, "OH", 2);
info->is_capacity = !strncmp(buf, "CA", 2);
info->is_temperature = !strncmp(buf, "TE", 2);
info->is_diode = !strncmp(buf, "DI", 2);
info->is_frequency = !strncmp(buf, "FR", 2);
info->is_gain = !strncmp(buf, "DB", 2);
info->is_hfe = !strncmp(buf, "HF", 2);
/*
* Note: "DB" shows the logarithmic ratio of input voltage to a
* pre-stored (user-changeable) value in the DMM.
*/
if (info->is_dc || info->is_ac)
info->is_volt = TRUE;
/* Bytes 0-1: Measurement mode AC, DC */
info->is_ac = !strncmp(buf, "AC", 2);
info->is_dc = !strncmp(buf, "DC", 2);
/* Bytes 2-8: See parse_value(). */
@ -140,6 +144,27 @@ static void parse_flags(const char *buf, struct metex14_info *info)
else if (!strcasecmp(u, ""))
info->is_unitless = TRUE;
/* Bytes 0-1: Measurement mode, except AC/DC */
info->is_resistance = !strncmp(buf, "OH", 2) ||
(!strncmp(buf, " ", 2) && info->is_ohm);
info->is_capacity = !strncmp(buf, "CA", 2) ||
(!strncmp(buf, " ", 2) && info->is_farad);
info->is_temperature = !strncmp(buf, "TE", 2);
info->is_diode = !strncmp(buf, "DI", 2) ||
(!strncmp(buf, " ", 2) && info->is_volt && info->is_milli);
info->is_frequency = !strncmp(buf, "FR", 2) ||
(!strncmp(buf, " ", 2) && info->is_hertz);
info->is_gain = !strncmp(buf, "DB", 2);
info->is_hfe = !strncmp(buf, "HF", 2) ||
(!strncmp(buf, " ", 2) && !info->is_volt && !info->is_ohm &&
!info->is_logic && !info->is_farad && !info->is_hertz);
/*
* Note:
* - Protocol doesn't distinguish "resistance" from "beep" mode.
* - "DB" shows the logarithmic ratio of input voltage to a
* pre-stored (user-changeable) value in the DMM.
*/
/* Byte 13: Always '\r' (carriage return, 0x0d, 13) */
}
@ -197,6 +222,10 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval,
analog->mq = SR_MQ_GAIN;
analog->unit = SR_UNIT_UNITLESS;
}
if (info->is_logic) {
analog->mq = SR_MQ_GAIN;
analog->unit = SR_UNIT_UNITLESS;
}
/* Measurement related flags */
if (info->is_ac)
@ -300,12 +329,13 @@ SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
/* Don't print byte 13. That one contains the carriage return. */
sr_dbg("DMM packet: \"%.13s\"", buf);
if ((ret = parse_value(buf, floatval)) != SR_OK) {
memset(info_local, 0x00, sizeof(struct metex14_info));
if ((ret = parse_value(buf, info_local, floatval)) != SR_OK) {
sr_dbg("Error parsing value: %d.", ret);
return ret;
}
memset(info_local, 0x00, sizeof(struct metex14_info));
parse_flags((const char *)buf, info_local);
handle_flags(analog, floatval, info_local);

View File

@ -57,6 +57,7 @@ SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info;
SR_PRIV struct sr_dev_driver radioshack_22_805_driver_info;
SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info;
SR_PRIV struct sr_dev_driver tecpel_dmm_8061_ser_driver_info;
SR_PRIV struct sr_dev_driver voltcraft_m3650cr_driver_info;
SR_PRIV struct sr_dev_driver voltcraft_m3650d_driver_info;
SR_PRIV struct sr_dev_driver voltcraft_m4650cr_driver_info;
SR_PRIV struct sr_dev_driver voltcraft_me42_driver_info;
@ -188,6 +189,13 @@ SR_PRIV struct dmm_info dmms[] = {
&tecpel_dmm_8061_ser_driver_info,
receive_data_TECPEL_DMM_8061_SER,
},
{
"Voltcraft", "M-3650CR", "1200/7n2/rts=0/dtr=1", 1200,
METEX14_PACKET_SIZE, sr_metex14_packet_request,
sr_metex14_packet_valid, sr_metex14_parse,
NULL,
&voltcraft_m3650cr_driver_info, receive_data_VOLTCRAFT_M3650CR,
},
{
"Voltcraft", "M-3650D", "1200/7n2/rts=0/dtr=1", 1200,
METEX14_PACKET_SIZE, sr_metex14_packet_request,
@ -605,6 +613,7 @@ DRV(radioshack_22_168, RADIOSHACK_22_168, "radioshack-22-168", "RadioShack 22-16
DRV(radioshack_22_805, RADIOSHACK_22_805, "radioshack-22-805", "RadioShack 22-805")
DRV(radioshack_22_812, RADIOSHACK_22_812, "radioshack-22-812", "RadioShack 22-812")
DRV(tecpel_dmm_8061_ser, TECPEL_DMM_8061_SER, "tecpel-dmm-8061-ser", "Tecpel DMM-8061 (UT-D02 cable)")
DRV(voltcraft_m3650cr, VOLTCRAFT_M3650CR, "voltcraft-m3650cr", "Voltcraft M-3650CR")
DRV(voltcraft_m3650d, VOLTCRAFT_M3650D, "voltcraft-m3650d", "Voltcraft M-3650D")
DRV(voltcraft_m4650cr, VOLTCRAFT_M4650CR, "voltcraft-m4650cr", "Voltcraft M-4650CR")
DRV(voltcraft_me42, VOLTCRAFT_ME42, "voltcraft-me42", "Voltcraft ME-42")

View File

@ -176,6 +176,7 @@ RECEIVE_DATA(RADIOSHACK_22_168, metex14)
RECEIVE_DATA(RADIOSHACK_22_805, metex14)
RECEIVE_DATA(RADIOSHACK_22_812, rs9lcd)
RECEIVE_DATA(TECPEL_DMM_8061_SER, fs9721)
RECEIVE_DATA(VOLTCRAFT_M3650CR, metex14)
RECEIVE_DATA(VOLTCRAFT_M3650D, metex14)
RECEIVE_DATA(VOLTCRAFT_M4650CR, metex14)
RECEIVE_DATA(VOLTCRAFT_ME42, metex14)

View File

@ -39,6 +39,7 @@ enum {
RADIOSHACK_22_805,
RADIOSHACK_22_812,
TECPEL_DMM_8061_SER,
VOLTCRAFT_M3650CR,
VOLTCRAFT_M3650D,
VOLTCRAFT_M4650CR,
VOLTCRAFT_ME42,
@ -124,6 +125,7 @@ SR_PRIV int receive_data_RADIOSHACK_22_168(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_RADIOSHACK_22_805(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_RADIOSHACK_22_812(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_TECPEL_DMM_8061_SER(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_M3650CR(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_M3650D(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_M4650CR(int fd, int revents, void *cb_data);
SR_PRIV int receive_data_VOLTCRAFT_ME42(int fd, int revents, void *cb_data);

View File

@ -246,6 +246,7 @@ extern SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info;
extern SR_PRIV struct sr_dev_driver radioshack_22_805_driver_info;
extern SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info;
extern SR_PRIV struct sr_dev_driver tecpel_dmm_8061_ser_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_m3650cr_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_m3650d_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_m4650cr_driver_info;
extern SR_PRIV struct sr_dev_driver voltcraft_me42_driver_info;
@ -311,7 +312,7 @@ static struct sr_dev_driver *drivers_list[] = {
#endif
#ifdef HAVE_HW_GMC_MH_1X_2X
&gmc_mh_1x_2x_rs232_driver_info,
&gmc_mh_2x_bd232_driver_info,
&gmc_mh_2x_bd232_driver_info,
#endif
#ifdef HAVE_HW_HAMEG_HMO
&hameg_hmo_driver_info,
@ -403,6 +404,7 @@ static struct sr_dev_driver *drivers_list[] = {
&radioshack_22_805_driver_info,
&radioshack_22_812_driver_info,
&tecpel_dmm_8061_ser_driver_info,
&voltcraft_m3650cr_driver_info,
&voltcraft_m3650d_driver_info,
&voltcraft_m4650cr_driver_info,
&voltcraft_me42_driver_info,

View File

@ -591,7 +591,7 @@ struct metex14_info {
gboolean is_diode, is_frequency, is_ampere, is_volt, is_farad;
gboolean is_hertz, is_ohm, is_celsius, is_pico, is_nano, is_micro;
gboolean is_milli, is_kilo, is_mega, is_gain, is_decibel, is_hfe;
gboolean is_unitless;
gboolean is_unitless, is_logic;
};
#ifdef HAVE_LIBSERIALPORT