jpnurmi / libserialport.dart

Serial Port for Dart
https://pub.dev/packages/libserialport
GNU Lesser General Public License v3.0
86 stars 34 forks source link

Failed to load dynamic library on Windows 10 when running an example 0.0.7 #22

Closed pouryaomidi closed 3 years ago

pouryaomidi commented 3 years ago

Hi, Running the example given on https://pub.dev/packages/dart_serial_port/example gives me the following error:

Invalid argument(s): Failed to load dynamic library (126)

0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:11:55)

1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:20:12)

2 LibraryLoader.load (package:dart_serial_port/src/dylib.dart:78:58)

3 dylib (package:dart_serial_port/src/dylib.dart:31:67)

4 _SerialPortImpl.availablePorts. (package:dart_serial_port/src/port.dart:230:32)

5 Util.call (package:dart_serial_port/src/util.dart:37:21)

6 _SerialPortImpl.availablePorts (package:dart_serial_port/src/port.dart:230:21)

7 SerialPort.availablePorts (package:dart_serial_port/src/port.dart:82:61)

8 main (file:///D:/Projects/playground/untitled/bin/untitled.dart:14:33)

9 _delayEntrypointInvocation. (dart:isolate-patch/isolate_patch.dart:283:19)

10 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

I am using dart sdk version: 2.12.0-259.8.beta (beta) (Tue Feb 2 15:59:29 2021 +0100) on "windows_x64".

Any tip is appreciated!

Pourya

jpnurmi commented 3 years ago

Could you check the instructions at #7? In short, flutter_serial_port ships the required external library.

pouryaomidi commented 3 years ago

Hi @jpnurmi , Thanks for your response. Are you suggesting that on Windows there is no way to use the serialport using purely dart?

jpnurmi commented 3 years ago

@pouryaomidi It's certainly possible to use dart_serial_port without Flutter, but libserialport.dll needs to be present. All flutter_serial_port does is to build and deploy the DLL for you [*], but you can build and deploy the DLL by hand instead.

[*] Simply because Flutter provides a build system to do that, whereas pure Dart packages don't have a way to build native C code.

pouryaomidi commented 3 years ago

@jpnurmi, I've already built libserialport using Visual Studio, then added the library in my path, but I still face the same issue mentioned above. Should I mention the libserialport.dll anywhere in the yaml file?

jpnurmi commented 3 years ago

Where is the DLL placed? If I remember correctly, in Windows the DLL can be found "out of the box" if it's in the same directory with the application executable. If that's not possible, you can also define the LIBSERIALPORT_PATH environment variable to tell dart_serial_port where to lookup the DLL.

pouryaomidi commented 3 years ago

I have tried to put it in dart/bin and next to the example file and both results in failed to load error. I will try the last option you said and send an update.

pouryaomidi commented 3 years ago

After creating a system environment variable LIBSERIALPORT_PATH as it is specified in your code in dylib.dart, I was able to run the code. Thanks for helping!

mohammad-imanni commented 2 years ago

@jpnurmi, I've already built libserialport using Visual Studio, then added the library in my path, but I still face the same issue mentioned above. Should I mention the libserialport.dll anywhere in the yaml file?

Give me built tutorial of libserialport

dkozenkov commented 1 year ago

Give me built tutorial of libserialport

@blackghost1379, you can get the compiled library "libserialport-0.dll" here: https://packages.msys2.org/package/mingw-w64-x86_64-libserialport?repo=mingw64 Then make changes to the dylib.dart.