jpnurmi / flutter_libserialport

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

Length must be in range #53

Closed Zopenzop closed 1 year ago

Zopenzop commented 2 years ago

My code is as follows, pretty basic

        availablePorts = libserial.SerialPort.availablePorts;
        libserial.SerialPort port = libserial.SerialPort(availablePorts.first);
        port.openWrite();

        var config = port.config;
        config.baudRate = 9600;
        port.config = config;

        port.config.bits = 8;
        port.config.stopBits = 1;
        port.config.parity = 0;

        port.config = config;
        final reader = libserial.SerialPortReader(port);
        reader.stream.listen((Uint8List data) {
          log(utf8.decode(data));
        });

I get an error on receiving data -

Invalid argument(s): length must be in the range [0, 4611686018427387903].
#0      _checkExternalTypedDataLength (dart:ffi-patch/ffi_patch.dart:60:5)
#1      Uint8Pointer.asTypedList (dart:ffi-patch/ffi_patch.dart:620:5)
#2      Util.read
package:libserialport/src/util.dart:47
#3      _SerialPortReaderImpl._waitRead
package:libserialport/src/reader.dart:145
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:300:17)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

p.s. I have confirmed that my cables or cable configurations aren't faulty by using a native application I made and also through TeraTerm.

Edit - I am getting some data now, but its either single bytes or a byte array with all zeroes whereas the data I should be receiving is a valid byte array. I am able to get it using other terminals.

indrawow commented 2 years ago

Same here

omidFdisk commented 1 year ago

i have same issue

aboutZZ commented 1 year ago

Same here

aboutZZ commented 1 year ago

Fixed. The serial port device driver is not compatible with Windows 10, please update the driver. Go to Settings -> privacy -> other devices, check your device is on the trusted device list. image.png OR use Windows 7😄

Zopenzop commented 1 year ago

Apparently, the reason why I was not able to get data correctly / was getting zero byte arrays was because I was setting the port config after opening the serial port. What solved the issue was setting the port config before opening the serial port.

Ankur261 commented 1 year ago

Apparently, the reason why I was not able to get data correctly / was getting zero byte arrays was because I was setting the port config after opening the serial port. What solved the issue was setting the port config before opening the serial port.

Can you please show the code or can tell me where to put the configurations.

Ankur261 commented 1 year ago

aboutZZ USB option is not showing on my system. Is there anything I need to change ?