The following table lists the trappable errors for theMSComm 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 theport |
2.Properties Description
Althoughthe MSComm control has many important properties, there area few that you should be familiar with first.
CommPortSets and returns the communications port number.
SettingsSets and returns the baud rate, parity, data bits, and stop bits asa string.
PortOpenSets and returns the state of a communications port. Also opens andcloses a port.
InputReturns and removes characters from the receive buffer.
OutputWrites a string of characters to the transmit buffer.
CommEvent
Returns the most recent communication event or error. This propertyis not available at design time and is read-only at run time.
Syntax
object.CommEvent
The CommEvent property syntax has these parts:
Part Description
object An object expression that evaluates to an object in theApplies To list.
Remarks
Although the OnComm event is generated whenever a communicationerror or event occurs, the CommEvent property holds the numericcode for that error or event. To determine the actual error orevent that caused the OnComm event, you must reference theCommEvent property.
The CommEvent property returns one of the following values forcommunication errors or events. These constants can also be foundin the Object Library for this control.
Communication errors include the following settings:
ConstantValueDescription
comEventBreak1001A Break signal was received.
comEventFrame1004Framing Error. The hardware detected a framing error.
comEventOverrun1006Port Overrun. A character was not read from thehardwarebefore the next character arrived and was lost.
comEventRxOver1008Receive Buffer Overflow. There is no room inthereceive buffer.
comEventRxParity1009Parity Error. The hardware detected a parity error.
comEventTxFull1010Transmit Buffer Full. The transmit buffer wasfullwhile trying to queue a character.
comEventDCB1011Unexpected error retrieving Device ControlBlock(DCB) for the port.
Communications events include the following settings:
ConstantValueDescription
comEvSend1There are fewer than Sthreshold numberofcharacters in the transmit buffer.
comEvReceive2Received Rthreshold number of characters. This eventisgenerated continuously until you use the Input propertytoremove the data from the receive buffer.
comEvCTS3Change in Clear To Send line.
comEvDSR4Change in Data Set Ready line. This event is onlyfiredwhen DSR changes from 1 to 0.
comEvCD5Change in Carrier Detect line.
comEvRing6Ring detected. Some UARTs (universalasynchronousreceiver-transmitters) may not support this event.
comEvEOF7End Of File (ASCII character 26) character received.
Data Type Integer
EOFEnable
The EOFEnable property determines if the MSComm control looks forEnd Of File (EOF) characters during input. If an EOF character isfound, the input will stop and the OnComm event will fire with theCommEvent property set to comEvEOF.
Syntax
object.EOFEnable [ = value ]
The EOFEnable property syntax has these parts:
Part Description
object An object expression that evaluates to an object in theApplies To list.
value A boolean expression that determines whether the OnComm eventis fired when an EOF character is found, as described inSettings.
Settings
The settings for value are:
Setting Description
True The OnComm event is fired when an EOF character isfound.
False (Default) The OnComm event isn't fired when an EOF characteris found.
Remarks
When EOFEnable property is set to False, the control will not scanthe input stream for EOF characters.
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 theApplies To list.
value An integer expression specifying the number of characterswaiting in the receive buffer.
Remarks
InBufferCount refers to the number of characters that have beenreceived by the modem and are waiting in the receive buffer for youto take them out. You can clear the receive buffer by setting theInBufferCount property to 0.
Note Do not confuse thisproperty with the InBufferSize property. The InBufferSize propertyreflects the total size of the receive buffer.
Data TypeInteger
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 theApplies To list.
value An integer expression specifying the size of the receivebuffer in bytes.
Remarks
InBufferSize refers to the total size of the receive buffer. Thedefault size is 1024 bytes. Do not confuse this property with theInBufferCount property which reflects the number of characterscurrently waiting in the receive buffer.
Note Note that the largeryou make the receive buffer, the less memory you have available toyour application. However, if your buffer is too small, it runs therisk of overflowing unless handshaking is used. As a general rule,start with a buffer size of 1024 bytes. If an overflow erroroccurs, increase the buffer size to handle your application'stransmission rate.
Data Type Integer
Input
Returns and removes a stream of data from the receive buffer. Thisproperty is not available at design time and is read-only at runtime.
Syntax
object.Input
The Input property syntax has these parts:
Part Description
object An object expression that evaluates to an object in theApplies To list.
Remarks
The InputLen property determines the number of characters thatare read by the Input property. Setting InputLen to 0 causes theInput property to read the entire contents of the receivebuffer.
The InputMode property determines the type of data that isretrieved with the Input property. If InputMode is set tocomInputModeText then the Input property returns text data in aVariant. If InputMode is comInputModeBinary then the Input propertyreturns binary data in an array of bytes in a Variant.
Data Type Variant
InputLen
Sets and returns the number of characters the Input property readsfrom 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 theApplies To list.
value An integer expression specifying the number of characters theInput property reads from the receive buffer.
Remarks
The default value for the InputLen property is 0. SettingInputLen to 0 causes the MSComm control to read the entire contentsof 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 canoptionally check the InBufferCount property to determine if therequired number of characters are present before using Input.
This property is useful when reading data from a machine whoseoutput is formatted in fixed-length blocks of data.
Data Type Integer
InputMode
Sets or returns the type of data retrieved by the Inputproperty.
Syntax
object.InputMode [ = value ]
The InputMode property syntax has these parts:
Part Description
object An object expression that evaluates to an object in theApplies To list.
value A value or constant that specifies the input mode, asdescribed in Settings.
Settings
The settings for value are:
Constant Value Description
comInputModeText 0 (Default) Data is retrieved through the Inputproperty as text.
comInputModeBinary 1 Data is retrieved through the Input propertyas binary data.
Remarks
The InputMode property determines how data will be retrievedthrough the Input property. The data will either be retrieved asstring 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 hasembedded 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 isnot 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 theApplies To list.
value An integer expression specifying the number of characterswaiting in the transmit buffer.
Remarks
You can clear the transmit buffer by setting the OutBufferCountproperty to 0.
Note Do not confuse theOutBufferCount property with the OutBufferSize property whichreflects the total size of the transmit buffer.
Data Type Integer
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 theApplies To list.
value An integer expression specifying the size of the transmitbuffer.
Remarks
OutBufferSize refers to the total size of the transmit buffer.The default size is 512 bytes. Do not confuse this property withthe OutBufferCount which reflects the number of bytes currentlywaiting in the transmit buffer.
Note The larger you make thetransmit buffer, the less memory you have available to yourapplication. However, if your buffer is too small, you run the riskof overflowing unless you use handshaking. As a general rule, startwith a buffer size of 512 bytes. If an overflow error occurs,increase the buffer size to handle your application's transmissionrate.
Data Type Integer
Output
Writes a stream of data to the transmit buffer. This property isnot 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 theApplies To list.
value A string of characters to write to the transmit buffer.
Remarks
The Output property can transmit text data or binary data. Tosend text data using the Output property, you must specify aVariant that contains a string. To send binary data, you must passa 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 containsembedded control characters, Null characters, etc., then you willwant to pass it as binary data.
Data Type Variant
RThreshold
Sets and returns the number of characters to receive before theMSComm control sets the CommEvent property to comEvReceive andgenerates 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 theApplies To list.
value An integer expression specifying the number of characters toreceive before generating the OnComm event.
Remarks
Setting the RThreshold property to 0 (the default) disablesgenerating the OnComm event when characters are received.
Setting RThreshold to 1, for example, causes the MSComm controlto generate the OnComm event every time a single character isplaced in the receive buffer.
Data Type Integer
SThreshold
Sets and returns the minimum number of characters allowable in thetransmit buffer before the MSComm control sets the CommEventproperty 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 theApplies To list.
value An integer expression representing the minimum number ofcharacters in the transmit buffer before the OnComm event isgenerated.
Remarks
Setting the SThreshold property to 0 (the default) disablesgenerating the OnComm event for data transmission events. Settingthe SThreshold property to 1 causes the MSComm control to generatethe OnComm event when the transmit buffer is completely empty.
If the number of characters in the transmit buffer is less thanvalue, the CommEvent property is set to comEvSend, and the OnCommevent is generated. The comEvSend event is only fired once, whenthe number of characters crosses the SThreshold. For example, ifSThreshold equals five, the comEvSend event occurs only when thenumber of characters drops from five to four in the output queue.If there are never more than SThreshold characters in the outputqueue, the event is never fired.
Data Type Integer