简体   繁体   中英

Node.js serial port on windows Access denied

I have following error while running short program:

events.js:2817: Uncaught Error: Opening \\.\COM1: Access denied

my program is just to try to open the port and see what is it working:

var SerialPort = require("serialport").SerialPort;

var serialPort = new SerialPort('COM1',{baudrate: 9600}, true);


serialPort.on ('open', function () {
    console.log("Open");
    serialPort.write(0x05);
    serialPort.on ('data', function( data ) {
        console.log("data" + data.toString());
    });
});

I am using USB to COM adapter that is set on COM1.

Try

var serialPort = new SerialPort('\\\\.\\COM1', {baudrate: 9600}, true);

This worked magic for me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM