Quicklinks
ActiveComport is a software development kit (SDK) that enables the user to communicate to a device over a serial interface.
Such a device can be: a weight indicator, a modem, a scanner, or any other device that is equiped with a serial port. It can even be another PC, connected via a NULL modem cable.
ActiveComport features the following:
Direct COM port support (like 'COM1'), TAPI (Windows Telephony Device) support (like 'Standard 56000 bps Modem'), support for RS-232/RS422/RS485, up to 256 simultaneous ports, support for all types of Hayes compatible modems, support for serial cable, USB cable or Bluetooth connections, support for GSM/GPRS modems, support for Virtual COM ports (i.e. COM ports redirected through the network), hardware flow control (RTS/CTS, DTR/DSR), software flowcontrol (XON/XOFF), configurable baudrate/parity/stopbits, full buffered data transfer, text/binary data transfer.
ActiveComport can be well integrated into VBScript environments.
This document describes how ActiveComport can be integrated into VBScript projects.
Download ActiveComport from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.
You're now able to write a more advanced script to communicate using the ActiveComport Toolkit.
Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:
Option Explicit
This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.
Now, declare the ActiveComport object:
Dim objComPort
Create the ActiveComport object like this:
Set objComPort = CreateObject( "ActiveXperts.ComPort" )
Now, add the following lines to the file to have your fist ActiveComport VBScript program:
WScript.Echo "Version: " & objComPort.Version WScript.Echo "Expiration Date: " & objComPort.Expiration Date
You can now send and/or receive data to an/or from a serial interface.
The following VBScript code shows how to query a modem:
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 <> "" 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, "at&f" 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 ' ********************************************************************
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/serial-port-component.