Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Opening \\.\ COM8: Access Denied #333

Closed
humblewizard opened this issue May 16, 2014 · 24 comments
Closed

Error: Opening \\.\ COM8: Access Denied #333

humblewizard opened this issue May 16, 2014 · 24 comments

Comments

@humblewizard
Copy link

Same issue with COM9. Both ports are usable by terminal program.

serialPort.list(); reports all of the ports on the system successfully.

sp1.close(); reports that the port is not currently open.

The OS is Windows 7 and the cmd.exe is opened as Admin before launching node.js

result: Error: Opening .\ COM8: Access Denied

@humblewizard humblewizard changed the title Error: Openning \\:\ COM8: Access Denied Error: Openning \\.\ COM8: Access Denied May 16, 2014
@humblewizard humblewizard changed the title Error: Openning \\.\ COM8: Access Denied Error: Opening \\.\ COM8: Access Denied May 16, 2014
@humblewizard
Copy link
Author

This bit of non (node-serialport) code does work on my system to read the com-port by the way:
I still would like to get the node serialport library working.

  var fs = require('fs');
  var inp = fs.createReadStream("\\\\.\\COM8");
  inp.setEncoding('utf8');
  var inptext = "";
  inp.on('data', function (data) {
      inptext += data;
  });

@voodootikigod
Copy link
Collaborator

@humblewizard what type of device are you connecting? And when you say "does not work" can you provide a bit more context/color? I don't have a win 7 setup with your device handy. Does it just not do anything or does it not output anything or does it error?

@lrice
Copy link

lrice commented Jul 8, 2014

The only experience I've had with this came when I would not properly close a device between runs of a program, and I would get that exact error the next iteration of the program. Try unplugging and replugging the device between runs. You may also be accidentally leaving the terminal connected to the desired COM port, so make sure your program is the first thing you try to run after plugging the device back in (and doublechecking the COM port didn't change obviously).

@vladkosarev
Copy link

I'm getting exact same issue.
[Error: Opening .\COM5: Access denied]
Running as admin. I can open the port just fine in realterm.
Port list is showing the port.
I am just connecting arduino to the port and everything is working fine other than this library in node.

Any clue why this would be happening?

Thanks.

@vprimachenko
Copy link

Very same here. WIN7x64

@voodootikigod
Copy link
Collaborator

I have things running perfectly fine on my surface here. Any chance you
have something strange with a device driver (FTDI driver maybe)?

Chris Williams

@voodootikigod http://twitter.com/voodootikigod | GitHub
http://github.com/voodootikigod

The things I make that you should check out:
SaferAging http://www.saferaging.com/ | JSConf http://jsconf.com/ |
RobotsConf http://robotsconf.com/ | RobotsWeekly
http://robotsweekly.com/

Help me end the negativity on the internet, share this
http://jsconf.eu/2011/an_end_to_negativity.html.

On Mon, Jan 5, 2015 at 8:23 AM, Valerij Primachenko <
notifications@github.com> wrote:

Very same here. WIN7x64


Reply to this email directly or view it on GitHub
#333 (comment)
.

@rlemon
Copy link

rlemon commented Jan 7, 2015

I have hit this issue today. Windows 7 (64bit) and the node-serialport 1.4.10 and node-webkit (not sure if this is causing issues) 0.11.5

to reproduce:
I create a small dummy application that just gives users three inputs. a select list of the available coms (from serialport.list) and a baud option and a 'ok' button. the first connect works fine, and I can communicate with the device, however if I refresh the 'page' (remember this is node-webkit) it errors, also if I run port.close(openPortAgainFn) I can report it does say it closes the port, but when I attempt to reopen it I get the same access denied errors. Note: I get this error when programatically closing and opening the port for a second time, as well as when I refresh the 'app/page' in node-webkit. Killing the node-webkit process and restarting it seems to solve the issue with the port being inaccessible.

Hopefully this helps shed a little more light on what is happening. I'm not fully convinced it is anything wrong with the library, maybe I'm just doing something wrong.

Edit: I did muck things up, I solved the issue of it not allowing me to close and reopen, however refreshing the application still breaks it. here is a gif outlining what I see you'll see I've added a few logs to describe the events I'm seeing. This isn't actually a problem for me as I'll be hiding those options for my application, however again, hopefully this helps others sort their issues.

@kallaspriit
Copy link

I'm seeing this as well on node-webkit when I don't explicitly close opened ports before refreshing the application. Only closing and re-opening the node-webkit application seems to make the ports usable again. The ports are also unusable from other applications until node-webkit is closed so it's more likely node-webkit issue rather then the serialport library fault.

I'm running windows 8.1 64bit, node v0.11.13-pre, node-webkit 0.11.2.

@dynamite-ready
Copy link

I can also reproduce a similar bug in Node Webkit (0.7.5).

To reproduce it, open an active port, and once it starts receiving data, close it.
Then try to open the same port. Node Serial port says it's closed, but it should be free.

The port only becomes free, after restarting Node Webkit.
That suggest there must be a work around of some kind.

I've tried to purge the Node Serialport reference from the require cache, but that didn't work.
Has anyone had any luck trying that?

@dynamite-ready
Copy link

Ignore the last post. The bug I encountered was a result of not clearing the last created object, and it's event handlers.

@olecom
Copy link

olecom commented Feb 3, 2015

