Solved

Access to COM Port denied

Posted on 2011-03-22
5
651 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
  • 3
5 Comments
 
LVL 32

Expert Comment

by:it_saige
Comment Utility
Could you perhaps provide some code to review?

-saige-
0
 

Author Comment

by:cmdolcet
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now