libserial is not detected in my dart programm - dart

I made a minimalistic dart software that interfaces a serial port:
import 'package:libserialport/libserialport.dart';
import 'dart:typed_data';
void main(List<String> arguments) {
final port = SerialPort("/dev/pts/4");
if (!port.openReadWrite()) {
print(SerialPort.lastError);
}
port.write(Uint8List.fromList("Lorem Ipsum".codeUnits));
final reader = SerialPortReader(port);
reader.stream.listen((data) {
print('received: $data');
});
}
But once I run:
dart run
I get the following error:
Unhandled exception:
Invalid argument(s): Failed to load dynamic library 'libserialport.so': libserialport.so: cannot open shared object file: No such file or directory
#0 _open (dart:ffi-patch/ffi_dynamic_library_patch.dart:12:43)
#1 new DynamicLibrary.open (dart:ffi-patch/ffi_dynamic_library_patch.dart:23:12)
#2 dylib
package:libserialport/src/dylib.dart:32
#3 _SerialPortImpl._init.<anonymous closure>
package:libserialport/src/port.dart:221
#4 Util.call
package:libserialport/src/util.dart:37
#5 _SerialPortImpl._init
package:libserialport/src/port.dart:221
#6 new _SerialPortImpl
package:libserialport/src/port.dart:211
#7 new SerialPort
package:libserialport/src/port.dart:72
#8 main
bin/serial.dart:5
#9 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#10 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
Exited (255)
I run it in a linux machine.

The problem as you see in the error message is that expects somewhere to be found the libserial.so library.
First and formemost we need to locate the library and see if it is installed:
ldconfig -p | grep libserial
At no output you can install it as you can see here. For linux mint and debian based distros run:
sudo apt-get install libserial0
Then re-run the command:
ldconfig -p | grep libserial
If the command after the installation has an output then you must check if the path is /lib/libserialport.so. In my case it was not:
libserialport.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libserialport.so.0
Sometimes after so in librarie's names a number may be appended. In that case we can symlink the libary to the /usr/lib path like that:
sudo ln -s /usr/lib/x86_64-linux-gnu/libserialport.so.0 /usr/lib/libserialport.so
Also, another case is if the library is not located to /usr/lib/libserial.so but in a subfolder inside the /usr/lib path.

The issue is the dynamic library is unable able to load from the system. The solution is
Install libserialport-dev package
for Debian based system use
sudo apt install libserialport-dev
Note: The dart package libserialport uses FFI to access the native API. Under the hood it uses libserialport a minimal, cross-platform shared library written in C. The package actually contain the c code. when we build or run the application it's supposed to be compiled it to libserial.so, but due to some reason this doesn't happen when we use this package directly.
If you use flutter framework use flutter_libserialport package, this take care of creating the .so file without any issue

Related

Issues with running remix Binary in Bazel sandbox

