-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqmlu-reader.py
More file actions
50 lines (39 loc) · 1.25 KB
/
sqmlu-reader.py
File metadata and controls
50 lines (39 loc) · 1.25 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
import time
import serial
# configure the serial connections (the parameters differs on the device you are connecting to)
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
def send_cmd(ser, cmd):
encoded = (cmd + '\n').encode()
ser.write(encoded)
time.sleep(1)
out = ''
while ser.inWaiting() > 0:
out += ser.read(1).decode('utf-8')
return out.strip()
def sqm_read_parse(txt: str) -> tuple:
""" example input: 00.00m,0000557221Hz,0000000000c,0000000.000s, 037.0C
example output: (00.0, 37.0) """
entities = txt.strip().split(",")
mag = float(entities[0][:-1]) # get rid of the m suffix
# Ignore frequency
temp = float(entities[4].strip()[:-1]) # get rid of the C suffix
return (mag, temp)
ser.isOpen()
# Read device info request
#ix_response = send_cmd(ser, "ix")
#print(f"ix response: [{ix_response}]")
# Get the measurements
rx_response = send_cmd(ser, "rx")
ser.close()
sqm, temp = sqm_read_parse(rx_response)
print(f"# {rx_response}")
print(f"sqm temperature={temp},magnitude={sqm}")
# Get the calibration info
#cx_response = send_cmd(ser, "cx")
#print(f"cx response: [{cx_response}]")