import time import serial # tester_port="/dev/ttyUSB0" tester_port = "COM1" conn = serial.Serial( tester_port, 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 [cmd, expect_response] in cmd_list: 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()