我想检测调制解调器输出端口,但我的代码无法显示结果?

时间:2013-12-14 11:00:02

标签: detection modem

我想获得Modem传出端口通过visual basic 6 Mscomm1。我正在使用诺基亚c2 0i作为我的调制解调器。代码连接调制解调器并发送消息。我的问题是如何获得正确的调制解调器传出端口并在消息框中显示其名称。请检查我的代码以进行更正:

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 个答案:

答案 0 :(得分:1)

使用内置串口类尝试此示例     进口系统     Imports System.IO.Ports     模块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