C Language Development Kit/Functions/ComClose

From OptiWiki

Jump to: navigation, search
Description Closes a serial communications port previously opened by comopen()
Syntax
int comclose(unsigned int port);
Arguments
unsigned int port
port specifies which serial communications port is to be closed. See the table below for details.
Terminal Supported ports Description
OPH100x COM1 Cradle CRD1000 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
Returns
0 The port was closed correctly.
-1 An invalid port number was given or in case of the OPL9724 or OPL9712 a connection could not be terminated.
Remarks Never leave a serial communication port open longer then necessary, since it increases power consumption. Note that 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 the two.
Example
#include "lib.h"
#include <stdio.h>
 
#define COM   COM0    // COM0 is the direct cable
void main( void )
{
    // Array for ten filenames; static so space is not on stack
    static char ftest[10][12 + 1];
    int test;
 
    systemsetting("K7L1L2L5");    // 19200, N, 8, 1
    if( comopen( COM ) != OK )
    {
        printf("\fCan't open port");
        while( 1 )
            idle();
    }
 
    do{
        printf("\fReceiving..");
        test = neto_receive( ftest, "123456", ENT_KEY, 3);
        printf("\ntest=%d", test);
    }while( test < 0 );
 
    comclose( COM );    // Save power!
 
    printf("\ftest = %d", test);
    printf("\npress any key");
    resetkey();
    while( !kbhit())
        idle();
 
    if( comopen( COM ) != OK)
    {
        printf("\fCan't open port");
        while( 1 )
            idle();
    }
 
    printf("\fTransmitting...\n%d files", test);
    test = neto_ transmit( ftest, test, "123456", ENT_KEY, 3);
    printf("\ftest=%d", test);
    comclose( COM );
    while( 1 )
        idle();
}


Views
Personal tools