本文整理汇总了TypeScript中SerialPort.SerialPort.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SerialPort.on方法的具体用法?TypeScript SerialPort.on怎么用?TypeScript SerialPort.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SerialPort.SerialPort
的用法示例。
在下文中一共展示了SerialPort.on方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.open((err) => {
if (err) return console.dir(err);
console.log('serial port opened');
console.dir(port);
serial.on('data', onData);
});
示例3: function
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;
});
})
}
} );
示例4: function
serialport.list(function (err, ports) {
ports.forEach(function(port) {
ports += port.comName + "\n";
console.log(port.comName);
if(port.comName === params[2])
{
currentPort = port;
}
});
console.log("Port " + currentPort.comName + " selected");
var activeSerialPort = new serialport.SerialPort(currentPort.comName, {
baudrate: 9600
});
activeSerialPort.on("open", function () {
var comInServer = new ComInServer();
comInServer.setSerialPort(activeSerialPort);
comInServer.setCallback(function (data) {
console.log(data.toString());
currentLog += data.toString();
});
});
});
示例5: test_events
function test_events() {
let port = new serialport.SerialPort("");
port.on('open', function () { });
}