jpnurmi / flutter_libserialport

Serial Port for Flutter
https://pub.dev/packages/flutter_libserialport
MIT License
139 stars 80 forks source link

USB port not listening on connect - Windows #62

Closed manishbuttan closed 2 months ago

manishbuttan commented 1 year ago

Hi, when I open the port in flutter to my USB serial port, it opens fine. But the port won't listen for incoming messages. If I close the port in the app and open it from Tera Term and close it, then open it again in the app, the communcation works fine and the incoming messages are working.

What is the proper way of opening the port and starting communication with the serial port without opening it externally?

Platform : Windows. Flutter.

if (!port.openReadWrite()) { print("Port not opened: ${SerialPort.lastError}"); }

try { serialPortReader = SerialPortReader(port); serialPortReader.stream.listen((data) { String message = String.fromCharCodes(data); _processUSBData(message); }); } catch (e) { print(SerialPort.lastError); }

Ibrahim653 commented 1 year ago

same issue here plz if u solve it reply

masterix21 commented 1 year ago

Try applying the port config when your port is already opened. Like so:

var port = SerialPort(gateway.port);
port.openReadWrite();

port.config = SerialPortConfig()
      ..baudRate = 9600
      ..bits = 8
      ..stopBits = 1
      ..parity = SerialPortParity.none
      ..setFlowControl(SerialPortFlowControl.none);
moodstubos commented 1 year ago

same here. I have to open serial port with putty first. After that I am able to receive data with this package. Without no data are received. Testet on windows 11

Update: After some testing I have found an solution that works for me. I have to set some flow controls. It was a lot of try and error and I have not tested which one did the trick, but with this config it works:

      _serialPort.config = SerialPortConfig()
        ..rts = SerialPortRts.flowControl
        ..cts = SerialPortCts.flowControl
        ..dsr = SerialPortDsr.flowControl
        ..dtr = SerialPortDtr.flowControl
        ..setFlowControl(SerialPortFlowControl.rtsCts);
manishbuttan commented 1 year ago

Thank you moodstubos. These settings worked for me as well. Import information to add to the documentation.

sattha commented 1 year ago

set the config after openReadWrite or other "open" port methods work for me.

NeariX67 commented 11 months ago

Sattha is right here. The SerialPortConfig class documentation states the following: @note A port must be opened before you can change its settings.

Solved my issue as well :)

Ibrahim653 commented 7 months ago

hahahahahahahaha

lucafabbri commented 2 months ago

Refers to #29