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

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

Related

libserial is not detected in my dart programm

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

Puppeteer and Docker for Mac (Apple M1)

Chromium is crashing when opened via puppeteer navigation with the following stack trace on my M1. I'm looking for some help from the community as non m1 based machines don't seem to have an issue with our puppeteer container.
[0613/204124.018517:ERROR:stack_trace_posix.cc(707)] Failed to parse the contents of /proc/self/maps
[0613/204124.746267:ERROR:stack_trace_posix.cc(707)] Failed to parse the contents of /proc/self/maps
[0613/204124.751355:ERROR:stack_trace_posix.cc(707)] Failed to parse the contents of /proc/self/maps
[0613/204124.981155:FATAL:nacl_helper_linux.cc(440)] Check failed: nacl_sandbox->IsSingleThreaded().
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[130:130:0613/204125.140482:FATAL:zygote_main_linux.cc(162)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded().
#0 0x0040072b9339 <unknown>
#1 0x00400722ff23 <unknown>
#2 0x00400722d070 <unknown>
#3 0x00400722dc6e <unknown>
#4 0x004006dae926 <unknown>
#5 0x004006da973e <unknown>
#6 0x004006daa369 <unknown>
#7 0x004006dab0cb <unknown>
#8 0x004006da838e <unknown>
#9 0x004006da8d4e <unknown>
#10 0x0040036e1227 <unknown>
#11 0x00400faba0b3 <unknown>
#12 0x0040036e102a <unknown>
Crash keys:
"switch-7" = "--enable-crashpad"
"switch-6" = "--change-stack-guard-on-fork=enable"
"switch-5" = "--user-data-dir=/tmp/puppeteer_dev_chrome_profile-5BphEe"
"switch-4" = "--enable-crash-reporter=,"
"switch-3" = "--crashpad-handler-pid=117"
"switch-2" = "--enable-crashpad"
"switch-1" = "--no-sandbox"
"num-switches" = "8"
qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[112:138:0613/204125.830241:ERROR:file_path_watcher_inotify.cc(329)] inotify_init() failed: Function not implemented (38)
[0613/204125.946536:ERROR:scoped_ptrace_attach.cc(27)] ptrace: Function not implemented (38)
Assertion failed: p_rcu_reader->depth != 0 (/qemu/include/qemu/rcu.h: rcu_read_unlock: 101)
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
Error scraping url: <my - url>:
Error: Unable to launch chrome
I'm launching puppeteer with the following options:
const args = [
'--no-first-run',
'--no-sandbox',
'--disable-setuid-sandbox',
'--single-process',
'--disable-dev-shm-usage',
'--ignore-certificate-errors',
'--ignore-urlfetcher-cert-requests',
'--disable-blink-features=AutomationControlled'
];
And I'm installing chromium into by ubuntu based container via:
# Install Chrome for Ubuntu
RUN apt-get update \
&& apt-get install -y chromium-browser
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium
Spent all day trying to fix it. In the end running docker with colima solved the issue. The thing is that some stuff simply will not work on arm and there is no point in fighting it. Colima allows you to run everything via Rosetta, hence emulating x86 all the way.
First install colima with brew install colima.
Shut down docker desktop if it's running.
Start colima with colima start --arch aarch64 --vm-type=vz (check readme for more info)
Now you have docker running fully via Rossetta. When running images, use "--platform linux/amd64".

puppeteer says Exception: Websocket url not found

For the first time, I am using puppeteer with dart , here the simple code :
import 'package:puppeteer/puppeteer.dart';
main() async {
var browser = await puppeteer.launch();
await browser.close();
}
In pubspec yaml file:
dependencies:
puppeteer: ^1.16.1
websocket: ^0.0.5
# path: ^1.6.0
when I am trying to run this piece of code with dart command:
dart puppy1_test.dart
I am getting this exception :
Unhandled exception:
Exception: Websocket url not found
#0 _waitForWebSocketUrl (package:puppeteer/src/puppeteer.dart:311:3)
<asynchronous suspension>
#1 Puppeteer.launch (package:puppeteer/src/puppeteer.dart:170:30)
<asynchronous suspension>
#2 main (file:///D:/project/<removed>/dl/puppy1/test/puppy1_test.dart:7:33)
#3 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
I solved the problem by deleting the .local-chromium folder. In this folder the chrome application is stored.
I suspect that the reason was a version mismatch, because I updated the dart version, after the creation of the project.

Creating a directory list in windows using Dart

I am trying to create a directory list on windows using dart but I get an error
Here is my code
void listerine(Directory pat){
//Directory root = new Directory(pat);
//var root = Directory.systemTemp;
pat.list(recursive: true, followLinks: false).listen((FileSystemEntity entity){
main(List<String> arguments){
var root = new Directory("C:\\");
print(root);
listerine(root);
}
Btw I am using android studio as an IDE.
I gives me this error.
I/flutter ( 7224): Directory: 'C:\'
E/flutter ( 7224): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 7224): FileSystemException: Directory listing failed, path = 'C:\/' (OS Error: No such file or directory, errno = 2)
E/flutter ( 7224): #0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1114:29)
E/flutter ( 7224): #1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter ( 7224): #2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
You have the question tagged as flutter but seems you are asking about a pure Dart program?
This code
import 'dart:io';
void listerine(Directory pat) async {
await for (var v in pat.list()) {
print(v);
}
}
main() {
listerine(new Directory("C:\\"));
}
produces what you'd expect on Windows, namely
Directory: 'C:\$Recycle.Bin'
Directory: 'C:\$WINDOWS.~BT'
Directory: 'C:\Apps'
...
Flutter uses a modified version of the Dart SDK replacing html support with the mobile rendering engine (skia).
The majority of Dart code can run in both versions, but not all. This means that you can re-use packages in Dart VM applications and in Flutter applications - but again not all. In particular, interacting with the browser or the platform are only available in their respective versions.
To interact with the Windows file system, you need the Dart VM version. Download this separately. As Günter says, to interact with the mobile file system in Flutter, use path_provider.

PWA Worker throws an error with AngularDart

I am trying to add offline capabilities to an angular dart project, running pub build but
Running pub build:pub.exe build
-----
Unhandled exception:
ProcessException: The system cannot find the file specified.
Command: pub.exe build
#0 _buildProjectIfEmptyOrOld (http://localhost:52940/pwa.dart:116)
<asynchronous suspension>
#1 main (http://localhost:52940/pwa.dart:40)
<asynchronous suspension>
#2 _startIsolate.<anonymous closure> (dart:isolate-
patch/isolate_patch.dart:263)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-
patch/isolate_patch.dart:151)
main.dart
import 'package:angular/angular.dart';
import 'package:my_app/views/app_component/app_component.dart';
import 'package:pwa/client.dart' as pwa;
void main() {
bootstrap(AppComponent);
// register PWA ServiceWorker for offline caching.
new pwa.Client();
}
pubspec.yaml
dependencies:
pwa: ^0.1.2
At that point, the pwa is trying to run pub.exe build. I haven't tried it on Windows, only a friend reported it working, but it is entirely possible that pub.exe does no longer work (if it ever did), and it should have been pub all along (and in this case it is a Windows-related bug).
Suggested workaround:
run pub build
run pub run pwa
run pub build again
If the above works, let me know, and I'll fix it in a patch release.

Resources