I'm trying to communicate with a board via serial (rs232) port using PySerial.
The board is a Renesas rl78 and below is my sample code. (Basically what I'm trying here is to execute some pre-defined commands. So here commands is again a command that returns a list of other commands)
import serial, time, ioser = serial.Serial()ser.port = "/dev/cu.usbserial"ser.baudrate = 19200 # as used for HyperTerminalser.timeout = 10 #non-block of 10 secondsser.bytesize = serial.EIGHTBITSser.parity=serial.PARITY_NONEser.stopbits=serial.STOPBITS_ONEser.xonoff = Falseser.rtscts = Trueser.dsrdtr = Trueser.dtr = Trueser.rts = Truetry: ser.open()except Exception, e: print "error open serial port: "+ str(e) exit()if ser.is_open: try: #ser.reset_input_buffer() #flush input buffer, discarding all its contents #ser.reset_output_buffer() #flush output buffer, aborting current output #write data ser.write(b'commands\r') ser.reset_input_buffer() time.sleep(2) in_wait = ser.in_waiting while True: if in_wait != 0: output = ser.read(in_wait) print(output) break else: break ser.close() except Exception, e1: print "error communicating...: "+ str(e1)else: print "cannot open serial port "And from the device's standpoint, we have to hit return (carriage return \r) in order to execute a command using any terminal application. i.e HyperTerminal or Serial for Mac.
So the above code does not return any output but just an empty string (this is what you get in the terminal when you just hit return (\r)). The device is behaving like it got a return (\r) and the command is completely ignored.
To make sure that it is not an issue with PySerial I tried to use PySerial's miniterm to get this terminal behavior, and I was able to successfully execute the commands
Again the catch here is to set CR as the EOL to get the commands to execute successfully.
python -m serial.tools.miniterm -e --eol=CRSo I'm puzzled here on what is wrong with my code and why it is not executing the commands.