Skip to content

Commit 560a9b7

Browse files
committed
WIP: Add a script to output an mmdata.txt for FlexBV
1 parent 7050317 commit 560a9b7

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

smuscript/flexbv_mmdata.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# This file is part of the SmuView project.
2+
#
3+
# Copyright (C) 2022 François Revol <revol@free.fr>
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
import smuview
24+
import time
25+
import os
26+
import signal
27+
import threading
28+
29+
#
30+
# This generates the mmdata.txt file as required by FlexBV to gather measurements
31+
# for the OpenBoardData project.
32+
#
33+
# https://pldaniels.com/flexbv/
34+
# https://openboarddata.org/
35+
#
36+
37+
# Replace with the name and configuration of your multimeter
38+
# eg. "hp-3478a:conn=libgpib/hp3478a"
39+
device_name = "demo"
40+
41+
# Replace with the name of the channel to relay to FlexBV, or "" for the first one
42+
# eg. "A1"
43+
channel_name = ""
44+
45+
# Path to the mmdata.txt to generate or None for auto-detection
46+
mmdata_path = "mmdata.txt"
47+
48+
49+
## end of config variables
50+
51+
print("Generate mmdata.txt for FlexBV")
52+
print("")
53+
54+
#if mmdata_path is None:
55+
# TODO: autodetect
56+
57+
# Connect the demo device (it's just one!)
58+
dmm_dev = Session.connect_device(device_name)[0]
59+
channels = dmm_dev.channels()
60+
print(str(channels))
61+
if channel_name == "":
62+
channel_name = list(channels.keys())[0]
63+
print(channel_name)
64+
# set on channel or on "" ??
65+
dmm_conf = dmm_dev.configurables()[channel_name]
66+
dmm_conf.set_config(smuview.ConfigKey.MeasuredQuantity, (smuview.Quantity.Voltage, {smuview.QuantityFlag.Diode}))
67+
print(type(smuview.Quantity.Voltage))
68+
print(str(smuview.Quantity.Voltage))
69+
#print(dmm_conf.get_string_config(smuview.ConfigKey.MeasuredQuantity))
70+
71+
# Add a user device
72+
user_dev = Session.add_user_device()
73+
user_dev_tab = UiProxy.add_device_tab(user_dev)
74+
print("New user tab = " + user_dev_tab)
75+
76+
# Add a generic control view to the device tab
77+
control_view_1 = UiProxy.add_control_view(user_dev_tab, smuview.DockArea.TopDockArea, dmm_dev.configurables()[""])
78+
print("New control view (1) = " + control_view_1)
79+
80+
# Add a demo control view to the device tab
81+
control_view_2 = UiProxy.add_control_view(user_dev_tab, smuview.DockArea.TopDockArea, dmm_dev.configurables()[channel_name])
82+
print("New control view (2) = " + control_view_2)
83+
84+
# Add a value panel view to the device tab
85+
value_panel_view_1 = UiProxy.add_value_panel_view(user_dev_tab, smuview.DockArea.TopDockArea, dmm_dev.channels()[channel_name])
86+
print("New valuepanel view (1) = " + value_panel_view_1)
87+
88+
time.sleep(1)
89+
90+
91+
print("")
92+
93+
tmp_path = mmdata_path.replace(".txt","") + ".tmp"
94+
95+
digits = 3
96+
if smuview.ConfigKey.Digits in dmm_conf.getable_configs():
97+
digits = dmm_conf.get_int_config(smuview.ConfigKey.Digits)
98+
99+
running = threading.Event()
100+
101+
def handler(signum, frame):
102+
running.set()
103+
104+
signal.signal(signal.SIGINT, handler)
105+
106+
while not running.is_set():
107+
time.sleep(0.5)
108+
if os.path.exists(mmdata_path):
109+
continue
110+
# FlexBV digested the previous file
111+
s = dmm_dev.channels()[channel_name].actual_signal()
112+
# get the unit back from the signal name
113+
unit = s.name().split("[")[1].split(" ")[0]
114+
u_in = s.get_last_sample(True)[1]
115+
with open(tmp_path, 'w', encoding="utf-8") as f:
116+
f.write(("{:."+str(digits)+"f}").format(u_in) + unit)
117+
os.rename(tmp_path, mmdata_path)
118+
119+
Session.remove_device(user_dev)
120+
Session.remove_device(dmm_dev)
121+
print("Exited")

0 commit comments

Comments
 (0)