diff --git a/README.md b/README.md index f2da688..17a900a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,17 @@ # victor-vc70c-hidraw-reader -A decoding program for VICTOR VC70C/86C/86D Multimeter as computer device. -More infomation is included in `vc_hidraw.h`. +A decoding program for VICTOR VC70C/86C/86D Multimeter as a computer device. +More information is included in `vc_hidraw.h`. -# Testing +## Testing Use these commands to make sure this program works on your computer with your multimeter connected. ``` git clone https://github.com/wuwbobo2021/victor-vc70c-hidraw-reader/ victor-vc70c-hidraw-reader/ cd victor-vc70c-hidraw-reader sudo make ``` + +## Known Problems +1. Currently this library is only for Linux platform; +2. Root authority is required to access the VC70C hidraw device; +3. `read_vc_multimeter_hidraw(vc_multimeter_reading*)` will block the current thread until next data is received. This may cause inconvenience of using this library. +4. (minor) When the multimeter is not measuring anything, AC/DC indication in the reading string may be incorrect. diff --git a/test.cpp b/test.cpp index 453769d..1651cb4 100644 --- a/test.cpp +++ b/test.cpp @@ -1,4 +1,5 @@ #include +#include "unistd.h" #include "vc_hidraw.h" using namespace std; @@ -16,7 +17,7 @@ int main(){ cout << reading.str << '\n'; else { cout << "?\n"; - sleep(0.1); + sleep(0.5); } } diff --git a/vc_hidraw.c b/vc_hidraw.c index 4786de6..0e52b38 100644 --- a/vc_hidraw.c +++ b/vc_hidraw.c @@ -37,6 +37,9 @@ typedef unsigned char BYTE; +// 0 <= digit <= 7 +#define Byte_Bit(b, digit) ((b >> digit) & 0x01) + const int VC_HID_Vendor_Number = 0x1244; const int VC_HID_Product_Number = 0xD237; @@ -93,12 +96,6 @@ const BYTE VC_HID_Digit_Decoding[4][16] const BYTE VC_HID_Decimal_Decoding[16] // e+0, 1, 2, 3 = {0, N, N, N, N, N, N, N, 3, N, 2, N, 1, N, N, N}; // buf[0x5], low: 0x4 - -bool byte_bit(BYTE b, BYTE digit){ - if (digit < 0 || digit > 7) return false; - return ((b >> digit) & 0x01); -} - int vc_fd; bool vc_found; bool open_vc_multimeter_hidraw(){ @@ -138,8 +135,8 @@ bool read_vc_multimeter_hidraw(vc_multimeter_reading* reading){ res = read(vc_fd, buf, HIDRAW_BUFFER_SIZE); if (res < VC_HID_Valid_Buffer_Size) return false; - reading->minus = byte_bit(buf[VC_HID_Polarity_Byte], VC_HID_Minus_Bit); - reading->AC = ! byte_bit(buf[VC_HID_DCAC_Byte], VC_HID_DC_Bit); + reading->minus = Byte_Bit(buf[VC_HID_Polarity_Byte], VC_HID_Minus_Bit); + reading->AC = ! Byte_Bit(buf[VC_HID_DCAC_Byte], VC_HID_DC_Bit); reading->str[0] = (reading->minus? '-' : ' '); @@ -199,8 +196,8 @@ bool read_vc_multimeter_hidraw(vc_multimeter_reading* reading){ } BYTE t = buf[VC_HID_Signs_Byte]; - reading->low_battery_voltage = ! byte_bit(t, VC_HID_Low_Battery_Voltage_Bit); - if (! byte_bit(t, VC_HID_Unit_n_Bit)){ + reading->low_battery_voltage = ! Byte_Bit(t, VC_HID_Low_Battery_Voltage_Bit); + if (! Byte_Bit(t, VC_HID_Unit_n_Bit)){ reading->value /= 1000*1000*1000; strcat(reading->str, "n"); } diff --git a/vc_hidraw.h b/vc_hidraw.h index 48d92e1..2707e51 100644 --- a/vc_hidraw.h +++ b/vc_hidraw.h @@ -53,12 +53,12 @@ typedef enum vc_multimeter_unit{ typedef struct vc_multimeter_reading{ float value; - bool minus; - vc_multimeter_unit unit; - bool AC; - bool percent_unit; - bool ol; //open-loop - bool low_battery_voltage; //battery of multimeter itself + vc_multimeter_unit unit : 3; + bool minus : 1; + bool AC : 1; + bool percent_unit : 1; + bool ol : 1; //open-loop + bool low_battery_voltage : 1; //battery of multimeter itself char str[21]; // 1 (' ' or '-') + 5 (decimal number) + 1 (' ') + 3 (numeric unit) + // 3 (unit) + 3 (DC/AC) + 4 (low capacity indication) + 1 ('\0')