Solved

Access to COM Port denied

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

823 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