The following table lists the trappable errors for the MSComm control.
Constant | Value | Description |
comInvalidPropertyValue | 380 | Invalid property value |
comSetNotSupported | 383 | Property is read-only |
comGetNotSupported | 394 | Property is read-only |
comPortOpen | 8000 | Operation not valid while the port is opened |
8001 | Timeout value must be greater than zero | |
comPortInvalid | 8002 | Invalid Port Number |
8003 | Property available only at run time | |
8004 | Property is read only at runtime | |
comPortAlreadyOpen | 8005 | Port already open |
8006 | The device identifier is invalid or unsupported | |
8007 | The device's baud rate is unsupported | |
8008 | The specified byte size is invalid | |
8009 | The default parameters are in error | |
8010 | The hardware is not available (locked by another device) | |
8011 | The function cannot allocate the queues | |
comNoOpen | 8012 | The device is not open |
8013 | The device is already open | |
8014 | Could not enable comm notification | |
comSetCommStateFailed | 8015 | Could not set comm state |
8016 | Could not set comm event mask | |
comPortNotOpen | 8018 | Operation valid only when the port is open |
8019 | Device busy | |
comReadError | 8020 | Error reading comm device |
comDCBError | 8021 | Internal error retrieving device control block for the port |
2.Properties Description
CommPort
Settings
PortOpen
Input
Output
CommEvent
Syntax
object.CommEvent
The CommEvent property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
Remarks
Although the OnComm event is generated whenever a communication error or event occurs, the CommEvent property holds the numeric code for that error or event. To determine the actual error or event that caused the OnComm event, you must reference the CommEvent property.
The CommEvent property returns one of the following values for communication errors or events. These constants can also be found in the Object Library for this control.
Communication errors include the following settings:
Constant
comEventBreak
comEventFrame
comEventOverrun
comEventRxOver
comEventRxParity
comEventTxFull
comEventDCB
Communications events include the following settings:
Constant
comEvSend
comEvReceive
comEvCTS
comEvDSR
comEvCD
comEvRing
comEvEOF
Data Type
EOFEnable
Syntax
object.EOFEnable [ = value ]
The EOFEnable property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value A boolean expression that determines whether the OnComm event
is fired when an EOF character is found, as described in
Settings.
Settings
The settings for value are:
Setting Description
True The OnComm event is fired when an EOF character is
found.
False (Default) The OnComm event isn't fired when an EOF character
is found.
Remarks
InBufferCount
Returns the number of characters waiting in the receive buffer.
This property is not available at design time.
Syntax
object.InBufferCount[ = value ]
The InBufferCount property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value An integer expression specifying the number of characters
waiting in the receive buffer.
Remarks
InBufferCount refers to the number of characters that have been received by the modem and are waiting in the receive buffer for you to take them out. You can clear the receive buffer by setting the InBufferCount property to 0.
Note
Data Type
InBufferSize
Sets and returns the size of the receive buffer in bytes.
Syntax
object.InBufferSize[ = value ]
The InBufferSize property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value An integer expression specifying the size of the receive
buffer in bytes.
Remarks
InBufferSize refers to the total size of the receive buffer. The default size is 1024 bytes. Do not confuse this property with the InBufferCount property which reflects the number of characters currently waiting in the receive buffer.
Note
Data Type
Input
Returns and removes a stream of data from the receive buffer. This
property is not available at design time and is read-only at run
time.
Syntax
object.Input
The Input property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
Remarks
The InputLen property determines the number of characters that are read by the Input property. Setting InputLen to 0 causes the Input property to read the entire contents of the receive buffer.
The InputMode property determines the type of data that is retrieved with the Input property. If InputMode is set to comInputModeText then the Input property returns text data in a Variant. If InputMode is comInputModeBinary then the Input property returns binary data in an array of bytes in a Variant.
Data Type
InputLen
Sets and returns the number of characters the Input property reads
from the receive buffer.
Syntax
object.InputLen [ = value ]
The InputLen property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value An integer expression specifying the number of characters the
Input property reads from the receive buffer.
Remarks
The default value for the InputLen property is 0. Setting InputLen to 0 causes the MSComm control to read the entire contents of the receive buffer when Input is used.
If InputLen characters are not available in the receive buffer, the Input property returns a zero-length string (""). The user can optionally check the InBufferCount property to determine if the required number of characters are present before using Input.
This property is useful when reading data from a machine whose output is formatted in fixed-length blocks of data.
Data Type
InputMode
Sets or returns the type of data retrieved by the Input
property.
Syntax
object.InputMode [ = value ]
The InputMode property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value A value or constant that specifies the input mode, as
described in Settings.
Settings
The settings for value are:
Constant Value Description
comInputModeText 0 (Default) Data is retrieved through the Input
property as text.
comInputModeBinary 1 Data is retrieved through the Input property
as binary data.
Remarks
The InputMode property determines how data will be retrieved through the Input property. The data will either be retrieved as string or as binary data in a byte array.
Use comInputModeText for data that uses the ANSI character set. Use comInputModeBinary for all other data such as data that has embedded control characters, Nulls, etc.
OutBufferCount
Returns the number of characters waiting in the transmit buffer.
You can also use it to clear the transmit buffer. This property is
not available at design time.
Syntax
object.OutBufferCount [ = value ]
The OutBufferCount property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value An integer expression specifying the number of characters
waiting in the transmit buffer.
Remarks
You can clear the transmit buffer by setting the OutBufferCount property to 0.
Note
Data Type
OutBufferSize
Sets and returns the size, in bytes, of the transmit buffer.
Syntax
object.OutBufferSize [ = object ]
The OutBufferSize property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value An integer expression specifying the size of the transmit
buffer.
Remarks
OutBufferSize refers to the total size of the transmit buffer. The default size is 512 bytes. Do not confuse this property with the OutBufferCount which reflects the number of bytes currently waiting in the transmit buffer.
Note
Data Type
Output
Writes a stream of data to the transmit buffer. This property is
not available at design time and is write-only at run time.
Syntax
object.Output [ = value ]
The Output property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value A string of characters to write to the transmit buffer.
Remarks
The Output property can transmit text data or binary data. To send text data using the Output property, you must specify a Variant that contains a string. To send binary data, you must pass a Variant which contains a byte array to the Output property.
Normally, if you are sending an ANSI string to an application, you can send it as text data. If you have data that contains embedded control characters, Null characters, etc., then you will want to pass it as binary data.
Data Type
RThreshold
Sets and returns the number of characters to receive before the
MSComm control sets the CommEvent property to comEvReceive and
generates the OnComm event.
Syntax
object.Rthreshold [ = value ]
The Rthreshold property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value An integer expression specifying the number of characters to
receive before generating the OnComm event.
Remarks
Setting the RThreshold property to 0 (the default) disables generating the OnComm event when characters are received.
Setting RThreshold to 1, for example, causes the MSComm control to generate the OnComm event every time a single character is placed in the receive buffer.
Data Type
SThreshold
Sets and returns the minimum number of characters allowable in the
transmit buffer before the MSComm control sets the CommEvent
property to comEvSend and generates the OnComm event.
Syntax
object.SThreshold [ = value ]
The SThreshold property syntax has these parts:
Part Description
object An object expression that evaluates to an object in the
Applies To list.
value An integer expression representing the minimum number of
characters in the transmit buffer before the OnComm event is
generated.
Remarks
Setting the SThreshold property to 0 (the default) disables generating the OnComm event for data transmission events. Setting the SThreshold property to 1 causes the MSComm control to generate the OnComm event when the transmit buffer is completely empty.
If the number of characters in the transmit buffer is less than value, the CommEvent property is set to comEvSend, and the OnComm event is generated. The comEvSend event is only fired once, when the number of characters crosses the SThreshold. For example, if SThreshold equals five, the comEvSend event occurs only when the number of characters drops from five to four in the output queue. If there are never more than SThreshold characters in the output queue, the event is never fired.
Data Type