本文整理匯總了TypeScript中SerialPort.SerialPort.open方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript SerialPort.open方法的具體用法?TypeScript SerialPort.open怎麽用?TypeScript SerialPort.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SerialPort.SerialPort
的用法示例。
在下文中一共展示了SerialPort.open方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: SerialPort
let run = (self: SerialPortRelay, resolve, reject) => {
this._handle = new SerialPort(port, {}, false);
this._handle.on('open', () => {
resolve(self);
super.connect(port);
});
this._handle.on('close', () => {
super.disconnect(port);
});
this._handle.on('error', (error) => {
super.error(error, port);
});
this._handle.on('data', (data) => {
super.data(data, data.length, port);
});
try {
this._handle.open();
} catch (error) {
reject(error);
}
};
示例2: Serial
ports.forEach((port) => {
var serial = new Serial(port.comName, {}, false);
serial.open((err) => {
if (err) return console.dir(err);
console.log('serial port opened');
console.dir(port);
serial.on('data', onData);
});
serials.push(serial);
});
示例3: function
export var test = function (com)
{
rfxtrx = new rfxcom.RfxCom(com, { debug: true });
//var jil = 5;
//var newdoma = new doma.jillesdomation(com);
//newdoma.open();
// //rfxtrx.reset = function (callback)
// //{
// // var self = this;
// // return self.sendMessage(0, 0, 0, [0, 0, 0, 0, 0, 0, 0, 0, 0], callback);
// // self.delay(50x00);
// // self.flush(function ()
// // {
// // self.getStatus(callback);
// // });
var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort(com, {
baudrate: 384000,
parser: rfxtrx.rfxtrxParser()
});
serialPort.open(function (error)
{
if (error)
{
console.log('failed to open: ' + error);
}
else
{
console.log('open');
serialPort.on('data', function (data)
{
console.log("Received: %s", dumpHex(data));
console.log("recieved: " + dumpHex(data));
});
buffer = [0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
serialPort.write(buffer, function (err, results)
{
console.log("Sent : %s", dumpHex(buffer));
rfxtrx.delay(500);
serialPort.flush(function ()
{
buffer = [0x0D, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
serialPort.write(buffer, function (err, results)
{
console.log("Sent : %s", dumpHex(buffer));
}
);
console.log('err ' + err);
console.log('results ' + results);
var jil = 5;
});
})
}
} );
// //rfxtrx.initialise();
// jil = 5;
}