I want to detect modem outgoing port but my code fails to show me result?

458 views Asked by At

I want to get Modem outgoing port Through visual basic 6 Mscomm1. I am using Nokia c2 0i for my modem. Code connect with modem and send message also . My question is how can i get correct Modem outgoing port and show its name in message box. Please check my code for correction:

Private Sub Timer1_Timer()
Dim FromModem$
On Error Resume Next
For i% = 1 To 6
MSComm1.CommPort = i%
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
Label8.Caption = " PORT " & i%
pb1.Value = pb1.Value + 10
List2.AddItem i%
Text1.Text = "Searching Modem Port" & i%
MSComm1.Output = "AT" + Chr$(13)
Sleep 4000
If MSComm1.InBufferCount Then
FromModem$ = FromModem$ + MSComm1.Input
If InStr(FromModem$, "OK") Then
MsgBox "Modem has Found" & i%
Beep 400, 300
Timer1.Enabled = False
Exit For
End If
Else
MSComm1.PortOpen = False
End If
End If
DoEvents
Next i%
If i% > 6 Then
Timer1.Enabled = False
End If
End Sub
1

There are 1 answers

0
Jade On

try this example by using built-in serial port class Imports System Imports System.IO.Ports Module SerialPortExample

    Sub Main()
        Dim ports As String() = SerialPort.GetPortNames()
        Dim port As String 
        For Each port In ports

            'put your function here
        YourTestPort(port) 'Call the Open port function then Send AT(char(13))

        Next port

    End Sub 
End Module