UnauthorizedAccessException on comPort.Open() when using usb Bluetooth dongle
Asked Answered
H

1

1

I have an unity/c# app which utilizes com ports to comunicate with a custom bluetooth device. The connection with serial ports works fine when using a stock/inbilt/OE bluetooth device in any computer I tested. When using a usb bluetooth adapter(BT dongle you plug into a usb port), I get an UnauthorizedAccessException when calling serialPort.Open().

The dongle finds my bluetooth device in win , I can see the outgoing serial port name. Have tryed making a plain WindowsFormsApp to figure out timings and delays but it is the same. No matter what I do there is the same exception on .Open() method. The simplified code would goes like:

SerialPort serialPort = new SerialPort(@"\\.\COM3" , 9600);
serialPort.Open();

I have seen and am not dupicating: why is access to com port denied? Access to the port is denied with USB Bluetooth adapter It's just that they dont solve anything.

Hiroshima answered 22/5, 2018 at 9:55 Comment(3)
Try running your app as AdministratorCheyney
"\\\\.\\COM3" instead of simple "COM3".Hollyhock
uf I am soo sorry, made a mistake when asking a question, have edited the code in question to how it's actually written. Please look at it again.Hiroshima
H
0

The UnauthorizedAccessException may be because the Bluetooth device has been paired before with another computer.

In this case the only solution is to remove the Bluetooth device, search for Bluetooth devices, add it again and enter the PIN again.

I use an OBDII adapter like this one: ELM327 Bluetooth adapter

I have a Windows 7 and Windows 10 on the same computer.

When I have recently paired the Bluetooth device on Windows 7 with my computer I can open the COM port without any problem as often as I like.

Then I reboot my computer to Windows 10 and I get an UnauthorizedAccessException. I have to remove the Bluetooth device, search for Bluetooth devices, add it again and enter the PIN again. Then it works.

When I reboot back to Windows 7 I get the UnauthorizedAccessException now on Windows 7 where it worked before. I have to remove the Bluetooth device, search for Bluetooth devices, add it again and enter the PIN again. Then it works.

I can do that as often as I like. Each time I have paired on one Windows, the other Windows is screwed up.

During the pairing process a public / private key pair is generated on the computer and in the Bluetooth device, which change each time. Microsoft is - as always - not able to give us a correct error message. We get an "Access Denied" instead of a more intelligent "Bluetooth Pairing Error".

Headquarters answered 14/12, 2023 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.