Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwbobo2021 authored Nov 29, 2021
1 parent d89b52b commit c675d1b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include "unistd.h"
#include "vc_hidraw.h"

using namespace std;
Expand All @@ -16,7 +17,7 @@ int main(){
cout << reading.str << '\n';
else {
cout << "?\n";
sleep(0.1);
sleep(0.5);
}
}

Expand Down
17 changes: 7 additions & 10 deletions vc_hidraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(){
Expand Down Expand Up @@ -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? '-' : ' ');

Expand Down Expand Up @@ -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");
}
Expand Down
12 changes: 6 additions & 6 deletions vc_hidraw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit c675d1b

Please sign in to comment.