Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed partial commit for both serial and HRM drivers [WP-898] #582

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 37 additions & 29 deletions webinos/core/api/iotdrivers/lib/drivers/serialDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
(function () {
'use strict';

var serialPort = require("serialport2").SerialPort;
var serialport_module = require('serialport');
var serialPort = serialport_module.SerialPort;

var path = require("path");
var fs = require("fs");

var intervalId;

var driverId = null;
var registerFunc = null;
var callbackFunc = null;

var SERIAL_PORT;
var SERIAL_RATE;
var serial = 0;
Expand Down Expand Up @@ -56,7 +59,6 @@
}

function init_serial(){

try{
var filePath = path.resolve(__dirname, "./serial_devices.json");
fs.readFile(filePath, function(err,data) {
Expand All @@ -67,17 +69,31 @@
//console.log("\n\nPORT : "+SERIAL_PORT);
//console.log("RATE : "+SERIAL_RATE);
try{
//serial = new serialPort(SERIAL_PORT , { baudrate : SERIAL_RATE });
serial = new serialPort();

serial.open(SERIAL_PORT, {
baudRate: SERIAL_RATE,
dataBits: 8,
parity: 'none',
stopBits: 1
});
serial = new serialPort(SERIAL_PORT, {baudrate: SERIAL_RATE}, false);
intervalId = setInterval(waiting_for_serial,2000);
}
catch(e){
console.log("catch : " + e);
}
}
});
}
catch(e2){
console.log("Serial port " + SERIAL_PORT + " is not ready");
}
}

function waiting_for_serial(){
//console.log("Searching "+ SERIAL_PORT);
serialport_module.list(function (err, ports) {
ports.forEach(function(port) {
if(port.comName == SERIAL_PORT){
//console.log("FOUND PORT");

clearInterval(intervalId);

serial.on('close', function (err) {
serial.open(function () {
serial.on('close', function (err) {
console.log("Serial port ["+SERIAL_PORT+"] was closed");
//TODO handle board disconnection
//TODO start listening for incoming boards
Expand All @@ -89,20 +105,12 @@
setTimeout(init_serial,2000);
}
});

serial.on('open', function () {
start_serial();
});
}
catch(e){
console.log("catch : " + e);
}
}
});
}
catch(e2){
console.log("Serial port " + SERIAL_PORT + " is not ready");
}
start_serial();
});
}
});
});

}

function start_serial(){
Expand Down Expand Up @@ -267,4 +275,4 @@
console.log('Serial driver - unrecognized cmd');
}
}
}());
}());
17 changes: 13 additions & 4 deletions webinos/core/api/iotdrivers/lib/drivers/zephyrHRMDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
(function () {
'use strict';

// var serialPort = require("serialport").SerialPort;
//var serialPort = require("serialport2").SerialPort;
var serialport_module = require('serialport');
var serialPort = serialport_module.SerialPort;

var serialPort = require("serialport2").SerialPort;
var path = require("path");
var fs = require("fs");
//var BT_DEV = "/dev/cu.HXM002536-BluetoothSeri";
Expand Down Expand Up @@ -102,14 +103,17 @@
SERIAL_RATE = settings.bluetooth[0].rate;

try{
serial = new serialPort(SERIAL_PORT, {baudrate: SERIAL_RATE}, false);

/*
serial = new serialPort();

serial.open(SERIAL_PORT, {
baudRate: SERIAL_RATE,
dataBits: 8,
parity: 'none',
stopBits: 1
});
*/

serial.on('close', function (err) {
console.log("Serial port ["+SERIAL_PORT+"] was closed");
Expand All @@ -123,8 +127,13 @@
}
});

/*
serial.on('open', function () {
start_serial();
});*/

serial.open(function () {
start_serial();
});

serial.on( "data", function( chunk ) {
Expand Down Expand Up @@ -278,4 +287,4 @@
}
return values;
}
}());
}());