-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcs-controller.js
More file actions
47 lines (35 loc) · 1.1 KB
/
cs-controller.js
File metadata and controls
47 lines (35 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Entry point for Control Solutions Node.js package
*
* This file exposes the API for communicating via serial port to
* CS's controller products.
*
*/
'use strict';
var serialPortFactory = require('serialport');
var MotorController = require('./lib/MotorController');
function ControllerManager()
{
var manager = this;
// Keeps track of all the ports we are managing
manager.ports = [];
// Access to the serialport module list function
manager.list = serialPortFactory.list;
manager.addPort = function( name, config )
{
// Override defaults with caller's config if any
var portConfig = {
baudrate: 115200, dataBits: 8, stopBits: 1,
};
for( var prop in config ) {
portConfig[prop] = config[prop];
}
// Create and save the new controller interface object
var thePort = new MotorController( name, portConfig );
manager.ports.push( thePort );
// Attempt to open (and keep open) the port
thePort.open();
return thePort;
};
}
module.exports = new ControllerManager();