Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public void Opens()
{
    if (this.serialPort.IsOpen == false)
    {
        this.serialPort.Open();
    }
}


Showing Exception on this.serialPort.Open();
AccessDenied and IOException occured
Posted
Updated 15-Oct-13 19:11pm
v3
Comments
Sergey Alexandrovich Kryukov 16-Oct-13 0:38am    
To start with, if (this.serialPort.IsOpen == false) is silly; this.serialPort.IsOpen is already a Boolean...
—SA
bryce 16-Oct-13 0:50am    
i'm guessing you're using the .net serial port class...
and when you try and open the serial port its throwing an exception and yo don't know why?
How about you tell us some more about your problem so we have data to work on


however access denied would suggest something (antherprogram) has already got the serial port in question open.


bryce
StM0n 16-Oct-13 1:13am    
Same thought...

1 solution

Just because you can create a SerialPort object and set the port to the appropriate value does not mean that the port is available: physical ports cannot be shared by applications since that would bean the received data being "shared" by two applications. This would beam that either all the data would have to be buffered to both - which is unrealistic since Windows would have to buffer an unknown number of applications, which takes time, and serial port processing is supposed to be as quick as possible to prevent overrun - or which application got which data would be random.

As has been suggested, another application got there first - so you cannot open the port. Use a try...catch block to detect this and report the problem to your user - you can't "share" ports!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900