The code on this repository builds upon the existing Python driver-functionality of witrn-ui by didim99, by adding real-time plotting (and logging) functionality using Bokeh. The result allows the user to control a WITRN USB-meter to be controlled using a web-browser.
Currently the code has only been tested using a Witrn C4.
pip install -r requirements.txt
NOTE: The requirements.txt
file is generated by running pipreqs
(pip install pipreqs
) in the project directory. ~=
means compatible version.
Copy the udev-rules-file to the correct location.
sudo cp udev/90-usbmeter.rules /etc/udev/rules.d/90-usbmeter.rules
Restart the udev management tool.
sudo udevadm control --reload-rules
sudo udevadm trigger
Use Zadig to replace Windows's default HID-driver to libusbK
.
- Run
zadig-2.8.exe
- Click on
Options
>List All Devices
- Select the
WITRN.C4
device (in case the Witrn C4 is used) - Select
libusbK (v3.0.7.0)
above theReplace Driver
button - Click on
Replace Driver
- Confirm the driver replacement operation, wait for the tool to finish
Running witrn-ui-bokeh.py
as-is with Python won't do anything. It is supposed to be launched using Bokeh server (bokeh serve
), which creates (and opens, on http://localhost:5006/witrn-ui-bokeh) an interactive web application that connects front-end UI events to running Python code. The correct usage is shown below.
bokeh serve --show witrn-ui-bokeh.py
Once the web-interface opens, use the following steps.
- Select a Device using the dropdown (
C4
selected by default).- Depending on the way the current will flow/flows through the USB-meter, disable (default enabled) the Invert Current Sign logic using the corresponding toggle-switch.
- Click on Open Connection
- Change the Plot Period [ms] to a value greater than
0
if the measurement-throughput is too/unnecessary high (the tool defaults to (try to) plot all incoming measurements, a non-zero value only plots incoming measurements at the defined period) - Click on Clear Plot to clear all of the already plotted measurements (the tool only keeps
6000
(configurable, usingMAX_X_POINTS
in witrn-ui-bokeh.py) data-points on the X-axis (per data-line) before discarding old data, in an attempt to maintain a somewhat responsive real-time application) - Click on an item in the Legend to enable or disable the display of certain lines on the plot
- Change the Plot Period [ms] to a value greater than
- Use the tooltips on the side (activated when hovering over the plot) to zoom in or out on the measurements, ...
- Change the plot- and file- Title and Log Period [ms] using the corresponding fields (if necessary), click on Start Logging to start saving values to a
.csv
-file.- The generated file has the following syntax (
DateTime
corresponds to the time at which the button has been pressed):YYYY-MM-DD_HH-MM-SS_<Title>.csv
- The generated file has the following syntax (
Usage sample: