CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Comm Port

  1. #1
    Join Date
    Jan 2006
    Posts
    42

    Comm Port

    hii ,
    how to in VIsual Basic programming , what comm ports are available in the computer where application is working,
    i want to show in the combo box the available comm ports on the computer,
    and allow user to select the comm port.
    Very similar to how we select the comm port in Hyperterminal.
    yogi

  2. #2
    Join Date
    Jun 2005
    Location
    Orissa
    Posts
    150

    Re: Comm Port

    Hope, you can use the MSCom control to find the comports available on the machine.

    thanks

  3. #3
    Join Date
    Jun 2005
    Location
    Orissa
    Posts
    150

    Re: Comm Port

    Hi,
    Here is a sample code.....

    Code:
    Private Sub Combo1_Click()
    On Error GoTo ErrHandle
        MSComm1.CommPort = Combo1.Text
        MSComm1.Settings "9600,N,8,1" 'Where 9600 is the baud rate, N is the parity, 8 is the number of data bits, and 1 is the number of stop bits. The default value of value is: 9600,N,8,1
        MSComm1.PortOpen = True
        If MSComm1.PortOpen = False Then
            MsgBox "com port " & MSComm1.CommPort & " not Opened"
        End If
    Exit Sub
    ErrHandle:
        If Err.Number = 8002 Then
            MsgBox "Port number " & MSComm1.CommPort & " not available"
        End If
    End Sub
    
    Private Sub Form_Load()
        With Combo1
            .AddItem "1", 0
            .AddItem "2", 1
            .AddItem "3", 2
            .AddItem "4", 3
            .AddItem "5", 4
            .AddItem "6", 5
            .AddItem "7", 6
        End With
    End Sub
    Thanks

  4. #4
    Join Date
    Jan 2006
    Posts
    42

    Re: Comm Port

    hi,
    the idea is good but i dont want to list the ones which are not present , only which are present on the computer, so only to select them directly
    thanks ,
    yogi

  5. #5
    Join Date
    Jan 2006
    Posts
    42

    Re: Comm Port

    hii gurus,
    Please help i am in a deep fix, about this ,
    i have to design a combobox very similar to the Hyperterminal combobox where we select the available commport on the respective computer.
    pleasssssssssssee help
    yogi

  6. #6
    Join Date
    Jul 2005
    Location
    Plzeň, Czech Republic
    Posts
    94

    Re: Comm Port

    Code:
    On Error Resume Next
    For I = Min to Max
      MSComm1.Port = I
      MSComm1.Settings = "9600,N,8,1"
      MSComm1.PortOpen = True
      If MSComm1.PortOpen and Err.Number = 0 then
         Combo1.AddItem I, I - 1
      endif
      MSComm1.PortOpen = False
      Err.Number = 0
    Next I
    Have not tried, hope it works ;-)
    Last edited by jsiii; October 5th, 2006 at 03:18 AM.

  7. #7
    Join Date
    Jan 2006
    Posts
    42

    Thumbs up Re: Comm Port

    hii guys ,
    there is no direct method to get the available commports
    its a check and list basis to know the available ports
    here is the code
    Private Sub MDIForm_Load()
    Dim I As Integer
    On Error Resume Next
    With GPS
    If .PortOpen = True Then .PortOpen = False
    For I = 1 To 16
    .CommPort = I
    .PortOpen = True
    If err.Number = 0 Then
    PortSel.AddItem "Com " & Format$(I)
    .PortOpen = False
    Else
    err.Clear
    End If
    Next I
    End With
    End Sub

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured