Adding serial communications capabilities to an application is never a simple matter.
It requires specialized knowledge that might be outside an individual programmer's expertise.
For years, VBScript, Visual Basic and Visual C++ developers have relied upon the power, flexibility and reliability of the
ActiveXperts Serial Port Component serial communications control from ActiveXperts Software. And today, also .NET developers use this control.
ActiveXperts Serial Port Component is a COM component, that provides an easy-to-use scripting interface for serial, asynchronous communications through a serial port. ActiveXperts Serial Port Component can control modems, ISDN modems, USB serial devices and other devices and machines that have a serial interface.
Use ActiveXperts Serial Port Component for different purposes:
ActiveXperts Serial Port Component features the following:
ActiveXperts Serial Port Component includes samples for many development tools, including:
ActiveXperts Serial Port Component is built on top of the Microsoft serial device drivers. It just uses these drivers. It neither replaces them, nor does it install any additional serial device drivers.
The core of ActiveXperts Serial Port Component is an ActiveX/COM component that comes in a 32-bit and a 64-bit version:
ActiveXperts Serial Port Component can be distributed easily to many PC's. Once you have purchased the licenses, you copy the AxSerial64.dll (and/or AxSerial32.dll) to the PCs and register the DLL on that PC.
ActiveXperts Serial Port Component can be used on any of the following operating systems:
To use ActiveXperts Serial Port Component in an ASP .NET, Visual Basic .NET or Visual C#. NET environment, the .NET Framework 2.0 or higher must be installed on the system. The .NET Framework is part of Windows 2003 server platforms and higher, and on Windows Vista workstation platforms and higher. For other Windows platforms, it's available as a separate installation. Please visit the Technology Information for the .NET Framework page to download the .NET Framework.
Internet Information Server (IIS) Setup installs the Visual Basic Script and Java Script engines.
To run ASP/ASP.NET pages on Windows Servers, IIS 6.x must be installed. IIS is an optional 'Role' in Windows Server platforms.
To run ASP .NET samples, .NET Framework 2.0 or higher must be installed.
The ActiveXperts Serial Port Component package consists of 3 modules; any combination of components can be installed:
To automatically install ActiveXperts Serial Port Component, download AxSerialSetup.exe and start the installation. The InstallShield wizard will guide you through the rest of the setup.
The installation will automatically register:
AxSerial64.dll, to support 64-bit applications;
and
AxSerial32.dll, to support 32-bit applications.
To manually install the ActiveXperts Serial Port Component core files, perform the following actions:
The following code snippets (VBScript) illustrate how to use ActiveXperts Serial Port Component.
Set objComport = CreateObject( "AxSerial.ComPort" ) ' Create new instance objComport.Device = "COM1" ' Use port directly (no Device Driver) objComport.BaudRate = 56000 ' Set baudrate (default:9600) objComport.HardwareFlowControl = asFLOWCONTROL_ENABLE ' Set Hardware Flow Ctrl (default:On) objComport.SoftwareFlowControl = asFLOWCONTROL_ENABLE ' Set Software Flow Ctrl (default:Off) objComport.Open ' Open the port Wscript.Echo "Open, result: " & objComport.LastError If( objComport.LastError <> 0 ) Then WScript.Quit End If objComport.WriteString( "at&f" ) ' Write command str = objComport.ReadString WScript.Echo "Received: [" & str & "]" ' Read the response objComport.Close ' Close the port
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Use Standard 9600 bps driver objComport.Open ' Open the port Wscript.Echo "Open, result: " & objComport.LastError If( objComport.LastError <> 0 ) Then WScript.Quit End If objComport.WriteString( "at&f" ) ' Write command str = objComport.ReadString WScript.Echo "Received: [" & str & "]" ' Read the response objComport.Close ' Close the port
Const RECIPIENT = "+31611223344" Const MESSAGE = "Hello, world!" Set objComport = CreateObject( "AxSerial.ComPort" ) ' Create new instance objComport.Device = "Nokia 6680 SmartPhone" ' Use the Standard 9600 bps driver objComport.LogFile = "C:\SerialPort.log" ' Enable logging objComport.Open ' Open the port Wscript.Echo "Open, result: " & objComport.LastError If( objComport.LastError <> 0 ) Then WScript.Quit End If WriteStr objComport, "at+cmgs=" & Chr( 34 ) & strNumber & Chr( 34 ) ReadStr objComport WriteStr objComport, strMessage strTermCmd = Chr( 26 ) ' Terminate: [ctrl]z and then [enter] WriteStr objComport, strTermCmd objComport.Sleep 3000 ' Takes a while before GSM phone responds ReadStr objComport ' +CMGS: expected ReadStr objComport ' OK expected objComport.Close ' Close the port ' ******************************************************************** ' 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 ' ********************************************************************
First, make sure the ActiveXperts Serial Port component (AxSerial64.dll, or AxSerial32.dll) is registered on the machine. In case you didn't use the installation program, be sure you used the REGSVR32.EXE program to register to component.
Then, add a reference to the ActiveXperts Serial Port component using the Visual Basic .NET Solution Explorer:
On top of the code, make this declaration:
Imports AxSerial
and declare and create an object like this:
Dim objComport As ComPort = New ComPort ' Declaration objComport = New ComPort ' Creation
After the declaration and creation of the object, you can use the object in your Visual Basic .NET code.
Visual Basic samples are part of the product installation.
They can also be found online: ftp.activexperts-labs.com/samples/serial-port-component.
First, make sure the ActiveXperts Serial Port component (AxSerial64.dll, or AxSerial32.dll) is registered on the machine. In case you didn't use the installation program, be sure you used the REGSVR32.EXE program to register to component.
Then, add a reference to the object using the Visual C# Solution Explorer:
On top of your code, make this declaration:
using AxSerial;
and declare and create an object like this:
ComPort objComport; // Declaration objComport = new ComPort(); // Creation
After the declaration and creation of the object, you can use the object in your Visual C# .NET code.
Visual C# .NET samples are part of the product installation.
They can also be found online: ftp.activexperts-labs.com/samples/serial-port-component.
ActiveXperts Serial Port Component can be used in Visual Basic 6.x or higher. In Visual Basic, go to the 'Project/References...' menu item and check the box next to ActiveXperts Serial Port Component Type Library. Now, you can declare and create ActiveXperts Serial Port Component objects.
Create a new ActiveXperts Serial Port Component object using the 'CreateObject' method:
Dim objComport As AxSerial.Comport ' Declaration Set objComport = CreateObject( "AxSerial.ComPort") ' Creation
After the declaration and creation of the object, you can use the object in your Visual Basic code.
Visual Basic samples are part of the product installation.
They can also be found online: ftp.activexperts-labs.com/samples/serial-port-component.
ActiveXperts Serial Port Component can be used in Visual C++ projects. To do so:
Create the various ActiveXperts Serial Port Component object instances like this:
#import "AxSerial.tlb" #include "AxSerialConstants.h" CoInitialize( NULL ); // Initialize COM AxSerial::IComPortPtr oComport = NULL; // Declaration oComport.CreateInstance(__uuidof(AxSerial::ComPort)); // Creation
After the declaration and creation of the object, you can use the object in your Visual C++ code.
Visual C++ samples are part of the product installation.
They can also be found online: ftp.activexperts-labs.com/samples/serial-port-component.
<html> <body> Version: <script language=vbscript runat=server> Set objComport = CreateObject( "AxSerial.ComPort" ) Response.Write objComport.Version </script> </body> </html>
ASP samples are part of the product installation.
They can also be found online: ftp.activexperts-labs.com/samples/serial-port-component.
Property | Type | Read/Write | Description |
Version | String | Out | Version number of ActiveXperts Serial Port Component |
Build | String | Out | Build number of ActiveXperts Serial Port Component |
LicenseStatus | String | Out | License Status |
LicenseKey | String | In/Out | License Key |
LastError | Number | In/Out | Result of the last called method |
Device | String | In/Out | Device name. Either a direct COM port or a Windows Telephony device name |
BaudRate | Number | In/Out | The baudrate of the communication session; default: 9600 bps |
Databits | Number | In/Out | The number of databits; default: 8 |
Stopbits | Number | In/Out | The number of stopbits; default: 1 |
Parity | Boolean | In/Out | Parity; default: False |
HardwareFlowControl | Number | In/Out | Use Hardware Flow Control |
DTRFlowControl | Boolean | In/Out | Use advanced Hardware Flow Control flag: Data Terminal Ready (default: True) |
RTSFlowControl | Boolean | In/Out | Use advanced Hardware Flow Control flag: Request To Send; default: True |
CTSFlowControl | Boolean | In/Out | Use advanced Hardware Flow Control flag: Clear To Send; default: False |
DSRFlowControl | Boolean | In/Out | Use advanced Hardware Flow Control flag: DSR (Data Set Ready); default: False |
SoftwareFlowControl | Number | In/Out | Use Software Flow Control |
ComTimeout | Number | In/Out | Timeout of ReadString, ReadByte and ReadBytes functions, in millisec; default: 1000 msecs |
IsOpened | Boolean | Out | True if port is opened, otherwise False |
PreCommandDelay | Number | In/Out | Pre command delay, in milliseconds. Only used with the WriteString method |
InterCharDelay | Number | In/Out | Delay between each character sent, in milliseconds. Only used with the WriteString method |
NewLine | String | In/Out | The character sequence that forms a newline |
LogFile | String | In/Out | All serial port commands, as well as data transfer, is logged to this file |
Version information of ActiveXperts Serial Port Component. This property is read-only; you cannot assign a value to it.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance
WScript.Echo "Version: " & objComport.Version
Build information of ActiveXperts Serial Port Component. This property is read-only; you cannot assign a value to it.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance
WScript.Echo "Version: " & objComport.Version
WScript.Echo "Build: " & objComport.Build
The status of your license. In case you have not licensed the product, the property holds the trial expiration date. For details, see Product Activation.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance
WScript.Echo "License Status: " & objComport.LicenseStatus
WScript.Echo "License Key: " & objComport.LicenseKey
A license key is required to unlock this component after the trial period has expired. Assign the LicenseKey property every time a new instance of this component is created (see code below). Alternatively, the LicenseKey property can be set automatically. This requires the license key to be stored in the registry. For details, see Product Activation.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.LicenseKey = "XXXXX-XXXXX-XXXXX" ' Assign your license key WScript.Echo "LicenseKey: " & objComport.LicenseKey
The result of a previous called method.
Use it to check the result of your last method call.
A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription method provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance ... objComport.Open ' Open the port WScript.Echo "LastError: " & objSnmp.LastError ' Display the result ...
Description:
Device driver to use.
You can either use a Windows telephony device (recommended) or a physical COM port (directly).
Assign one of the following strings to the 'Device' property:
Windows telephony devices are highly recommended.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 19200 bps Modem" ' Use a Windows telephony device ...
Description:
Baud rate at which the communications device operates. The default
value is 0, which means that the baud rate setting is inherited from
the Port/Device settings in the Control Panel of Windows.
You should use the UpdateCom method if you want to
change the baudrate and the port is already opened.
This property can be one of the following values:
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.BaudRate = 38400 ' Use 38400 bps objComport.Open ...
Description:
Number of databits in a byte. The default value is asDATABITS_DEFAULT, which means that the data bits setting is inherited from the Port/Device settings in the Control Panel of Windows. You cannot change the value when the port is already opened.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.DataBits = objComport.asDATABITS_7 ' Use 7 bit data bits objComport.Open ...
Description:
You can configure StopBits to be asSTOPBITS_DEFAULT, asSTOPBITS_1, asSTOPBITS_2 or asSTOPBITS_15.
If StopBits is asSTOPBITS_1, one stop bit is used to indicate the end of data transmission.
If StopBits is asSTOPBITS_2, two stop bits are used to indicate the end of data transmission.
If StopBits is asSTOPBITS_15, the stop bit is transferred for 150% of the normal time used to transfer one bit.
The default value is asSTOPBITS_DEFAULT, which means that the stop bits setting is inherited from the Port/Device settings in the Control Panel of Windows.
You cannot change the value when the port is already opened.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.StopBits = objComport.asSTOPBITS_15 ' Use 1.5 stop bits objComport.Open ...
Description:
Parity checking can detect errors of one bit only. An error in two bits might cause the data to have a seemingly valid parity, when in fact it is incorrect.
You can configure Parity to be none, odd, even, mark, or space.
If Parity is asPARITY_DEFAULT, the parity setting is inherited from the Port/Device settings in the Control Panel of Windows.
If Parity is asPARITY_NONE (=none), parity checking is not performed and the parity bit is not transmitted.
If Parity is asPARITY_ODD (=odd), the number of mark bits (1's) in the data is counted, and the
parity bit is asserted or unasserted to obtain an odd number of mark
bits.
If Parity is asPARITY_EVEN (=even), the number of mark bits in the data is counted, and the parity
bit is asserted or unasserted to obtain an even number of mark bits.
If Parity is asPARITY_MARK (=mark), the parity bit is asserted.
If Parity is asPARITY_SPACE (=space), the parity bit is unasserted.
The default value is asPARITY_DEFAULT.
You cannot change the value when the port is already opened.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.Parity = objComport.asPARITY_NONE ' No parity objComport.Open ...
Use Hardware Flow Control. The default value is asFLOWCONTROL_DEFAULT, which means that the hardware flow control settings are inherited from the Port/Device settings in the Control Panel of Windows.
This property sets the generic hardware flow control control properties.
When you set 'HardwareFlowControl' to asFLOWCONTROL_ENABLE:
When you set 'HardwareFlowControl' to asFLOWCONTROL_DISABLE:
In most circumstances, it is not necessary to assign DTRFlowControl,
RTSFlowControl,
CTSFlowControl or DSRFlowControl individually.
However, in some situations you want need to assign these properties individually.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.HardwareFlowControl = objComport.asFLOWCONTROL_DISABLE ' No hardware flow control objComport.Open ...
Advanced Hardware Flow Control. Usually, the HardwareFlowControl property will suffice:
it sets all four advanced hardware flow control flags (
DTRFlowControl,
RTSFlowControl,
CTSFlowControl,
DSRFlowControl).
The default value is asFLOWCONTROL_DEFAULT, which means that the DTR flow control settings are inherited from
the Port/Device settings in the Control Panel of Windows.
You cannot change the value when the port is already opened.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.DTRFlowControl = objComport.asFLOWCONTROL_DISABLE ' No DTR hardware flow control objComport.Open ...
Description:
Advanced Hardware Flow Control. Usually, the HardwareFlowControl property will suffice:
it sets all four advanced hardware flow control flags (
DTRFlowControl,
RTSFlowControl,
CTSFlowControl,
DSRFlowControl).
The default value is asFLOWCONTROL_DEFAULT, which means that the RTS flow control settings are inherited from the Port/Device settings in the Control Panel of Windows.
You cannot change the value when the port is already opened.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.RTSFlowControl = objComport.asFLOWCONTROL_DISABLE ' No RTS objComport.Open ...
Description:
Advanced Hardware Flow Control. Usually, the HardwareFlowControl property will suffice:
it sets all four advanced hardware flow control flags (
DTRFlowControl,
RTSFlowControl,
CTSFlowControl,
DSRFlowControl).
The default value is asFLOWCONTROL_DEFAULT, which means that the CTS flow control settings are inherited from the Port/Device settings in the Control Panel of Windows.
You cannot change the value when the port is already opened.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.CTSFlowControl = objComport.asFLOWCONTROL_DISABLE ' No CTS hardware flow control objComport.Open ...
Description:
Advanced Hardware Flow Control. Usually, the HardwareFlowControl property will suffice:
it sets all four advanced hardware flow control flags (
DTRFlowControl,
RTSFlowControl,
CTSFlowControl,
DSRFlowControl).
The default value is asFLOWCONTROL_DEFAULT, which means that the DSR flow control settings are inherited from the Port/Device settings in the Control Panel of Windows.
You cannot change the value when the port is already opened.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.DSRFlowControl = objComport.asFLOWCONTROL_DISABLE ' No DSR hardware flow control objComport.Open ...
Description:
Software flow control. You should use the UpdateCom method if you want to change the baudrate after you have opened the port.
The default value is asFLOWCONTROL_DEFAULT,
which means that the software flow control settings are inherited from
the Port/Device settings in the Control Panel of Windows.
The other valid values are: asFLOWCONTROL_DISABLE and asFLOWCONTROL_ENABLE.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM2" ' Set device to COM2 objComport.SoftwareFlowControl = objComport.asFLOWCONTROL_ENABLE ' Use software flow control objComport.Open ...
Description:
Timeout of ReadString method, in milliseconds. You can call this method anytime you want.
The default value is 1000.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600bps Modem" ' Set device to Standard 9600 bps Modem str = objComport.ReadString ' Blocks until string read or 1s elapsed WScript.Echo str objComport.ComTimeout = 5000 ' Set timeout to 5000 msecs str = objComport.ReadString ' Blocks until string read or 5s elapsed WScript.Echo str objComport.Close ' Close port ...
Description:
True if port is opened, otherwise False.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem If( objComport.IsOpened ) Then WScript.Echo "Port is opened" objComport.Close ' Close port End If
Description:
Specifies a delay (in milliseconds) used before WriteString actually starts writing the command string.
This property was introduced to support slow devices that do not accept a few commands right after eachother.
These devices need a small delay between commands, which can be accomplished by setting this 'PreCommandDelay' property.
Note that the property does NOT apply to the WriteBytes and WriteByte functions.
Default value: 0, indicating no delay between commands.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If( objComport.LastError = 0 ) Then objComport.PreCommandDelay = 500 ' WriteString will use delay of 500ms ' before the command string is sent objComport.InterCharDelay = 10 ' delay of 10 ms between each character ' Transmitted by WriteString method ... objComport.WriteString "AT&F" ... objComport.Close ' Close the port End If
Description:
Specifies a delay (in milliseconds) used in WriteString between each character transmitted. This property was introduced to
support slow devices that do not allow each character tranmitted right
after eachother in command mode. These devices need a small delay
between characters, which can be accomplished by setting this
'InterCharDelay' property.
Note that the property does NOT apply to the WriteBytes method.
Default value: 0, indicating no delay between characters.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If( objComport.LastError = 0 ) Then objComport.PreCommandDelay = 500 ' WriteString will use delay of 500ms ' before the command string is sent ... objComport.InterCharDelay = 10 ' Delay of 10 ms between each character ' transmitted by WriteString method objComport.WriteString "AT&F" ... objComport.Close ' Close the port End If
Description:
The character sequence that forms a newline. Default value: the CR (carriage return) string. Most frequent used newline strings:
A newline is used internally by two functions:
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If( objComport.LastError = 0 ) Then objComport.NewLine = vbCrLf ' Use CRLF in subsequent Read/WriteBytes calls ' transmitted by WriteString method objComport.WriteString "AT&F" ' AT&F is sent, followed by a CRLF ... objComport.Close ' Close the port End If
Description:
By default, LogFile holds the empty string and nothing is logged. If you assign a valid file name to it, all device commands and responses will be written to this log file.
Output is always appended.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.LogFile = "C:\MyLogFile.txt" ' All operations are logged here objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Open the port ...
Method | Description |
Clear | Reset all properties to the default values |
GetDeviceCount | Return the number of Windows telephony devices installed on the local computer |
GetDevice | Retrieve a Windows telephony device name |
Open | Open a comport |
Close | Close a comport |
ClearTX | Clears the output buffer |
ClearRX | Clears the input buffer |
ReadString | Read an ASCII string from the comport |
ReadByte | Read a (binary) byte from the comport |
ReadBytes | Read a stream of (binary) bytes from the comport |
WriteString | Write an ASCII string to the comport |
WriteByte | Write a (binary) byte to the comport |
WriteBytes | Write a stream of (binary) bytes to the comport |
UpdateCom | Update the comport with new configuration settings |
RaiseRTS | Raise the RTS signal |
RaiseDTR | Raise the DTR signal |
QueryCTS | Query the CTS signal |
QueryDSR | Query the DSR signal |
QueryDCD | Query the DCD signal |
QueryRI | Query the RI signal |
Sleep | Be idle for some time |
GetErrorDescription | Get error description |
SaveLicenseKey | Save the License Key in the registry |
Description:
Reset all properties to their initial values.
Parameters:
None.
Always 0.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ... objComport.Close objComport.Clear ' Clear all properties objComport.Device = "COM1" ' Set device to COM1: objComport.Open ...
Description:
Returns the number of installed Windows telephony devices on the local computer.
Parameters:
The number of installed Windows telephony devices. Check the LastError property to see if the method was completed successfully.
NOTE: The number of Windows telephony devices does not include the number installed COM ports.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance
WScript.Echo "Number of installed Windows telephony devices: " & objComport.GetDeviceCount()
Description:
Returns the n-th telephony device of the system. The number n can be between 0 and GetDeviceCount()-1.
Parameters:
The name of the device. Call the LastError method to see if the method was completed successfully.
The name of the device can be assigned to the Device property to open a Windows telephony device.
Example:
Set objComport= CreateObject("AxSerial.ComPort") ' Create new instance
n = objComport.GetDeviceCount()
For i = 0 to n-1
WScript.Echo "Device " & i & ": " & objComport.GetDevice( i )
Next
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance If( objComport.GetDeviceCount() > 0 ) objComport.Device = objComport.GetDevice( 0 ) ' Use the first telephony device objComport.WriteByte 32 End If
Description:
Open the comport. The Device indicates to port to open.
Parameters:
None.
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port ...
Description:
Close the COM port.
Parameters:
None.
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If( objComport.LastError = 0 ) Then ... objComport.Close ' Close the port End If
Description:
Clears the output buffer (if the device or UART has one).
Parameters:
None.
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to COM2 objComport.Open ' Now open the Standard 9600 bps Modem If( objComport.LastError = 0 ) Then ... objComport.ClearTX ' Clear transmission queue objComport.WriteString "AT&F" ... objComport.Close ' Close the port End If
Description:
Clears the input buffer (if the device or UART has one).
Parameters:
None.
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If( objComport.LastError = 0 ) Then ... objComport.ClearTX ' Clear transmission queue objComport.ClearRX ' Clear transmission queue ... objComport.WriteString "AT&F" WScript.Echo objComport.ReadString ' Read incoming data ... objComport.Close ' Close the port End If
Description:
This method reads a string of data from the device.
The method returns when either a string, terminated by a NewLine, is read from the device,
or when the time specified by ComTimeout has elapsed.
In case of a timeout, the empty string will be returned and LastError will indicate a time-out.
Parameters:
None.
The string that was read from the device.
Check LastError property to see if the method was completed successfully.
In case of a timeout, the empty string is returned, and LastError will indicate a time-out.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then objComport.ComTimeout = 2000 str = objComport.ReadString ' Method will timeout after 2000 msec WScript.Echo "String read: " & str ... objComport.Close End If
Description:
Send a stream of binary data to the device.
Parameters:
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If( objComport.LastError = 0 ) Then ... data = Chr( 1 ) & Chr( 2 ) & Chr( 253 ) & Chr( 254 ) & Chr( 255 ) objComport.WriteBytes data ' Write stream of data ... objComport.Close ' Close the port End If
Description:
This method sends a (binary) byte to the device.
Parameters:
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If( objComport.LastError = 0 ) Then ... objComport.WriteByte 97 ' [A] objComport.WriteByte 116 ' [T] objComport.WriteByte 122 ' [Z] objComport.WriteByte 13 ' [<CR>]; ATZ issued. ... objComport.Close ' Close the port End If
Description:
This method sends a string of ASCII data to the device. Finally NewLine is sent to the device.
Parameters:
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If( objComport.LastError = 0 ) Then ... objComport.WriteString "AT&F" ... objComport.Close ' Close the port End If
Description:
This method reads one byte of data from the device.
The method returns when either a byte is read from the device,
or when the time specified by ComTimeout has elapsed.
In case of a timeout, LastError will indicate a time-out.
Parameters:
None.
The byte that was read from the device.
Check LastError property to see if the method was completed successfully.
In case of a timeout, the LastError will be set to indicate a timeout.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to COM2 objComport.Open ' Now open the port If objComport.LastError = 0 Then objComport.ComTimeout = 2000 .. bt = objComport.ReadByte If( objComport.LastError = 0 ) Then ' Method will timeout after 2000 msec WScript.Echo "Byte read: " & bt End If ... objComport.Close End If
Description:
This method reads a stream of binary data from the device.
The method returns when when the time specified by ComTimeout has elapsed.
Parameters:
None.
The method returns when when the time specified by ComTimeout has elapsed.
If data was read from the port, 0 will be returned;
in case of a timeout without data being read from the port, the LastError property will indicate a timeout.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then objComport.ComTimeout = 2000 ... btData = objComport.ReadBytes ' Read stream of binary data If( objComport.LastError = 0 ) Then ' Method will timeout after 2000 msec WScript.Echo "Number of bytes read: " & Len( btData ) End If ... objComport.Close End If
Description:
If a COM port is already opened and you changed the baudrate or Software Flow Control, you must this method to let the changes take effect. of the comport.
Parameters:
None.
The method returns when when the time specified by ComTimeout has elapsed.
If data was read from the port, 0 will be returned;
in case of a timeout without data being read from the port, the LastError property will indicate a timeout.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then objComport.BaudRate = 57600 ' Use different baudrate objComport.SoftwareFlowControl = asFLOWCONTROL_ENABLE ' Use software flow control objComport.UpdateCom ' Update COM port ... objComport.Close End If
Description:
Raise (or lower) the RTS (Request-To-Send) signal. Raising this signal has nothing to do with the HardwareFlowControl property: 'RaiseRTS' just raises (or lowers) the RTS signal, regardless of the hardware flow control used.
Parameters:
Boolean: True to raise the signal, or False to lower the signal.
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then objComport.RaiseRTS( True ) ' Raise RTS ... objComport.RaiseRTS( False ) ' Lower RTS ... objComport.Close End If
Description:
Raise (or lower) the DTR (Data-Terminal-Ready) signal. Raising this signal has nothing to do with the HardwareFlowControl property: 'RaiseDTR' just raises (or lowers) the DTR signal, regardless of the hardware flow control used.
Parameters:
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then objComport.RaiseDTR( True ) ' Raise DTR ... objComport.RaiseDTR( False ) ' Lower DTR ... objComport.Close End If
Description:
Query the actual value of the CTS (Clear-To-Send) signal.
Parameters:
None.
True if CTS is raised, otherwise: False
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then ... bVal = objComport.QueryCTS() ' Query CTS signal WScript.Echo "CTS: " & bVal ... objComport.Close End If
Description:
Query the actual value of the DSR (Data-Set-Ready) signal.
Parameters:
None.
True if DSR is raised, otherwise: False
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then ... bVal = objComport.QueryDSR() ' Query DSR signal WScript.Echo "DSR: " & bVal ... objComport.Close End If
Description:
Query the actual value of the DCD (Data-Carrier-Detect) signal.
Parameters:
None.
True if DCD is raised, otherwise: False
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then ... bVal = objComport.QueryDCD() ' Query DCD signal WScript.Echo "DCD: " & bVal ... objComport.Close End If
Description:
Query the actual value of the RI (Ring-Indicator) signal.
Parameters:
None.
True if RI is raised, otherwise: False
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then ... bVal = objComport.QueryRI() ' Query RI signal WScript.Echo "RI: " & bVal ... objComport.Close End If
Description:
This method can be used in your script anywhere you want; it will suspend the program. One paramter is required: the number of milliseconds you want to suspend.
Parameters:
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "Standard 9600 bps Modem" ' Set device to Standard 9600 bps Modem objComport.Open ' Now open the port If objComport.LastError = 0 Then objComport.WriteString( "AT&F" ) ' Suspend for 1000 msecs, then resume objComport.Sleep( 1000 ) WScript.Echo objComport.ReadString objComport.Close End If
Description:
GetErrorDescription provides the error description of a given error code.
Parameters:
The error description that is associated with the given error code.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.Device = "COM9" ' Set device to COM9 ... WScript.Echo "LastError: " & objComport.LastError WScript.Echo "Error description: " & objComport.GetErrorDescription( objComport.LastError ) ...
Description:
Use SaveLicenseKey to store the license key permanently in the registry. When a license key is saved, it is restored automatically every time a new instance of the object ('ComPort') is created. It is not recommended to save the license key if you distribute the component with your own software, because the key can be easily used by others.
Parameters:
Always 0. Check LastError property to see if the method was completed successfully.
Example:
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.LicenseKey = "XXXXX-XXXXX-XXXXX" objComport.SaveLicenseKey ' Save license key to registry
For more information, see Product Activation.
Constant | Value | Description |
asFLOWCONTROL_DEFAULT | 0 | Flow Control setting is inherited from the Port/Device settings in the Control Panel of Windows. |
asFLOWCONTROL_DISABLE | 1 | Disable Flow Control |
asFLOWCONTROL_ENABLE | 2 | Enable Flow Control |
Constant | Value | Description |
asDATABITS_DEFAULT | 0 | Stop bits setting is inherited from the Port/Device settings in the Control Panel of Windows. |
asDATABITS_7 | 7 | 7 data bits |
asSTOPBITS_8 | 8 | 8 data bits |
Constant | Value | Description |
asSTOPBITS_DEFAULT | 0 | Stop bits setting is inherited from the Port/Device settings in the Control Panel of Windows. |
asSTOPBITS_1 | 1 | 1 bit stop bit (default) |
asSTOPBITS_2 | 2 | 2 bit stop bit |
asSTOPBITS_15 | 15 | 1.5 bit parity |
Constant | Value | Description |
asPARITY_DEFAULT | 0 | No parity bits |
asPARITY_NONE | 1 | No parity bits |
asPARITY_ODD | 2 | Odd parity |
asPARITY_EVEN | 3 | Even parity bits |
asPARITY_MARK | 4 | Mark parity |
asPARITY_SPACE | 5 | Space parity |
When a method is called, the result of the method is stored in the object's LastError property. When LastError is 0, it means that the last called method completed successfully; otherwise, an error occured.
The value of the LastError tells you why the method failed. All error codes are listed on the ActiveXperts web site:
www.activexperts.com/support/errorcodes (list of error codes).
Here, you can also lookup a specific error to find its description.
You can also call the GetErrorDescription method to find the error description.
Samples for Visual Basic, Visual Basic .NET, Visual C++, Visual C# .NET, ASP and VBScript are included as part of the installation. You can also find the samples on our website at ftp.activexperts-labs.com/samples/serial-port-component.
Visit our website for a complete list of FAQ's at: https://www.activexperts.com/support
Please contact our website for support questions about this product, or send an email to our support-staff:
Website: https://www.activexperts.com/support
E-mail: support@activexperts.com
Please visit www.activexperts.com/order to buy the product. Here, you can also find the latest prices.
You can also contact us via email: sales@activexperts.com
After purchasing the product, you will receive one or more product registration keys.
After purchasing the product, you will receive a license key.
There are four ways to activate (unlock) the component using this license key:
1. Directly from your program code
You can unlock the component by using the LicenseKey property. This way, the license is NOT stored in the registry of the computer. This is the recommended way when distributing this component with your own software.
2. Store the license key in the registry - Installation
When the license key is entered during Setup (AxSerialSetup.exe, available from the ActiveXperts download site),
the license key will be saved in the following registry key:
'HKEY_LOCAL_MACHINE\Software\ActiveXperts\Serial Port Component\LicenseKey'
Once the license key is stored in the registry, the LicenseKey property will be assigned automatically with that value each time the object is instantiated.
3. Store the license key in the registry - Manually
You can enter the license key manually (e.g. through REGEDIT.EXE) in following registry key:
'HKEY_LOCAL_MACHINE\Software\ActiveXperts\Serial Port Component\LicenseKey'
Once the license key is stored in the registry, the LicenseKey property will be assigned automatically with that value each time the object is instantiated.
4. Store the license key in the registry - SaveLicenseKey method
You can enter the license key by calling the SaveLicenseKey method. You need to call SaveLicenseKey only once.
Set objComport = CreateObject("AxSerial.ComPort") ' Create new instance objComport.LicenseKey = "XXXXX-XXXXX-XXXXX" ' Replace XXXXX-XXXXX-XXXXX by your own key objComport.SaveLicenseKey
Once the license key is stored in the registry, the LicenseKey property will be assigned automatically with that value each time the object is instantiated.
For information about how to use the registration code with a Distribution License, please read the following document: How to distribute an ActiveXperts Component.
PLEASE READ THIS SOFTWARE LICENSE AGREEMENT CAREFULLY BEFORE DOWNLOADING OR USING THE SOFTWARE. BY CLICKING ON THE "ACCEPT" BUTTON, OPENING THE PACKAGE, DOWNLOADING THE PRODUCT, OR USING THE EQUIPMENT THAT CONTAINS THIS PRODUCT, YOU ARE CONSENTING TO BE BOUND BY THIS AGREEMENT. IF YOU DO NOT AGREE TO ALL OF THE TERMS OF THIS AGREEMENT, CLICK THE "DO NOT ACCEPT" BUTTON AND THE INSTALLATION PROCESS WILL NOT CONTINUE, RETURN THE PRODUCT TO THE PLACE OF PURCHASE FOR A FULL REFUND, OR DO NOT DOWNLOAD THE PRODUCT. GENERAL In this Software License Agreement: (i) "ActiveXperts" means ActiveXperts Software B.V. (ii) "Customer" means the individual(s), organization or business entity buying a license of the Software from ActiveXperts or its Distributors or its Resellers. (iii) "Software" means computer programs (and their storage medium) supplied by ActiveXperts and known collectively as "ActiveXperts Serial Port Component" in which ActiveXperts has property rights and any user manuals, operating instructions, brochures and all other documentation relating to the said computer programs (the expression "Software" to include all or any part or any combination of Software). 1. LICENSE GRANT ActiveXperts grants Customer the following rights provided that you comply with all terms and conditions of this License Agreement: (a) Installation and use. Customer may install, use, access, display and run one copy of the Software on a single computer, such as a workstation, terminal or other device ("Workstation Computer"). A "License Pack" allows you to install, use, access, display and run additional copies of the Software up to the number of "Licensed Copies" specified above. (b) Reservation of Rights. ActiveXperts reserves all rights not expressly granted to you in this License Agreement. 2. UPGRADES AND SUPPLEMENTS To use a product identified as an upgrade, you must first be licensed for the Software as eligible for the upgrade. After upgrading, Customer may no longer use the product that formed the basis for Customer's upgrade eligibility. This License Agreement applies to updates or supplements to the original Software provided by ActiveXperts, unless we provide other terms along with the update or supplement. 3. LIMITATION ON REVERSE ENGINEERING,DECOMPILATION, AND DISASSEMBLY Customer may not reverse engineer, decompile, or disassemble the Software, except and only to the extent that it is expressly permitted by applicable law notwithstanding this limitation. 4. TERMINATION Without prejudice to any other rights, ActiveXperts may cancel this License Agreement if Customer does not abide by the terms and conditions of this License Agreement, in which case you must destroy all copies of the Software and all of its component parts. 5. NOT FOR RESALE SOFTWARE Software identified as "Not for Resale" or "NFR," may not be resold, transferred or used for any purpose other than demonstration, test or evaluation. 6. LIMITED WARRANTY ActiveXperts warrants that for a period of ninety (90) days from the date of shipment from ActiveXperts: (i) the media on which the Software is furnished will be free of defects in materials and workmanship under normal use; and (ii) the Software substantially conforms to its published specifications. Except for the foregoing, the Software is provided AS IS. This limited warranty extends only to Customer as the original licensee. Customer's exclusive remedy and the entire liability of ActiveXperts and its suppliers under this limited warranty will be, at ActiveXperts or its service center's option, repair, replacement, or refund of the Software if reported (or, upon request, returned) to the party supplying the Software to Customer. In no event does ActiveXperts warrant that the Software is error free or that Customer will be able to operate the Software without problems or interruptions. This warranty does not apply if the software (a) has been altered, except by ActiveXperts, (b) has not been installed, operated, repaired, or maintained in accordance with instructions supplied by ActiveXperts, (c) has been subjected to abnormal physical or electrical stress, misuse, negligence, or accident, or (d) is used in ultrahazardous activities. 7. LIMITATION OF LIABILITY AND REMEDIES. Notwithstanding any damages that you might incur for any reason whatsoever (including, without limitation, all damages referenced above and all direct or general damages), the entire liability of ActiveXperts and any of its suppliers under any provision of this License Agreement and your exclusive remedy for all of the foregoing (except for any remedy of repair or replacement elected by ActiveXperts with respect to any breach of the Limited Warranty) shall be limited to the greater of the amount actually paid by you for the Software or U.S.$5.00. The foregoing limitations, exclusions and disclaimers (including Sections 4, 5 and 6 above) shall apply to the maximum extent permitted by applicable law, even if any remedy fails its essential purpose. 8. ENTIRE AGREEMENT This License Agreement (including any addendum or amendment to this License Agreements which is included with the Software) are the entire agreement between you and ActiveXperts relating to the Software and the support services (if any) and they supersede all prior or contemporaneous oral or written communications, proposals and representations with respect to the Software or any other subject matter covered by this License Agreement. To the extent the terms of any ActiveXperts policies or programs for support services conflict with the terms of this License Agreement, the terms of this License Agreement shall control. This Agreement shall be construed in accordance with the laws of The Netherlands and the Dutch courts shall have sole jurisdiction in any dispute relating to these conditions. If any part of these conditions shall be or become invalid or unenforceable in any way and to any extent by any existing or future rule of law, order, statute or regulation applicable thereto, then the same shall to the extent of such invalidity or enforceability be deemed to have been deleted from the conditions which shall remain in full force and effect as regards all other provisions. 9. Copyright The Software is protected by copyright and other intellectual property laws and treaties. ActiveXperts or its suppliers own the title, copyright, and other intellectual property rights in the Software. The Software is licensed, not sold.