Modified:
07/03/2007
Application ID: #5929
Option Explicit
Dim numDevices, strDevices, i, str, objComport
Set objComport = CreateObject( "ActiveXperts.Comport" )
Wscript.Echo "ActiveComport " & objComport.Version & " demo."
Wscript.Echo "Expiration date: " & objComport.ExpirationDate & vbCrLf
' Set Device property
numDevices = objComport.GetDeviceCount()
strDevices = "*** Enter one of the following device names *** " & vbCrLf & vbCrLf
For i = 0 To numDevices - 1
strDevices = strDevices & objComport.GetDevice( i )
strDevices = strDevices & vbCrLf
Next
strDevices = strDevices & "COM1" & vbCrLf & "COM2" & vbCrLf & "COM ..." & vbCrLf
Do
objComport.Device = InputBox( strDevices, "Input" )
Loop until objComport.Device <> ""
' Optionally override defaults
' objComport.BaudRate = 9600
' objComport.HardwareFlowControl = True
' objComport.SoftwareFlowControl = False
' Set Logging - for troubleshooting purposes
objComport.LogFile = "C:\ActiveComport.log"
' Open the port
objComport.Open
If( objComport.LastError <> 0 ) Then
Wscript.Echo "Open failed, Error #" & objComport.LastError & " : " & objComport.GetErrorDescription( objComport.LastError )
WScript.Echo "Ready."
WScript.Quit
End If
' Write command, and wait for the response
WriteStr objComport, "atz"
ReadStr objComport
' Write command, and wait for the response
WriteStr objComport, "ati"
ReadStr objComport
' Close the port
objComport.Close
Set objComport = Nothing
WScript.Echo "Ready."
' ********************************************************************
' Sub Routines
' ********************************************************************
Sub WriteStr( obj, str )
obj.WriteString str
WScript.Echo "-> " & str
End Sub
' ********************************************************************
Sub ReadStr( obj )
str = "notempty"
obj.Sleep 200
Do While str <> ""
str = obj.ReadString
If( str <> "" ) Then
WScript.Echo "<- " & str
End If
Loop
End Sub
License Information
Direct link: