Solved

Access to COM Port denied

Posted on 2011-03-22
5
662 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 33

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SqlServer no dupes 25 38
"Emulate" TAB key when press Enter Key 3 49
MYSQL responding very slow 3 28
VB.NET Application Installation with sqlserver 8 32
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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