-The API is simple, and designed to be a minimal wrapper around the serial port
-support in each OS.
-
-Most functions take a pointer to a struct sp_port, which represents an serial
-port. This structure is obtained from the array returned by sp_list_ports().
-
-All functions can return only three possible error values. SP_ERR_ARG indicates
-the function was called with invalid arguments. SP_ERR_FAIL indicates that the
-OS reported a failure. SP_ERR_MEM indicates that a memory allocation failed.
-Aoth these error values are negative.
-
-When SP_ERR_FAIL is returned, an error code or string description of the error
-can be obtained by calling sp_last_error_code() or sp_last_error_message(). The
-error code or message is that provided by the OS; libserialport does not define
-any error codes or messages of its own.
-
-Functions calls that succeed return SP_OK, which is equal to zero, or where
-otherwise documented a positive value.
-
-The available functions are as follows:
-
-Enumeration
------------
-
-struct sp_port **sp_list_ports();
-
- Lists the serial ports available on the system. The value returned is an array
- of pointers to sp_port structures, terminated by a NULL. It should be freed after
- use by calling sp_free_port_list().
-
-void sp_free_port_list(struct sp_port **list);
-
- Frees the data structure returned by sp_list_ports().
-
-Opening and closing ports
--------------------------
-
-int sp_open(struct sp_port *port, int flags);
-
- Opens the specified serial port.
-
- Parameters:
-
- port: Pointer to port structure.
- flags: Flags to use when opening the serial port. Possible
- flags are: SP_MODE_RDWR, SP_MODE_RDONLY, and SP_MODE_NONBLOCK.
-
- Returns: SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
- if an invalid port or name is passed.
-
-int sp_close(struct sp_port *port);
-
- Closes the specified serial port.
-
- Returns: SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
- if an invalid port is passed.
-
-Setting port parameters
------------------------
-
-int sp_set_params(struct sp_port *port, int baudrate,
- int bits, int parity, int stopbits,
- int flowcontrol, int rts, int dtr);
-
- Sets serial parameters for the specified serial port.
-
- Parameters:
-
- port: Pointer to port structure.
- baudrate: Baud rate to set.
- bits: Number of data bits to use.
- parity: Parity setting to use
- (SP_PARITY_NONE, SP_PARITY_EVEN or SP_PARITY_ODD)
- stopbits: Number of stop bits to use (1 or 2).
- flowcontrol: Flow control setting to use
- (SP_FLOW_NONE, SP_FLOW_HARDWARE or SP_FLOW_SOFTWARE)
-
- Returns: SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
- for invalid arguments.
-
-Reading, writing and flushing data
-----------------------------------
-
-int sp_read(struct sp_port *port, const void *buf, size_t count)
-
- Reads a number of bytes from the specified serial port.
-
- Parameters:
-
- port: Pointer to port structure.
- buf: Buffer in which to store the bytes read.
- count: Number of bytes to read.
-
- Returns: The number of bytes read, SP_ERR_FAIL on failure,
- or SP_ERR_ARG for invalid arguments.
-
-int sp_write(struct sp_port *port, const void *buf, size_t count)
-
- Writes a number of bytes to the specified serial port.
-
- Parameters:
-
- port: Pointer to port structure.
- buf: Buffer containing the bytes to write.
- count: Number of bytes to write.
-
- Returns: The number of bytes written, SP_ERR_FAIL on failure,
- or SP_ERR_ARG for invalid arguments.
-
-int sp_flush(struct sp_port *port);
-
- Flushes serial port buffers.
-
- Returns: SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
- if an invalid port is passed.
-
-Error handling
---------------
-
-int sp_last_error_code();
-
- Gets the error code for a failed operation.
-
- In order to obtain the correct result, this function should be called
- straight after the failure, before executing any other system operations.
-
- Returns: The system's numeric code for the error that caused the last
- operation to fail.
-
-char *sp_last_error_message();