I want to write to serial port to embedded micro-controller,
I am using serial to USB converter.
My code is as below (Sample code):
import serial
import time
ec = serial.Serial('COM2', baudrate=57600)
print(ec.isOpen())
cmd=str(input('cmd >> '))
ncmd = cmd+'\r\n'
ec.write(ncmd.encode())
time.sleep(2)
data = ec.read_all()
time.sleep(1)
print(data)
ec.close()
if ec.close():
print('port closed')**
But every time I run code with some command I do not get expected output. e.g. If I send command '4', it is expected that it should read all error data from controller. But instead it gives following empty message;
True
cmd >> 4
b''
Could anyone please help? Where am I doing something wrong?
\r- Nullman