I've encountered an issue trying to use bazel as a build tool for remix. I've been able to run remix in dev mode but currently unable to get remix build to work.
I've encountered a few errors that led up to this point. I'll list the errors in the order which they occurred with my fixes (just incase any of the fixes introduces a new issue)
First error in the bazel sandbox is related to a transitive dependency of #remix-run/dev (#remix-run/dev->gunzip-maybe->browserify-zlib). Bazel failed to fetch the bazel repository #npm__browserify-zlib__0.1.4. I assumed this was a bazel issue and tried to override browserify-zlib#0.1.4 with browserify-zlib#0.2.0, which worked. Here is bazel error for reference:
ERROR: /Users/emmanuel/projects/bbbazel/WORKSPACE:89:17: fetching _npm_import rule //external:npm__browserify-zlib__0.1.4: Traceback (most recent call last):
File "/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/external/aspect_rules_js/npm/private/npm_import.bzl", line 471, column 27, in _impl
pkg_json = json.decode(rctx.read(pkg_json_path))
Error in decode: at offset 685, object has duplicate key: "main"
ERROR: /private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/external/npm/BUILD.bazel:3012:6: #npm//:npm__browserify-zlib__0.1.4_source_directory depends on #npm__browserify-zlib__0.1.4//:source_directory in repository #npm__browserify-zlib__0.1.4 which failed to fetch. no such package '#npm__browserify-zlib__0.1.4//': at offset 685, object has duplicate key: "main"
Next error in the bazel sandbox is related to another transitive dependency of #remix-run/dev (#remix-run/dev->xdm->deasync). The install lifecycle hook for the deasync npm package makes a call to the node-gyp binary which doesn't exist in the sandbox and the bazel build command fails during setup. To fix this, I disabled the install lifecycle hook (I also disabled it with a pnpm install outside the sandbox and the remix build command executed perfectly) which led to the final error. Here's the error message for this error:
/Users/emmanuel/projects/bbbazel/BUILD.bazel:5:22: Running lifecycle hooks on npm package deasync#0.1.28 failed: (Exit 1): lifecycle-hooks.sh failed: error executing command (from target //:.aspect_rules_js/node_modules/deasync#0.1.28/lc) bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/aspect_rules_js/npm/private/lifecycle/lifecycle-hooks.sh deasync ../../../external/npm__deasync__0.1.28/package ... (remaining 1 argument skipped)
/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/external/aspect_rules_js/npm/private/lifecycle/min/node-gyp-bin/node-gyp: line 5: 1211: command not found
node-gyp not found! Please upgrade your install of npm! You need at least 1.1.5 (I think) and preferably 1.1.30.
> deasync#0.1.28 install /private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/deasync#0.1.28/node_modules/deasync
> node ./build.js
===============================================================
Failure while running lifecycle hook for package 'deasync#0.1.28':
Script: 'install'
Command: `node ./build.js`
Stack trace:
spawn ENOENT
at ChildProcess.<anonymous> (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/external/aspect_rules_js/npm/private/lifecycle/min/index.min.js:1:91930)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1100:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)
The final error suggests a bug with remix, but since it only occurs in the bazel sandbox I think it may be an issue that cuts across bazel and remix. The error returned is shown below:
The following error is a bug in Remix; please open an issue! https://github.com/remix-run/remix/issues/new
Missing output for entry point
Error
at Object.onCompileFailure (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/#remix-run+dev#1.12.0_#remix-run+serve#1.12.0/node_modules/#remix-run/dev/dist/cli/commands.js:180:13)
at Object.compile (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/#remix-run+dev#1.12.0_#remix-run+serve#1.12.0/node_modules/#remix-run/dev/dist/compiler/remixCompiler.js:34:134)
at async Object.build (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/#remix-run+dev#1.12.0_#remix-run+serve#1.12.0/node_modules/#remix-run/dev/dist/compiler/build.js:33:3)
at async Object.build (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/#remix-run+dev#1.12.0_#remix-run+serve#1.12.0/node_modules/#remix-run/dev/dist/cli/commands.js:175:3)
at async Object.run (/private/var/tmp/_bazel_emmanuel/f416ba8913b741927ac435783e3163e0/sandbox/darwin-sandbox/1566/execroot/fleet/bazel-out/darwin_arm64-fastbuild/bin/node_modules/.aspect_rules_js/#remix-run+dev#1.12.0_#remix-run+serve#1.12.0/node_modules/#remix-run/dev/dist/cli/run.js:449:7)
Building Remix app in production mode...
Target //examples/remix:build failed to build
I've tried to run it outside bazel and with pnpm (I added the override to the package.json for browserify-zlip#0.2.0, then I ran pnpm instal with --ignore-scripts flag) and it builds fine.
I'm not sure if this is a bug with remix or a bazel issue. Has anyone else experienced this? Or does anyone having a working version of remix with bazel as the build tool?
I've created a minified version of the repository in the state of the 3rd error https://github.com/noelenwenede/bbbazel. Start up instructions are in the readme file.

docker gradle java windows git build local dependency projects best practise

I have 1 gradle java Project-A that depends on 2 other gradle java Project-B and also Project-C. All 3 projects build locally using build.gradle and Project-A build.gradle contains:
implementation project(':Project-B')
implementation project(':Project-C')
and Project A settings.gradle contains:
include ':Project-B'
project(':Project-B').projectDir = new File(settingsDir, '../Project-B')
include ':Project-C'
project(':Project-C').projectDir = new File(settingsDir, '../Project-C')
All 3 projects have separate private Git repo (because in future other projects depend on B and C).
So that's fine. Now I want to dockerise project-A. Its Dockerfile is:
FROM gradle:jdk11-alpine AS builder
COPY ./ ./
RUN gradle build
FROM adoptopenjdk/openjdk11:jre-11.0.6_10-alpine
COPY --from=builder *.jar Project-A.jar
CMD ["java -jar Project-A.jar"]
The docker build . for Project-A is giving an error:
#11 51.17 FAILURE: Build failed with an exception.
#11 51.17
#11 51.17 * What went wrong:
#11 51.17 Could not determine the dependencies of task ':bootJar'.
#11 51.17 > Could not resolve all task dependencies for configuration ':runtimeClasspath'.
#11 51.17 > Could not resolve project :project-B.
#11 51.17 Required by:
#11 51.17 project :
#11 51.17 > No matching configuration of project :project-B was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally but:
#11 51.17 - None of the consumable configurations have attributes.
#11 51.17 > Could not resolve project :project-C.
#11 51.17 Required by:
#11 51.18 project :
#11 51.18 > No matching configuration of project :project-C was found. The consumer was configured to find a runtime of a library compatible with Java 11, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally but:
#11 51.18 - None of the consumable configurations have attributes.
So, what's best practise to get a Dockerfile to build Project-B and Project-C ? i.e. the respective jar aren't published anywhere else and have to be built along with Project-A
The bootJar task is merely:
bootJar {
archiveBaseName = 'Project-A'
archiveVersion = '0.1.0'
}
Basically, a locally run gradle build can resolve the underlying projects, but a locally run docker build . cannot. What COPY step am I missing?

Dart libserial is unable to open `/dev/pts` devices

I am monitoring a serial device via a jpevulator:
jpnevulator --read --ascii --tty /dev/ttyACM0 --pty --pass --read --ascii --timing-print
jpnevulator: slave pts device is /dev/pts/3.
jpnevulator: Use --read or --write, but not both. Performing a read this time.
**strong text**
And I made a simple programm that sends a string and reads from the serial port as well:
import 'package:libserialport/libserialport.dart';
import 'dart:typed_data';
void main(List<String> arguments) {
final port = SerialPort("/dev/pts/3");
if (!port.openReadWrite()) {
print(SerialPort.lastError);
}
port.write(Uint8List.fromList("Lorem Ipsum".codeUnits));
final reader = SerialPortReader(port);
reader.stream.listen((data) {
print('received: $data');
});
}
But I get the error once I dart run it:
Building package executable...
Built serial:serial.
Unhandled exception:
SerialPortError: No such file or directory, errno = 2
#0 Util.call (package:libserialport/src/util.dart:39:7)
#1 _SerialPortImpl._init (package:libserialport/src/port.dart:221:10)
#2 new _SerialPortImpl (package:libserialport/src/port.dart:211:42)
#3 new SerialPort (package:libserialport/src/port.dart:72:38)
#4 main (file:///mnt/data/Kwdikas/dart/serial/bin/serial.dart:5:16)
#5 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
Any idea why? I am running it on linux mint. I am using flutter installed dart that is shipped as snap:
$ whereis dart
dart: /usr/bin/dart /usr/lib/dart /snap/bin/dart
And I have installed it using classic confinement:
sudo snap install flutter --classic

Pipenv uses the wrong lib directory

I have a project using Python 3.10.4, i. e., the Pipfile has,
[requires]
python_version = "3.10.4"
I installed Python 3.10.4 using pyenv install 3.10.4 and now pyenv versions returns,
* system (set by /home/username/.config/pyenv/version)
3.10.4
Now when I run pipenv install I get,
Creating a virtualenv for this project…
Using /home/username/.config/pyenv/versions/3.10.4/bin/python3 (3.10.4) to create virtualenv…
⠋created virtual environment CPython3.10.4.final.0-64 in 82ms
creator CPython3Posix(dest=/home/username/.local/share/virtualenvs/project-2ZeatEXR, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/username/.local/share/virtualenv)
added seed packages: pip==20.3.4, pkg_resources==0.0.0, setuptools==44.1.1, wheel==0.34.2
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Virtualenv location: /home/username/.local/share/virtualenvs/project-2ZeatEXR
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
from . import utils
File "/usr/lib/python3/dist-packages/pipenv/vendor/requests/utils.py", line 27, in <module>
from .cookies import RequestsCookieJar, cookiejar_from_dict
File "/usr/lib/python3/dist-packages/pipenv/vendor/requests/cookies.py", line 172, in <module>
class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
AttributeError: module 'collections' has no attribute 'MutableMapping'
The line Using /home/username/.config/pyenv/versions/3.10.4/bin/python3 (3.10.4) indicates that pipenv has found the right Python version and is using it to create the virtual environment but then when creating the lock file, observe that it uses the lib: /usr/lib/python3/dist-packages/pipenv/vendor/requests/utils.py directory is of the system installation. Which then causes the error since the system's lib is for Python 3.9.
Maybe this is a bug or maybe I have missed some config. Could someone see what is going wrong here?

Can't install libgtk2.0-dev_2.24.31-2_arm64.deb on Renesas R-Car H3 (H3ULCB)

I am trying to run object detection algorithm (which is using OpenCV 2.4.13.7) on H3ULCB. It is giving libGTK as shown below
root#h3ulcb:/media/2.4.13_algo_target_# ./main_
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or [ 1976.641753] audit: type=1706
Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvWaitKey, fil7
terminate called after throwing an instance of 'cv::Exception'
what(): /media/2.4.13.7_pckage/modules/highgui/src/window.cpp:567: error: (-2) The function is not implemented. Rebuild the library with Wiy
Aborted (core dumped)}
To solve the error , I tried to install libGTK package (libgtk2.0-dev_2.24.31-2_arm64.deb) on H3ULCB, but its not getting installed to the target.
* pkg_extract_data_file_names_to_stream: Failed to extract data.tar.gz from package '/media/libgtk2.0-dev_2.24.31-2_arm64.deb'.
* pkg_get_installed_files: Error extracting file list from /media/libgtk2.0-dev_2.24.31-2_arm64.deb.
* opkg_install: Cannot install package libgtk2.0-dev.
BSP and SDK for H3ULCB are build using yocto, details are listed below:
Yocto version: 2.23
Poky: 2.1.3
The same error is resolved on the native Linux (Ubuntu16.04) by installing the libgtk2.0 library from apt-get manager. But package manager apt and dpkg is not getting installed on the target. I tried to add these managers in the yocto layers while building the image.
Currently Available package manager on H3ULCB is OPKG. Since OPKG works on .IPK packages but not .IPK packages on available for libgtk2.0, I have converted the .deb package to a .IPK package .While executing the .IPK package on H3ulcb:
root#h3ulcb:/media# opkg install libgtk2.0-dev_2.24.31-2_arm64.ipk
Collected errors:
* open_outer: Failed to open package 'libgtk2.0-dev_2.24.31-2_arm64.ipk': Unrecognized archive format
* pkg_extract_control_file_to_stream: Failed to extract control.tar.gz from package 'libgtk2.0-dev_2.24.31-2_arm64.ipk'.
* pkg_init_from_file: Failed to extract control file from libgtk2.0-dev_2.24.31-2_arm64.ipk.
In the package libgtk2.0-dev_2.24.31-2_arm64.deb, there are 3 files
control.tar.gz
data.tar.xz
debian-binary
while executing the .deb file on H3ULCB, the error showed data.tar.gz instead of data.tar.xz as given below:
pkg_extract_data_file_names_to_stream: Failed to extract data.tar.gz from package '/media/libgtk2.0-dev_2.24.31-2_arm64.deb'.
I have converted data.tar.xz to data.tar.gz, but how to pack these files 3 files back to .deb package?

Resources