libserialport.dart
libserialport.dart copied to clipboard
Not able to read port data. port.read() is always throwing false.
Hi, When I'm trying to connect the serial port with the below code, I am getting port.read() always as false. I am not able to read the data as the port is not getting opened. I can confirm that the device which is sending the data is has no problem. Can you please help us resolving this issue.
Future
_port = SerialPort(selectedDevice.portName);
_port.openRead();
var config = _port.config;
config.baudRate = 9600;
_port.config = config;
_port.config.bits = 8;
_port.config.stopBits = 1;
_port.config.parity = 0;
_port.config.xonXoff = 0;
_port.config.rts = 0;
_port.config.cts = 0;
_port.config.dsr = 0;
_port.config.dtr = 0;
_port.config = config;
// config.dispose();
if (_port.openRead()) {
print('Port opened: ${selectedDevice.portName}');
// Start reading data from the port
_reader = SerialPortReader(_port!);
_reader!.stream.listen((Uint8List data) {
buffer += String.fromCharCodes(data);
print('Received data: $buffer');
});
} else {
print('Failed to open the port.');
}
} else { print('No ports available.'); } }