st-ten-1/src/test/multicomp.py

30 lines
757 B
Python
Raw Normal View History

2022-07-19 14:09:26 +00:00
import time
import serial
conn = serial.Serial(
"/dev/ttyUSB0",
baudrate=115200,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
2022-07-20 17:29:11 +00:00
cmd_list = (("*IDN?\n", True), # QUERY ID
("CONF:RES 500\n", False), # SET RESISTANCE MEASURE, 500 Ohm range
("MEAS?\n", True), # GET MEASURE
("MEAS?\n", True), # GET MEASURE
2022-07-19 14:09:26 +00:00
("MEAS?\n", True)) # GET MEASURE
for cmditem in cmd_list:
2022-07-20 17:29:11 +00:00
cmd, expect_response = cmditem
2022-07-19 14:09:26 +00:00
conn.write(bytes(cmd, encoding="ascii"))
if expect_response:
response = conn.readline()
2022-07-20 17:29:11 +00:00
print(f"{cmd} RESPONSE: " + response.decode("ascii"))
2022-07-19 14:09:26 +00:00
else:
print(f"{cmd}")
time.sleep(1)
conn.close()