Solved

Access to COM Port denied

Posted on 2011-03-22
5
672 Views
Last Modified: 2012-05-11
Whenever I try and access a COM Port  Open control that has been declared on a previous form it give me the following error. Access to the port COM20 is denied.
0
Comment
Question by:cmdolcet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 34

Expert Comment

by:it_saige
ID: 35192819
Could you perhaps provide some code to review?

-saige-
0
 

Author Comment

by:cmdolcet
ID: 35192939
I go through this the first sub and open the port (btnFindButton_Click). I return all the values on that open port. I then press the btnChangeChannel  to open the second form. I  assign a value to  the RF_Selected variable in that second form  (which is a global variable) and then close the form. However before closing I call thebtnFindButton_Click(nothing, nothing) which puts me into the btnFindButton_Click again and I look to see if my variable state has changed (WirelessBase_RF_CH_Changed= True) If it changed then I try to write to the COM port  serialCOMDiscover.Write(" <#B" & RF_Selected) this is when it guives me the error.
Public Sub btnFindButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindButton2.Click 
For intloop = 0 To ActiveCOM.Count - 1
            Me.cboCOMPort.Items.Add(ActiveCOM(intloop))
            'set the properties of the com port
            serialCOMDiscover.PortName = "COM" & ActiveCOM(intloop)
            Selected_COM_Port = ActiveCOM(intloop)
            serialCOMDiscover.BaudRate = 9600
            Communication_Protocol_Defaults()
            serialCOMDiscover.Parity = Parity.None
            serialCOMDiscover.DataBits = 8
            serialCOMDiscover.DtrEnable = True
            If WirelessBase_RF_CH_Changed = False Then
                serialCOMDiscover.Open()
            Else
                serialCOMDiscover.Write(" <#B" & RF_Selected)
            End If
            serialCOMDiscover.Write("<W")
            System.Threading.Thread.Sleep(3000)
            serialCOMDiscover.Write("<RS")
            serialCOMDiscover.Write("<*")
            System.Threading.Thread.Sleep(1000)
            strDataCOM1 = serialCOMDiscover.ReadExisting
end sub


 Private Sub btnChangeChannel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChangeChannel.Click
        Dim frmChannelChange As New frmChannelUpdate
        frmChannelChange.Show()
    End Sub

Open in new window

0
 

Accepted Solution

by:
cmdolcet earned 0 total points
ID: 35198237
After I reviewed the code I noticed that my COM Port was always open and I need to close the COM Port connection before I could open the new one up. That's where the error came from.
0
 
LVL 5

Expert Comment

by:andr_gin
ID: 35198414
1.) Maybe the SerialPort does not like it, if you change the PortName and Write data directly afterwards ;-)

2.) What happens in the first run? Do you write data to the COM port in line 17 without opening it first?
0
 

Author Closing Comment

by:cmdolcet
ID: 35230031
after reviewing the code I noticed that I was not closing my COM port before opening up the same COM port. My mistake
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Data organization issue 7 56
How to set focus on a dynamic control 18 52
Subtract dates in vb.net 6 34
AD Computer Objects in VB .Net 2 17
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question