Access to the port 'COM9' is denied

1,606 views
Skip to first unread message

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com
i have tryed to connect to gps reserver  with using C#.net but i got an error.i have full permission to my pc.i disable firewall also.please help me to solove this problem


System.UnauthorizedAccessException was unhandled
  Message="Access to the port 'COM9' is denied."
  Source="System"
  StackTrace:
       at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
       at System.IO.Ports.SerialStream..ctor (String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
       at System.IO.Ports.SerialPort.Open()
       at PortProgramming.SerialPortProgram..ctor() in E:\CJ's Documents\4thYear\Project\Temp\PortProgramming\PortProgramming\Program.cs:line 31
       at PortProgramming.SerialPortProgram.Main (String[] args) in E:\CJ's Documents\4thYear\Project\Temp\PortProgramming\PortProgramming\Program.cs:line 20
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

Nilantha Ekanayake

unread,
May 20, 2007, 1:41:30 AM5/20/07
to DotNetDe...@googlegroups.com

sriram reddy

unread,
May 20, 2007, 8:19:19 AM5/20/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

DId yo do he project as webproject or windows project?
looks like your trying to access serial port from IIS if so try to
impersonalize the access.

sriram

On May 20, 6:41 am, "Nilantha Ekanayake" <nilant...@gmail.com> wrote:
> i have tryed to connect to gps reserver with using C#.net but i got an
> error.i have full permission to my pc.i disable firewall also.please help me
> to solove this problem
>
> System.UnauthorizedAccessException was unhandled
> Message="Access to the port 'COM9' is denied."
> Source="System"
> StackTrace:
> at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode,
> String str)

> at System.IO.Ports.SerialStream..ctor(String portName, Int32


> baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32
> readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable,
> Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
> at System.IO.Ports.SerialPort.Open()
> at PortProgramming.SerialPortProgram..ctor() in E:\CJ's
> Documents\4thYear\Project\Temp\PortProgramming\PortProgramming\Program.cs:l­ine
> 31

> at PortProgramming.SerialPortProgram.Main(String[] args) in E:\CJ's
> Documents\4thYear\Project\Temp\PortProgramming\PortProgramming\Program.cs:l­ine


> 20
> at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
> args)

> at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence

Nila

unread,
May 22, 2007, 1:19:38 AM5/22/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi..
It was a windows project.I found it from code project
--codings are
#region Namespace Inclusions
using System;
using System.IO.Ports;
using System.Windows.Forms;
#endregion

namespace PortProgramming
{
class SerialPortProgram
{
// Create the serial port with basic settings
private SerialPort port = new SerialPort("COM9", 9600,
Parity.None, 8, StopBits.One);

[STAThread]
static void Main(string[] args)
{
// Instatiate this class
new SerialPortProgram();
}

private SerialPortProgram()
{
Console.WriteLine("Incoming Data:");

// Attach a method to be called when there is data waiting
in the port's buffer
port.DataReceived += new
SerialDataReceivedEventHandler(port_DataReceived);

// Begin communications
port.Open();

// Enter an application loop which keeps this thread alive
Application.Run();
}

private void port_DataReceived(object sender,
SerialDataReceivedEventArgs e)
{
// Show all the incoming data in the port's buffer
Console.WriteLine(port.ReadExisting());

sriram reddy

unread,
May 22, 2007, 6:51:16 AM5/22/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

First of all did you try other COM ports. Why dont you try COM1 or 2
may be those works.

I didnt see any errors in the code and i compiled in my PC fine and
reading my COM2 as i dont have COM9.

If you want to achive this much simple.

Dragh and drop the SerialPort controle from your Visual studio toolbox
and set all properties as you want.

then to the code page of the win Form you instantiated the control and
do some thing like this.


intializeComponenets() //this will be generated by your windows form
designer

MyserialPort.Open;

if (MyserialPort.Isopen)
{
// your event on data receive on Myserialport also you can use a
timer object to tick every sec and grab the data from Port buffer
//as GPS receiver puls one in every sec intervel

// then you read a line
Myserialport.readline();
// GPS receiver place a line terminator after every pull by default
// then log int your file or desplay the position on you co-ordinates

}

let em know if you need full code for receiving loging and displaying
on given co-ordinates.

sriram

> at System.Threading.ThreadHelper.ThreadStart()- Hide quoted text -
>
> - Show quoted text -

Nila

unread,
May 23, 2007, 12:29:59 AM5/23/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
hi.
Thankx.I'll try with your way.I used com9 because my gps resv software
wk with com9. I tryed with other com ports also. ill let u know the
progress. thankx again
Nilantha

Nila

unread,
May 28, 2007, 3:30:18 AM5/28/07
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi sriram,
can u please share the codings.
Thankx
Nilantha
Reply all
Reply to author
Forward
0 new messages