Reseting the com port when 8005 error

Posted on 2007-08-12
Last Modified: 2013-11-25
Hi, I am using the MSComm control and I receiving a 8005 error as if the port is open.  The situation is that I am trying to close the port just before trying to open it and then I received the 8012 as if the port is already close. If I comment the close script and run the code again it said that the port is open.  How the port is open if when I try to close it, it said is close?  If there a way to force close the port before try to open it?
It does not make sence that the port is open and also close at the same time.  I am not an expert programmer but...

Question by:waldemar_tavarez
    LVL 38

    Accepted Solution


    Port Mapper is a freeware tool which helps home users open/close ports in their routers and gateways securely. It automatically maps and manages ports in the router, enabling online multiplayer game play without disturbing the gaming session. Port Mapper is more secure than manually opening and closing ports, because it opens the ports only when needed and automatically closes them when you are finished playing. Port Mapper works with your Internet gateway/router in such a way that you can have control on the programs that communicate over your network. Using Port Mapper, you can expose applications to your friends over the internet in a safe manner
    LVL 65

    Assisted Solution

    Without seeing your code, I could only find VB6 code, but it uses this
        frmMain.MSComm1.CommPort = Count
        frmMain.MSComm1.PortOpen = True
        If Err.Number = 8005 Then
            'The port is already open
            'The port exists, so add it to the list.
            NumberOfPorts = NumberOfPorts + 1
            CommPorts(NumberOfPorts) = "COM" & CStr(Count)
        ElseIf frmMain.MSComm1.PortOpen = True Then
            'If the port opens, it exists.
            'Close it and add to the list.
            frmMain.MSComm1.PortOpen = False
            NumberOfPorts = NumberOfPorts + 1
            CommPorts(NumberOfPorts) = "COM" & CStr(Count)
        End If


    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    754 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

    22 Experts available now in Live!

    Get 1:1 Help Now