Serial communication in Electron

Pavol Kögler
3 min readJun 23, 2020

Few months ago I came across an interesting project. Group of skilled electrical engineers developed machine that could regenerate old lead batteries. However they needed nice interface for workers on site to operate their machine. So they asked me for help. The setup was simple — my interface will run on Raspberry Pi and it will communicate with the machine through serial interface. As a JavaScript developer my first choice was to use electron. I got some nice example for electron working with react to get started and only thing left was to have working serial communication. It seemed to me as an easy task, there are some libraries that can do that. However when I started building the app for linux I was always getting some errors and it seemed to be impossible to make it work. I spent like 10 hours and with no real progress I decided to ditch it. What came to my mind was:

  • I have fixed environment — the app will always run in exactly given version of Raspbian
  • It is easy to use cli to communicate through serial interface in linux
  • It is easy to call shell commands from electron backend
  • There will be only one usb device attached to the raspberry (our machine)

So I decided to end the dependency nightmare caused by serial communication packages from npm and build it from scratch.

--

--