#include "dmm.h"
#include <string.h> // memcpy(), strchr()
#include <math.h> // pow()
EXTERN_C void _cdecl _fltused(){}; // don't create .bss data segment here!
struct Metex:INDATA{
void _stdcall Handler();
};
void Metex::Handler() {
switch (msg) {
case init:{
rmax=32;
counts=lParam?19999:99999; // TODO: guessed
baud=lParam?1200:2400;
}break;
case data:{
if (rlen<14) {ok=true; return;} // Expect more data
for (int i=0; i<14; i++) rbuf[i]&=~0x80; // strip MSB (stop bit), TODO: Remove this quirks!
if (rbuf[13]!='\r') return; // Ignore more characters, but newline must be at right position
READOUT ro;
ZeroMemory(&ro,sizeof(ro));
memcpy(ro.digits,rbuf+2,7);
ro.value=strtod(ro.digits,NULL);
// TODO: No information for accuracy available, data sheet of ME-22T is needed
for (BYTE*a=rbuf+9; a<rbuf+13; a++) if (*a!=' ') { // found a unit
static const char prefixes[]="pnum KMG"; // possible SI unit prefixes
const char*p=strchr(prefixes,*a);
if (p) { // unit prefix detected
ro.unitprefix=(char)(p-prefixes-4)*3; // calculate exponent
ro.value*=pow(10.0,ro.unitprefix); // adjust value (beware C++ overloading of pow()!)
a++; // to base unit
}
static const char unitletters[]=" VOFHAC"; // first letter of base unit
p=strchr(unitletters,*a);
if (p) ro.unitcode=(char)(p-unitletters); // known unit
else memcpy(ro.unit,a,rbuf+13-a); // unknown unit
break;
}
DWORD features=0;
switch (*(WORD*)rbuf) {
case 'CA': features|=1<<F_AC; break; // "AC" (TODO: Including DC or not?)
case 'CD': features|=1<<F_DC; break; // "DC"
case 'FH': features|=1<<F_hFE; break; // "HF" (for hFE)
case 'ID': features|=1<<F_Diode; break; // "DI" (diode and continuity test)
} // moreover FRequency, TEmperature, OHm, LOgic
SetData(features,&ro,1);
rlen=0;
ok=true;
}nobreak;
case tout:
case open:{
SendBytes("\xC4",1); // "D" with stop bit
}break;
}
}
EXTERN_C bool /*_declspec(dllexport)*/ WINAPI EnumAll(int n, ENUMINFO* ei) {
if (n>=2) return false;
strcpy(ei->ManufName,"Metex");
strcpy(ei->ModelName,n?"M4650CR":"ME-22T");
ei->IconIndex=0;
ei->ExtraAlloc=0;
ei->pHandler=(void(_stdcall INDATA::*)())&Metex::Handler;
ei->lParam=n;
return true;
}
Detected encoding: UTF-8 | 0
|