30 lines
745 B
Python
30 lines
745 B
Python
|
|
import time
|
||
|
|
|
||
|
|
import serial
|
||
|
|
|
||
|
|
conn = serial.Serial(
|
||
|
|
"/dev/ttyUSB0",
|
||
|
|
baudrate=115200,
|
||
|
|
stopbits=serial.STOPBITS_ONE,
|
||
|
|
parity=serial.PARITY_NONE,
|
||
|
|
bytesize=serial.EIGHTBITS,
|
||
|
|
timeout=1
|
||
|
|
)
|
||
|
|
|
||
|
|
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
|
||
|
|
("MEAS?\n", True)) # GET MEASURE
|
||
|
|
|
||
|
|
for cmditem in cmd_list:
|
||
|
|
cmd,expect_response=cmditem
|
||
|
|
conn.write(bytes(cmd, encoding="ascii"))
|
||
|
|
if expect_response:
|
||
|
|
response = conn.readline()
|
||
|
|
print(f"{cmd} RESPONSE: "+response.decode("ascii"))
|
||
|
|
else:
|
||
|
|
print(f"{cmd}")
|
||
|
|
time.sleep(1)
|
||
|
|
conn.close()
|