C Language Development Kit/Functions/GetCom2
From OptiWiki
| 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. | |||||||||
| Syntax | int getcom2(int port, int timeout); | |||||||||
| Arguments | port specifies which serial communications port is to be opened. See the table below for details.
int port
int timeouttimeout 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. | |||||||||
| 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 = 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 } } |
