Replies: 1 comment
-
I tend to do something like this, where I keep my device commands contained to the main process and only expose the commands that I want available in the UI, I typically use a Promise Queue to prevent cross talk:
I recommend using the promise queue, but this approach lets you keep everything in promises. I also recommend keeping ports open in the deviceManager collection to reduce the overhead of opening the port every call. This is why I have the removeListeners in the ack_call so that it doesn't get overloaded with 'error' listeners. |
Beta Was this translation helpful? Give feedback.
-
Hello, I am converting a web app to electron and attempting to utilize seriaport for device communications.
The app is essentially control software for an appliance which is connected over USB serial.
The device under control uses a simple line-based protocol: read one line of serial data, then send a line of reply (using
/r/n
delimiters). I would like be able to send a message and receive the reply as single operation, much like an ajax request.So I would like to something similar to this:
The problem is that IPC has to copy arguments across processes, using the Structured Clone Algorithm which is not capable of copying functions. So clearly the callback style cannot work, as we can't pass
responseHandler
toTxRx
.The promise based version doesn't pass
responseHandler
argument directly to the ipc handler, so it almost looks like that could work. However, in my admittedly limited understanding of promises, i think even trying some promise-based solution wouldn't workaround the issue, and would still require copying the.then( ... )
argument across processes at some level?Without any way to pass functions around, I feel completely lost as to how to get anything done.
Can anyone help me understand how one is meant to properly send a message and then process the reply?
Below is a rough summary of most of the relevant code I am attempting to use for this.
serial.js
preload.js
main.js
Beta Was this translation helpful? Give feedback.
All reactions