#333 (comment)

  var fs = require('fs');
  var inp = fs.createReadStream("\\\\.\\COM8");
  inp.setEncoding('utf8');
  var inptext = "";
  inp.on('data', function (data) {
      inptext += data;
  });

Lucky man. I still am getting this on simple access nodejs/node-v0.x-archive#6125

Error: UNKNOWN, open '\\.\COM13'

(huawei modem, worked on node 0.7 somehow)...

@willemmulder
Copy link

I have the same issue. Getting a

events.js:72
    throw er; // Unhandled 'error' event
Error: Opening \\.\COM3: Access denied

Windows8.1.

@willemmulder
Copy link

Would there be a workaround to test what exactly fails?

What I know at the moment

OK device works fine
OK drivers work fine
OK third-party program displays data just fine
NOK node-serialport throws error on creating the SerialPort.

This is the program I have:

var serialPortModule = require("serialport");
var firstComPortName;
serialPortModule.list(function (err, ports) {
  ports.forEach(function(port) {
    firstComPortName = port.comName;
  });
  console.log(firstComPortName);
  if (firstComPortName) {
    try {
        var SerialPort = serialPortModule.SerialPort;
        var serialPort = new SerialPort(firstComPortName, {
            baudrate: 115200
        });
      }
    }
  }

@jacobrosenthal
Copy link
Contributor

Hrm. Just saw this or something similar today testing some windows stuff. For me It was my code, It turns out I was opening a port that I thought I had lazy opened.

var serialPort = new com.SerialPort(path, {
   baudrate: 9600,
 }); \\NOTICE NOT FALSE
serialPort.open();
C:\Users\jacobrosenthal\Desktop\bs2-programmer [master +1 ~0 -0 !]> node .\examp
les\hi.js COM47
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Opening \\.\COM47: Access denied
    at Error (native)

@willemmulder
Copy link

Thanks. So how did you change your code to get it working?

@jacobrosenthal
Copy link
Contributor

This may or may not be your problem, but In my case you cant open a port thats trying to open. I used the lazy opening pattern by adding false so I could still explicitly open.

var serialPort = new com.SerialPort(path, {
   baudrate: 9600,
 }, false);
serialPort.open();

My finding was interesting (to me) because we now know you can block yourself from accessing the port.

@willemmulder
Copy link

He Jacob, thanks. I'm not sure whether this is the problem that I'm having, since I get the error at the very moment that I create the SerialPort (even without an explicit .open()) but maybe it helps to lazy open the port, and then explicitly call .open() on it. Let's see!

@corelgott
Copy link

Hi @ all,

I'm currently stuck on the "Access denied"-problem on a win7 x64. I'm not 100% sure if its an interesting thing, but since the error comes instantaneously when creating the serial port it investigated it a little. Since it shouldn't access the port at the time of creation the error kind of makes no sense.
That got me thinking... after I spent some time on this, it seems that the error is not the result of the lib accessing the port, but when trying to require the pre-compiled bindings...

My compiled bindings are laying under:

\\node_modules\\serialport\\build\\serialport\\v1.6.3\\Release\\node-webkit-v43-win32-x64\\serialport.node

When the port is created line 14 in serialport.js reads:

var SerialPortBinding = require(binding_path);

whereas binding_path resolves to the correct path. But results in the "access denied" error.

When just executing require [path/to/lib] directly in the console I'm seeing the same behavior.

Running require('fs').readFileSync([path/to/lib]) returns the buffer containing the files content as expected... (Without any error)

I might be on the completely wrong track here - but perhaps it's worth looking into this.

@corelgott
Copy link

I finally have solved the problem... at least for me

After setting the windows permissions on the serialport.node lib to "Full Access" for "Anyone" (Nothing lesser worked for me) the error changed to %1 is not a valid Win32 application - Which was great so I only hat to figure out how to compile it for win7 x64

After fiddling around with node-pre-gyp for a while this one worked for me:

node-pre-gyp configure --runtime=node-webkit --target=0.12.0 -target-platform=win64

I had to move the resulting file into \\node_modules\\serialport\\build\\serialport\\v1.6.3\\Release\\node-webkit-v43-win32-x64 (even though the versions don't even loosely match the nw-version I am using) - Set permissions and after that everything is working....

@zbycz
Copy link

zbycz commented Jun 19, 2015

I had exactly this issue, when other program was using the specified COM port, so node wasnt able to access it.

@cinderblock
Copy link

I'm having the same issue.

C:\Users\...>node
> var SerialPort = require('serialport').SerialPort;
undefined
> var serialPort = new SerialPort('COM5');
undefined
> serialPort.open(function(err) {if (err) console.log(err);});
undefined
> [Error: Opening \\.\COM5: Access denied]

I can open COM5 with putty so I'm quite sure nothing else is using the port.

I've tried running node as administrator.

Windows 8.1 x64
node v0.12.6
node-serialport 1.6.1

@heaversm
Copy link

Had the same error and the comment from @jacobrosenthal about lazy loading worked for me. Thanks!

@durst99
Copy link

durst99 commented Feb 2, 2016

I'm having also this issue. Can someone tell me where to put the code that jacobrosenthal postet ?
var serialPort = new com.SerialPort(path, { baudrate: 9600, }, false); serialPort.open();

@reconbot
Copy link
Member

Creating a SerialPort object will open your port for you unless you tell it not to. When you call open you get an error as it's already open. So if you get this error, don't call open or tell the port not to open immediately.

The docs on openImmediately are here.

I'm going to close this issue for now.

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests