dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    37

    Error 8002: Invalid port number

    Hi Guys,

    I get 'Error 8002: Invalid port number' error when trying to use MSCOMM. When i debugged, the CommPort property is set to '1' which is a common port number. When i press F5, the program continues itrs execution as normal.
    Please explain me this illogical behaviour.

    Regards,
    Swapna

  2. #2
    Join Date
    Jun 2002
    Location
    Bangalore
    Posts
    42

    Re: Error 8002: Invalid port number

    The comm port 1 may not be present in the system.
    Right click on My computer - > Properties - > Hardware ->Device Manager to check the available com ports in your system.
    Benny C A
    Al Ain, UAE

  3. #3
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    37

    Re: Error 8002: Invalid port number

    Hi Bnnyca,

    My program detects the COM ports available on the PC and tries to communicate to the port which is ready for communication. If I was clear in my first post, I had mentioned that, when I press F5 (continuing the executon), the application runs as normal.

    Regards,
    Swapna

  4. #4
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Error 8002: Invalid port number

    Post the Code that causes this error, so that we can see what could be causing the problem...

    Gremmy
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  5. #5
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    37

    Re: Error 8002: Invalid port number

    Call GetInstalledCOMPorts(port_array)
    For i = 0 To UBound(port_array) - 1
    If Me.DSPComm.PortOpen = True Then
    Me.DSPComm.PortOpen = False
    End If
    Me.DSPComm.Settings = "9600,n,8,1"
    Me.DSPComm.RThreshold = 1
    Me.DSPComm.CommPort = Val(Mid$(port_array(i), 4, Len(port_array(i)) -3))
    Me.DSPComm.PortOpen = True
    Me.DSPComm.InBufferCount = 0
    Me.DSPComm.Output = Chr$("&H" & "41")

    data_received = Initial_Receive_Data
    If Hex$(Asc(data_received)) = "41" Then
    serial_port = Val(Mid$(port_array(i), 4, Len(port_array(i)) - 3))
    exit_flag = True
    Exit For
    ElseIf data_received = "Not Responding" Then
    End If
    Next

    '-------------------------------------------------------------------------------------------
    Me.DSPComm.PortOpen = True
    The debugger shows error at this line.

  6. #6
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Error 8002: Invalid port number

    Okay a few things that i did notice...

    Code:
    Me.DSPComm.CommPort = Val(Mid$(port_array(i), 4, Len(port_array(i)) -3))
    Your commport should be set before you adjust any of the port settings.
    Quote Originally Posted by VB Books Online
    Once you’ve specified which port to open and how data communication is to be handled, you use the PortOpen property to establish the connection. It is a Boolean value, True or False. If, however, the port is not functional, if the CommPort property is set incorrectly, or if the device does not support the settings you’ve specified, an error will be generated or the external device may not work correctly.
    The first bit of code you've got won't realy do much.. the MScomm control will not be able to check if the port is open by another Application and close it..
    Quote Originally Posted by VB Books Online
    Each MSComm control you use corresponds to one serial port. If you need to access more than one serial port in your application, you must use more than one MSComm control.
    Hope this helps...

    Gremmy...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  7. #7
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    37

    Re: Error 8002: Invalid port number

    Call GetInstalledCOMPorts(port_array)
    For i = 0 To UBound(port_array) - 1
    Me.DSPComm.CommPort = Val(Mid$(port_array(i), 4, Len(port_array(i)) - 3))
    'If Me.DSPComm.PortOpen = True Then
    'Me.DSPComm.PortOpen = False
    'End If
    Me.DSPComm.Settings = "9600,n,8,1"
    Me.DSPComm.RThreshold = 1
    Me.DSPComm.PortOpen = True
    Me.DSPComm.InBufferCount = 0
    Me.DSPComm.Output = Chr$("&H" & "41")
    data_received = Initial_Receive_Data
    If Hex$(Asc(data_received)) = "41" Then
    serial_port = Val(Mid$(port_array(i), 4, Len(port_array(i)) - 3))
    exit_flag = True
    Exit For
    ElseIf data_received = "Not Responding" Then
    End If
    Next

    '-----------------------------------------------------------------------------------------------
    I have changed accordingly. The error persists.
    This application was working fine until today morning. I have not changed any part of the code and suddenly, this error is generated. As i told u earlier, when i click the debug button on the error window, the line it shows is ' Me.DSPComm.PortOpen = True '. And when i click either F5 or F8, the execution proceeds further successfully. This is the strange thing i have noticed.

  8. #8
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Error 8002: Invalid port number

    Has there been any other serial device added to the PC recently, or other software that may be using a serial port ??

    These may be causing a conflict on the port.

    Also Dubble check your Bios settings on the com ports.. Sometimes a comport will show in windows but in bios it is disabled...

    Gremmy..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  9. #9
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    37

    Re: Error 8002: Invalid port number

    Hi Gremmy,
    Morning i had installed a software that would share a single COM port between many a applications by creating virtual ports. Thats causing the problem.. .. I have uninstalled it and it works fine now..
    Thank u so much for ya hint..

    Regards,
    swapna

  10. #10
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Error 8002: Invalid port number

    Hey Swapnaoe..

    not a prob.. Glad to have helped.

    Gremmy...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.