-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioniclient.py
More file actions
89 lines (66 loc) · 2.24 KB
/
Copy pathioniclient.py
File metadata and controls
89 lines (66 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#################################################
# #
# Ionicon WebAPI - Python client #
# #
# this module requires the 'requests' package #
# #
# >> pip install --user requests #
# #
#################################################
import os
import time
import requests
class IoniClient:
'''
Access the Ionicon WebAPI.
Usage:
>>> client = IoniClient()
>>> client.get('TPS_Pull_H')
{'TPS_Pull_H': 123.45, ... }
>>> client.set('TPS_Pull_H', 42)
{'TPS_Pull_H': 42.0, ... }
>>> client.start_measurement()
ACK
>>> client.host, client.port
('localhost', 8002)
'''
def __init__(self, host='localhost', port=8002):
self.host = host
self.port = port
@property
def baseurl(self):
return f'http://{self.host}:{self.port}/Ic_WebAPI'
def get(self, varname):
uri = self.baseurl + '/WebAPI_Get'
payload = {varname: '?'}
r = requests.get(uri, params=payload)
return r.text
def get_traces(self):
uri = self.baseurl + '/TRACES_WebAPI_Get' + '?'
r = requests.get(uri)
return r.text
def set(self, varname, value):
uri = self.baseurl + '/WebAPI_Set'
payload = {varname: value}
r = requests.post(uri, data=payload)
return r.text
def set_filename(self, filename):
return self.set('ACQ_SRV_SetFullStorageFile', os.path.normpath(filename))
def start_measurement(self, filename=''):
if filename:
return self.set('ACQ_SRV_Start_Meas_Auto', os.path.normpath(filename))
return self.set('ACQ_SRV_Start_Meas_Quick', 1)
def stop_measurement(self):
return self.set('ACQ_SRV_Stop_Meas', 1)
if __name__ == '__main__':
import sys
client = IoniClient()
if len(sys.argv) == 2:
print(client.get(sys.argv[1]))
elif len(sys.argv) == 3:
print(client.set(sys.argv[1], sys.argv[2]))
else:
print(f"""\
usage:
python {sys.argv[0]} <varname> [<value>]
""")