ComClose

Availability All terminals
Description Closes a communications port previously opened by ComOpen().
Syntax int ComClose( int port );
Arguments
int port
port specifies which communications port is to be closed. See the table below for details.

Terminal Supported ports Description
OPN-2500 & OPN-6000 COM0
COM1
COM7
COM8
COM9
COM10
COM11
COM12
COM13
COM14
COM15
COM16
COM17
COM18
USB-VCP (Opticon 1D COM-Port)
USB-CDC (Opticon 2D COM-Port)
USB-CDC (OptiConnect)
USB-CDC (Opticon 2D COM-Port)
USB-HID (Human Interface device)
USB-MSD (Mass Storage)
Bluetooth HID (No white list)
Bluetooth HID (White list)
Bluetooth LE UART & OptiConnect (No white list)
Bluetooth LE UART & OptiConnect (White list)
Bluetooth LE OptiConnect(No white list)
Bluetooth LE OptiConnect (White list)
Bluetooth LE UART (No white list)
Bluetooth LE UART (White list)
Returns
0 The port was closed correctly.
-1 An invalid port number was given or, in case of a Bluetooth port, a connection could not be terminated.
Remarks Never leave a communication port open longer then necessary, since it increases power consumption.
Example
#include <stdio.h>
#include "lib.h"

void main( void )
{
    int ch, open, connected;

    ComOpen( COM9 );    // Open the COM port for USB-VCP

    Sound(TSTANDARD, VHIGH, SMEDIUM, SHIGH, 0);
    open = TRUE;
    connected = FALSE;

    for(;;)
    {
        if(connected != UsbIsConnected())
        {
            Sound(TLONG, VHIGH, SHIGH, 0);
            connected = UsbIsConnected();
        }
        
        if((ch=getchar()) == TRIGGER_KEY && !open)
        {
            Sound(TSTANDARD, VHIGH, SMEDIUM, SHIGH, 0);
            ComOpen( COM9 );
            open = TRUE;
        }
        else if(ch == CLR_KEY && open)
        {
            ComClose(COM9);
            Sound(TLONG, VHIGH, SERROR, 0);
            connected = open = FALSE;
        }
        
        if( (ch = GetCom( 0 )) != -1)    // Echo
            PutCom( ch );
        
        Idle();    // Very important to lower the power consumption
    }
}