Git Product home page Git Product logo

Comments (11)

jpnurmi avatar jpnurmi commented on August 19, 2024 1

Yes, it indicates an error but the last error is not set so it slips through. There was a reason to add that check so I'm sceptic to blindly change it. However, clamping the -2 length to 0 length would give and empty list, to make it a no-op.

from flutter_libserialport.

AriaShishegaran avatar AriaShishegaran commented on August 19, 2024 1

Yes, it indicates an error but the last error is not set so it slips through. There was a reason to add that check so I'm sceptic to blindly change it. However, clamping the -2 length to 0 length would give and empty list, to make it a no-op.

So do you consider this a bug that needs resolving? I'm asking this because initially, we viewed this as our own bad implementation, can we provide any extra data that helps you move forward with this bug or offer a workaround?

from flutter_libserialport.

jpnurmi avatar jpnurmi commented on August 19, 2024

Do you have any code snippet to show? Where does the error come from? Does it show any stacktrace?

from flutter_libserialport.

xclud avatar xclud commented on August 19, 2024

I cloned this repo and modified example/main.dart like this:

void initPorts() {
  setState(() => availablePorts = SerialPort.availablePorts);

  final serial = SerialPort('COM1');

  if (serial.openReadWrite()) {
    final reader = SerialPortReader(serial);
    reader.stream.listen((event) {
      print(event);
    });

    serial.write(Uint8List.fromList([1, 2, 3, 4]));
  }
}

Stacktrace is null. But i have attached a screenshot:

Screenshot

from flutter_libserialport.

AriaShishegaran avatar AriaShishegaran commented on August 19, 2024

@jpnurmi
Any comment/progress on this? we are facing the same issue here. would appreciate it if you help us navigate through the issue.

from flutter_libserialport.

jpnurmi avatar jpnurmi commented on August 19, 2024

I'm not sure why the library returns an error without providing the last error. Nevertheless, a sanity check like this could help. Are you able to test it for me? I don't have a suitable environment...

diff --git a/lib/src/util.dart b/lib/src/util.dart
index 2ca44c5..b0e2ddf 100644
--- a/lib/src/util.dart
+++ b/lib/src/util.dart
@@ -44,7 +44,7 @@ class Util {
   static Uint8List read(int bytes, UtilFunc<ffi.Uint8> readFunc) {
     final ptr = ffi.calloc<ffi.Uint8>(bytes);
     final len = call(() => readFunc(ptr));
-    final res = Uint8List.fromList(ptr.asTypedList(len));
+    final res = Uint8List.fromList(ptr.asTypedList(len.clamp(0, len)));
     ffi.calloc.free(ptr);
     return res;
   }

from flutter_libserialport.

xclud avatar xclud commented on August 19, 2024

The problem is with len being -2. I tried debugging but it seems -2 comes from serialport.dll.

final len = call(() => readFunc(ptr));

from flutter_libserialport.

ricardoboss avatar ricardoboss commented on August 19, 2024

@jpnurmi @AriaShishegaran any progress on this one? I started getting this error after switching to SerialPortReader. Before, I was calling port.read(...) myself and had no such issue. The advantage of the reader is that it provides a convenient stream.

from flutter_libserialport.

lucafabbri avatar lucafabbri commented on August 19, 2024

@ricardoboss we are about to release on pub dev the 0.4.0.
Could check the issue against this release as available?

from flutter_libserialport.

ricardoboss avatar ricardoboss commented on August 19, 2024

Sure, I can't say when I have time to test this though

from flutter_libserialport.

lucafabbri avatar lucafabbri commented on August 19, 2024

Sure, I can't say when I have time to test this though

No problem ;)

from flutter_libserialport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.