Skip to content

Commit 5165cf2

Browse files
committed
Add manufacturer to approved list of serial drivers to look for.
1 parent b4d1754 commit 5165cf2

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

main.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
const { autoUpdater } = require( 'electron-updater' );
22
const log = require( 'electron-log' );
33

4-
const { BrowserWindow, app } = require( 'electron' );
4+
const { BrowserWindow, app, Notification } = require( 'electron' );
55
const { SerialPort } = require( 'serialport' );
66
const { ReadlineParser } = require( '@serialport/parser-readline' );
77
const path = require( 'path' );
88
const url = require( 'url' );
99
const regex = /(ST|US),GS,\s+([0-9.]+)(lb|kb)/g;
1010
const currentEnvironment = process.env.NODE_ENV;
1111
const isOnline = require( 'is-online' );
12+
const manufacturerList = ['Prolific','FTDI'];
1213

1314
autoUpdater.logger = log;
1415
autoUpdater.logger.transports.file.level = 'info';
@@ -53,6 +54,10 @@ function readLine( line ){
5354
}
5455

5556
function closeWindow( closeMessage = 'you did something wrong.' ){
57+
new Notification({
58+
title: 'Weigh Station Error',
59+
body: closeMessage
60+
}).show()
5661
mainWindow.close();
5762
log.info( 'Window closed because ' + closeMessage );
5863
}
@@ -109,11 +114,12 @@ async function initSerialPort(){
109114
}
110115

111116
const scalePort = ports.find( function( port ){
112-
return port[ 'manufacturer' ] === 'Prolific';
117+
return manufacturerList.includes(port[ 'manufacturer' ]); // Manufacturer of the port is in the list of allowed
113118
} )
114119

115120
if(!scalePort) {
116-
log.error( "Couldn't find scale port" );
121+
closeWindow( "Couldn't find a scale." );
122+
log.error( "Couldn't find a scale." );
117123
return;
118124
}
119125

@@ -144,7 +150,7 @@ async function initSerialPort(){
144150

145151
port.on( 'close', function(){
146152
log.info( 'Port has been closed.' );
147-
closeWindow( 'Port has been closed.' );
153+
closeWindow( 'Lost connection to scale.' );
148154
} );
149155

150156
port.on( 'error', function( e ){
@@ -214,11 +220,11 @@ app.on( 'activate', function(){
214220
} );
215221

216222
app.on( 'will-quit', function(){
217-
if(port.isOpen)
223+
if(port && port.isOpen)
218224
port.close();
219225
} );
220226

221227
app.on( 'quit', function(){
222-
if(port.isOpen)
228+
if(port && port.isOpen)
223229
port.close();
224230
} );

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "scale-serialreader",
33
"productName": "ScaleSerialReader",
4-
"version": "1.0.3",
4+
"version": "1.0.4",
55
"description": "An Electron application with node serialport that streams data from a serial-usb to a website.",
66
"author": "Steven Hawley",
77
"main": "main.js",

0 commit comments

Comments
 (0)