Establishing a Serial Connection

Before you can use a Comm control to transmit data, you must establish a connection to the port. Each serial port has settings that control how the port sends data. The CommPort property determines which port the control will use, and the Settings property sets the port’s baud and the number of parity, data, and stop bits. The baud determines the speed of the connection, while the parity, data bits, and stop bits provide error control. Each side of a serial connection must use the same port settings.

In addition to using identical port settings, each side of the connection must know when to transmit or receive data. Properties such as Handshaking, DTREnable, and RTSEnable manage the connection and the flow of data through the serial port.

You can set the Handshaking property to specify the handshaking protocol used by your application. By default, the Handshaking property is set to comNone, indicating that the connection does not use handshaking.

If you set Handshaking to either comRTS or comRTSXOnXOff, you must set the RTSEnabled property to True. Otherwise, you can only send, not receive, data through the connection.

Once you establish the settings and protocols, set the PortOpen property to True to open a communication port; set it to False to close the port.

    To establish a connection to a serial port

  1. Set the CommPort property to the port number of the communications port. The port number depends on the hardware of your Windows CE-based device.
  2. Assign a string to the Settings property to set the baud, parity, data bits, and stop bits that the control will use when the port is opened. Some example connection strings are “19200,n,8,1” and “9600,e,7,1”.
  3. Set the PortOpen property to True to open the connection.

When the port is open and the connection is active, you can send and receive data through the port.