mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2026-03-12 03:58:40 +01:00
Serial port test script
This commit is contained in:
parent
cf91c4df1e
commit
6f6d885477
1 changed files with 40 additions and 0 deletions
40
luciexpress/testserial.js
Normal file
40
luciexpress/testserial.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
var sys = require("sys");
|
||||
var SerialPort = require("serialport").SerialPort
|
||||
var serialPort = new SerialPort("/dev/ttyUSB0", {
|
||||
baudrate: 115200
|
||||
});
|
||||
serialPort.open(function (error) {
|
||||
if ( error ) {
|
||||
console.log('failed to open: '+error);
|
||||
} else {
|
||||
console.log('open');
|
||||
var commands = ["ifconfig"];
|
||||
serialPort.on('data', function(data) {
|
||||
process.stdout.write(data);
|
||||
if(String(data).indexOf("Inteno login:") >= 0){
|
||||
console.log("onlogin");
|
||||
serialPort.write("\n", function(err, results) {
|
||||
console.log('err ' + err);
|
||||
console.log('results ' + results);
|
||||
});
|
||||
} else if(String(data).indexOf("Password:") >= 0){
|
||||
console.log("onpassword");
|
||||
serialPort.write("\n", function(err, results) {
|
||||
console.log('err ' + err);
|
||||
console.log('results ' + results);
|
||||
});
|
||||
} else if(String(data).match(/\w*@\w*:[^#]#/)){
|
||||
if(commands.length){
|
||||
serialPort.write(commands.shift()+"\n", function(err, results) {
|
||||
//console.log('err ' + err);
|
||||
//console.log('results ' + results);
|
||||
});
|
||||
} else {
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
});
|
||||
serialPort.write("\n");
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Add table
Reference in a new issue