serialport / bindings-rust Goto Github PK
View Code? Open in Web Editor NEWExperimental Serialport bindings written in rust
Experimental Serialport bindings written in rust
Very subject to change, I'm just playing around right now but this feels very possible in ways it hasn't before.
A rust based bining following the abstract binding api that be be used instead of the bindings package today. I'm considering the new bindings api because I think it will be easier to make, but the usage of serialport/stream is so high that this has to work with it eventually.
Nice to haves
A napi.rs based rust bindings that provides a binding class and utility functions. This gives us prebuilt binaries for many platforms and N-API support for electron and worker threads.
The async patterns we need to use here are not very clear to me. I think a mix of serialport-rs and custom async code will get us to the performance metrics. To start we can stick all the serialport-rs code behind tokio's task::spawn_blocking()
but this spawns temporary threads for every call which isn't performant for any operation.
The current bindings put all c++ operations on an event loop provided by v8. And put the unix fs read/write operations onto an IO thread pool. For windows the operations are "async" and don't need the thread pool as I understand it. In any case this isn't consistent.
The bindings design has a read and write queue. The current inflight read, inflight write and any administrative function (eg, not a read or write) can all be inflight at the same time being worked by the event loop or by the thread pool. I wonder if drain
blocks the event loop in our current setup?
Opening, setting baud rates and other com settings don't appear to be blocking. This isn't a comprehensive list. Tokio claims to be able to do async io on unix platforms unclear about windows and unclear about serialports.
Dedicating threads for reads, writes and drain, and having a single tokio thread for administrative functions. Pros, everything has dedicated resources, cons we'll need to provide our own communication channels for reads and writes and wont be able to use tokio for that, possible lower performance without a poller telling us when we can resume reading/writing.
Assuming we can do unix async io for serialports with tokio, we use spawn_blocking
for windows serialport reading and reading and writing through serialport-rs
. Everything else goes on the default tokio thread pool except drain
which we use spawn_blocking
as well. Pros, easy setup, easy reasoning about execution, cons possible poor performance for windows.
Assuming we can do unix async io for serialports with tokio, we write an async windows serialport struct for reading and writing. Everything goes on the default tokio thread pool except drain
which we use spawn_blocking
for the blocking thread_pool
. Pros, easy setup, easy reasoning about execution, cons, a lot of work possibly for windows serialport writing/reading.
spawn_blocking
spawns a new thread each time. I see references to that and to a blocking pool and how you can turn a normal thread into a blocking thread. Its just very confusing. it does use a thread pool for blocking operationsdeno written in rust using v8 can use directly the rust bindings and then
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.