How to Open a Port: Tutorial

This tutorial shows the basic steps required to open a serial port using the RComm API.

If the port is being opened for a console application or similar environment where device drivers are not guaranteed to be started, first load the LDD and PDDs as per the tutorial How to load the Physical Device Driver and Logical Device Driver: Tutorial


  1. The RComm is a client of the RCommServ API, so create a RCommServ session.

  2. Call RCommServ::LoadCommModule() with the aFileName parameter set to a Serial Protocol Module. This requests that the Serial Communications Server use a specific Serial Protocol Module. These Serial Protocol Modules are .CSY files that let the Serial Communications Server know how the server should manage the port. For example, sample terminal code uses a standard RS232 module called ECUART, while infra-red code uses a IrDA module called IrCOMM. The .csy file extension is not required in the aFileName parameter.

  3. Call RComm:Open() to connect the RComm client to the server and to open the port by name. You must specify the name of the port. The serial port name format is:
    [text-string]::[0-255]
    The name of the port may not be the same as the name of the Serial Protocol Module. For example, the Infrared Serial Protocol Module is called irda.csy and the port name is IrCOMM.

Example

RCommServ server; 
server.Connect ();                     // step 1
server.LoadCommModule (_L ("ECUART")); // step 2
RComm commPort;
commPort.Open (server, _L ("COMM::0"), ECommExclusive); // step 3