C Language Development Kit/Functions/GetCom2

From OptiWiki

Jump to: navigation, search
Description This function reads a character from the receive buffer from the serial communications port that was specified. The difference between this function and getcom() is that you can specify the port here, where getcom() uses the last port that was opened.
int getcom2(int port, int timeout);
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
int timeout

timeout is the time (in steps of 20ms) that the routine tries to get a character from the communications port before returning. For example timeout = 10 specifies 200 milliseconds. When timeout = 0, the routine returns directly.

Returns On success, when a character is available, getcom2() returns the received character. On error -1 is returned.
Remarks When the COM port was not opened previously, the error value -1 will be returned.
#include "lib.h"
#include <stdio.h>
void main( void )
    int ch;
    comopen( COM2 );    // Open the COM port for the cradle
    while( 1 )
        if( (ch = getcom2( COM2, 0 )) != -1)
            putchar( ch );
            putcom2( COM2, ch );
        if( (ch = getchar()) != EOF)
            putchar( ch );
            putcom2( COM2, ch );
        idle();    // Very important to lower the power consumption

Personal tools