有关于MSComm控件详解

 Visual Basic: MSComm Control
 
    The MSComm control provides serial communications for your application by allowing the transmission and reception of data through a serial port.
 
1.Error Messages (MS Comm Control)

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

    Although the MSComm control has many important properties, there are a few that you should be familiar with first.

 

CommPort     Sets and returns the communications port number.
Settings     Sets and returns the baud rate, parity, data bits, and stop bits as a string.
PortOpen     Sets and returns the state of a communications port. Also opens and closes a port.
Input        Returns and removes characters from the receive buffer.
Output       Writes a string of characters to the transmit buffer.

 


CommEvent

      Returns the most recent communication event or error. This property is 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 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               Value                              Description
comEventBreak           1001                       A Break signal was received.
comEventFrame           1004         Framing Error. The hardware detected a framing error.
comEventOverrun         1006     Port Overrun. A character was not read from the hardware                                       before the next character arrived and was lost.
comEventRxOver          1008        Receive Buffer Overflow. There is no room in the                                                     receive buffer.
comEventRxParity        1009         Parity Error. The hardware detected a parity error.
comEventTxFull          1010          Transmit Buffer Full. The transmit buffer was full       

你可能感兴趣的:(VB)