kod
brakunknown
python
2 years ago
832 B
3
Indexable
import serial import time try: ser = serial.Serial( # set parameters, in fact use your own :-) port="COM8", baudrate=19200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE ) ser.isOpen() # try to open port, if possible print message and proceed with 'while True:' print ("port is opened!") except IOError: # if port is already opened, close it and open it again and print message ser.close() ser.open() print ("port was already open, was closed and opened again!") command = '' time.sleep(1.8) command = str('r') command += str('\n') ser.write(command.encode(encoding = 'ASCII', errors = 'strict')) ser.write(command.encode(encoding = 'utf8', errors = 'strict')) ser.write(b'R\n') time.sleep(2) data = ser.readline() print(data)
Editor is loading...