我收到以下行中的错误:command = input("please type command.example open 1")
#call the serial_connection() function
ser.write(b"%d\r\n"%command)
实际上,我希望用户编写输入并将其解析为ser.写入,而不要求输入并直接将字符串放入ser.write中,例如:
^{pr2}$
工作正常,只有当我试图将输入结果用作要包含的字符串时才会出现问题ser.写入在
更多的代码:ser = 0
#Initialize Serial Port
def serial_connection():
COMPORT = int(input("Please enter the port number: "))
ser = serial.Serial()
ser.baudrate = 38400 #Suggested rate in Southco documentation, both locks and program must be at same rate
ser.port = COMPORT - 1 #counter for port name starts at 0
#check to see if port is open or closed
if not ser.isOpen():
print ('The Port %d is open - Will attempt to close lock 1 Stephan: '%COMPORT + ser.portstr)
#timeout in seconds
ser.timeout = 10
ser.open()
command = input("please type command.example open 1")
#call the serial_connection() function
ser.write(b"%d\r\n"%command)
else:
print ('The Port %d is **open** Stephan' %COMPORT)
如有任何澄清,请告知。在