Solved

Access to COM Port denied

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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