This function opens a port for communication.

Syntax

int ComOpen(
  int port
);

Parameters

port
[in] Specifies which communications port is to be opened.
See the table below for details.
ValueDescription
COM3 Bluetooth SPP (Master)
COM4 Bluetooth HID (Slave)
COM5 Bluetooth SPP (Slave)
COM9 USB VCP
COM10 USB HID
Other COM ports are reserved for the system for OS or extension.
The default communication settings are different for each communication / boat number.
Set by calling the SetConfig function.

Return value

The function ends normally (OK) or returns a port specification error (ERROR).

Remarks

You cannot open multiple COM ports at the same time.
When a comport is opened the power consumption may increase,
so use the ComClose function when communication is no longer needed.

Requirements

Header file:
lib.h
Library file:
libSTARTUPOPH5000.a

Sample

#include <stdio.h>
#include "lib.h"

void main(void)
{
    int ch;

    ComOpen(COM9); // Open the COM port
    for(;;)
    {
        if ((ch=GetCom(0)) != -1)
        {
            putchar(ch);
        }
        if ((ch=getchar())!=EOF)
        {
            PutCom(ch);
        }
        Idle(); // Very important to lower the power consumption
    }
}

Last updated: 2020/10/07