C Language Development Kit/Functions/ComOpen

From OptiWiki

Jump to: navigation, search
Description Opens a port for serial communication.
Syntax
int comopen(unsigned int port);
Arguments
unsigned int port
port specifies which serial communications port is to be opened. See the table below for details.
Terminal Supported ports Description
OPH100x COM1 Cradle CRD1001 or IrDA dongle
COM2 Same as COM1
PHL1300 COM1 Cradle IRU1300 or IrDA dongle
COM2 Same as COM1
PHL1700 COM0 Direct cable
COM1 IrDA dongle or IRU1700-SV
COM2 Cradle IRU1700
PHL2700 COM0 Direct cable
COM1 Cradle IRU2600 or IrDA dongle
COM2 Same as COM1
DWT7133 COM2 Cradle DCW9133
OPL97xx COM1 Cradle CRD9723 or IrDA dongle
COM2 Same as COM1
COM3 Bluetooth interface (Master), using the SPP profile (OPL9724,9712)
COM4 Bluetooth interface (Master), usign the DUN profile (OPL9724,9712)
COM5 Bluetooth interface (Slave), using the SPP profile (OPL9724,9712)
DCL153x COM0 USB direct cable.
COM1 Cradle CRD9723 or IrDA dongle
COM2 Same as COM1

The baudrate, the number of data bits, the parity mode, the number of stopbits and the handshaking modes, can all be selected via a systemsetting() call. comopen() uses the current settings when opening a communications port.

The default settings of the handheld terminal are:

Baudrate 9600 (115K2 for the OPH100x)
Parity None
Databits 8
Stopbits 1
Hardware handshaking No
Software handshaking No
Returns
0 The port was opened normally.
-1 The port number was invalid.
-3 The port could not be opened, because the cradle did not respond (PHL1700, OPL97xx and DCL153x when opening COM2)
<-10 The OPL9724 or OPL9712 could not establish a connection.
Remarks When a comport is opened the power consumption may increase, so use the comclose() function when serial communication is no longer needed.

When you have opened a communication port with comopen(), and then you open a second communication port with comopen() the first port is closed automatically.

The functions getcom() and putcom(), will use the port opened by comopen().

Note: Only the PHL1700 has a difference between COM1 and COM2. The rest of the terminals do support COM1 and COM2, but there is no difference between them.

Example
#include "lib.h"
#include <stdio.h>
 
void main( void )
{
    int ch;
 
    comopen( COM2 );    // Open the COM port for the cradle
 
    while( 1 )
    {
        if( (ch = getcom( 0 )) != -1)
        {
            putchar( ch );
            putcom( ch );
        }
 
        if( (ch = getchar()) != EOF)
        {
            putchar( ch );
            putcom( ch );
        }
        idle();    // Very important to lower the power consumption
    }
}


Views
Personal tools