 |
About PortController |
 |
Getting Started |
|
|
Open Method
Opens the communications port.
Syntax
Visual Basic
object.Open port [, settings]
Visual C++
object.Open(port, settings)
Delphi
object.Open(port, settings)
| Part
| Description |
| object |
An object expression that evaluates to a PortController object. |
| port |
A string containing the name of the communications port.
|
| settings |
A string containing comma delimited settings for the port in the format
BaudRate, DataBits, Parity, StopBits.
|
Example
Visual Basic
myPortController.Open "COM1", "9600,8,N,1"
Visual C++
m_myPortController.Open("COM1","9600,8,N,1");
Delphi
myPortController.Open('COM1', '9600,8,N,1');
Remarks
The settings parameter is optional. If is not supplied (or specified as an empty string
in VC++) the current values for these properties are used.
To use current values for a particular
setting, simply leave the setting blank. For example, "9600, , E, 1.5" sets BaudRate to 9600,
Parity to Even, and StopBits to 1.5 while using the current value for DataBits.
Valid baud rates are as follows:
- 110
- 300
- 600
- 1200
- 2400
- 4800
- 9600 (Default)
- 14400
- 19200
- 28800
- 38400
- 56000
- 57600
- 115200
- 128000
- 256000
Valid data bits values are as follows:
Valid parity values are as follows:
| Setting
| Description |
| N |
None |
| O |
Odd |
| E |
Even |
| M |
Mark |
| S |
Space |
Note that these conventions are different than the conventions for the Parity property conventions.
Valid stop bits values are as follows:
| Setting
| Description |
| 1 |
1 Stop Bit |
| 1.5 |
1.5 Stop Bits |
| 2 |
2 Stop Bits |
Note that these conventions are different than the conventions for the StopBits property conventions.
BaudRate, DataBits,
Parity, and StopBits parameters are subject to the
constraints documented in their property documentation.
Returns
Nothing
Errors
Violating any of the settings constraints will cause the PortController to use the current
or default values for the offending setting.
After opening a port using Open(), any subsequent call to Open() will cause
the PortController to throw a "Port is already open" exception.
An attempt to open a port that has already been opened by another application or
that does not exist will cause the PortController to throw a "Could not open port.
This may be because the port does not exist or it is already in use." exception.
See Also
DataBits, BaudRate, Parity, StopBits, PortName, Close()
|