imabot2 / serialib

Serial library for Linux & Windows
MIT License
195 stars 45 forks source link

Implement setting data bits, stop bits and parity #10

Closed maxgerhardt closed 3 years ago

maxgerhardt commented 3 years ago

Closes #8.

Changes the function signature of openDevice from

     char    openDevice (const char *Device,const unsigned int Bauds);

to

    char openDevice(const char *Device, const unsigned int Bauds,
                    SerialDataBits Databits = SERIAL_DATABITS_8,
                    SerialParity Parity = SERIAL_PARITY_NONE,
                    SerialStopBits Stopbits = SERIAL_STOPBITS_1);

The default parameters have been set to the previous 8N1 setting as to not break existing programs.

The available settings are

/**
 * number of serial data bits
 */
enum SerialDataBits {
    SERIAL_DATABITS_5, /**< 5 databits */
    SERIAL_DATABITS_6, /**< 6 databits */
    SERIAL_DATABITS_7, /**< 7 databits */
    SERIAL_DATABITS_8,  /**< 8 databits */
    SERIAL_DATABITS_16,  /**< 16 databits */
};

/**
 * number of serial stop bits
 */
enum SerialStopBits {
    SERIAL_STOPBITS_1, /**< 1 stop bit */
    SERIAL_STOPBITS_1_5, /**< 1.5 stop bits */
    SERIAL_STOPBITS_2, /**< 2 stop bits */
};

/**
 * type of serial parity bits
 */
enum SerialParity {
    SERIAL_PARITY_NONE, /**< no parity bit */
    SERIAL_PARITY_EVEN, /**< even parity bit */
    SERIAL_PARITY_ODD, /**< odd parity bit */
    SERIAL_PARITY_MARK, /**< mark parity */
    SERIAL_PARITY_SPACE /**< space bit */
};

Further, a note has been added in the examples regarding the Windows serial port naming. For COM ports above COM9, the name of the device must be \\.\COMx.

The Doxygen file has been reworked to remove hardcoded paths (/home/philippe/sources/serialib/doc...) and instead use relative filepaths. The HTML documentation has been regenerated using the latest Doxygen 1.9.1.

The changes were tested on Windows as well as Linux (Xubuntu 21.04), compilation and execution works fine.

maxgerhardt commented 3 years ago

@imabot2 please merge?