Visual Basic: MSComm Control

PortOpen Property

See Also   Example   Applies To

Sets and returns the state of the communications port (open or closed). Not available at design time.

Syntax

object.PortOpen [ = value ]

The PortOpen 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 specifying the state of the communications port.

Settings

The settings for value are:

Setting Description
True Port is opened
False Port is closed

Remarks

Setting the PortOpen property to True opens the port. Setting it to False closes the port and clears the receive and transmit buffers. The MSComm control automatically closes the serial port when your application is terminated.

Make sure the CommPort property is set to a valid port number before opening the port. If the CommPort property is set to an invalid port number when you try to open the port, the MSComm control generates error 68 (Device unavailable).

In addition, your serial port device must support the current values in the Settings property. If the Settings property contains communications settings that your hardware does not support, your hardware may not work correctly.

If either the DTREnable or the RTSEnable properties is set to True before the port is opened, the properties are set to False when the port is closed. Otherwise, the DTR and RTS lines remain in their previous state.

Data Type

Boolean