Interface and Application Programming

For this assignment, I'll test interfacing with the serial asynchronous bridge board "hello.bus.45".

The bridge board will double blink if it receives 0 "it's id" or single blink otherwise.

I tested interfacing with the board using NodeJs using "serialport" package.

var SerialPort = require('serialport');
var port = new SerialPort('/dev/ttyUSB0', {
 baudRate: 9600,
 parser: SerialPort.parsers.readline('\n')
});
port.on('open', function() {
 port.write('0', function(err) {
   if (err) {
     return console.log('Error on write: ', err.message);
   }
   console.log('message written\n');
 });
});
// open errors will be emitted as an error event 
port.on('error', function(err) {
 console.log('Error: ', err.message);
})
port.on('data', function (data) {
 console.log('Data: ' + data);
});

The code open USB0 port and send 0 and print out the returned message

I then started to test out Electron to see how I can use it to create desktop applications using NodeJs

First I downloaded cloned the 'Getting Started' repo and explored it to see how it works.

I then installed the serialport package and pasted the previous code into renderer.js but I cam with an error: 'Uncaught Error: Module version mismatch. Expected 48, got 46.'

I searched for the problem and found out that I didn't install it the right way for electron so I found the right way to do it in the docs:

ran 'npm start' and got it working

Next I created some field to dynamically configure the serial port and display output in a text box and modified the code to handle the serial communications

Files