I receive the error in the following line:
command = input("please type command.example open 1")
#call the serial_connection() function
ser.write(b"%d\r\n"%command)
Essentially I want the input written by the user and parse it into ser.write, without asking for the input and directly putting the string into ser.write
such as:
ser.write(b'close1\r\n')
worked fine, the problem only occurred when i try to use the result of the input as a string to include in ser.write
A bit more of the code:
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)
for any clarification, kindly advise.