I'm trying to access a virtual serial port created with http://www.hhdsoftware.com/virtual-serial-ports on Windows 8.
When I use a terminal emulator (Realterm) to access the port, it seems to work; well, I see characters I type in the output file, I do not see anything from the input file in the emulator window, but to be honest the UI of the emulator is overwhelming and I don't fully understand what I'm doing.
But I actually want to access the port using the serialport module for node.js. This is my JS code:
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var serialPort = new SerialPort("COM2", {
// these are the default values in Realterm that seem to work there
baudRate: 57600,
dataBits: 8,
stopBits: 1,
parity: 'none',
parser: serialport.parsers.readline("\r\n")
}, true, function(error){
if ( error ) {
console.log('failed to open: '+error);
} else {
console.log('open');
serialPort.on('data', function(data) {
console.log('data received: ' + data);
});
serialPort.write("ls\r\n", function(err, results) {
console.log('err ' + err);
console.log('results ' + results);
});
}
});
My problem is that when I run the above code, I only get an error:
failed to open: Error: SetCommState: Unknown error code 87
What's really strange is that I only get this error when I run the code before accessing the port with Realterm. After closing Realterm, I do not get this error, but instead there is simply no output, i.e. the code doesn't receive the "open" event.
Any Ideas what I'm doing wrong?