|
typedef struct sSerialPort * | SerialPort |
|
|
enum | SerialPortError {
SERIAL_PORT_ERROR_NONE = 0
, SERIAL_PORT_ERROR_INVALID_ARGUMENT = 1
, SERIAL_PORT_ERROR_INVALID_BAUDRATE = 2
, SERIAL_PORT_ERROR_OPEN_FAILED = 3
,
SERIAL_PORT_ERROR_UNKNOWN = 99
} |
|
Serial interface abstraction layer. This functions have to be implemented to port lib60870 to new platforms when the serial link layers are required.
◆ SerialPort_create()
PAL_API SerialPort SerialPort_create |
( |
const char * |
interfaceName, |
|
|
int |
baudRate, |
|
|
uint8_t |
dataBits, |
|
|
char |
parity, |
|
|
uint8_t |
stopBits |
|
) |
| |
Create a new SerialPort instance.
- Parameters
-
interfaceName | identifier or name of the serial interface (e.g. "/dev/ttyS1" or "COM4") |
baudRate | the baud rate in baud (e.g. 9600) |
dataBits | the number of data bits (usually 8) |
parity | defines what kind of parity to use ('E' - even parity, 'O' - odd parity, 'N' - no parity) |
stopBits | the number of stop buts (usually 1) |
- Returns
- the new SerialPort instance
◆ SerialPort_getBaudRate()
PAL_API int SerialPort_getBaudRate |
( |
SerialPort |
self | ) |
|
Get the baudrate used by the serial interface.
- Returns
- the baud rate in baud
◆ SerialPort_open()
PAL_API bool SerialPort_open |
( |
SerialPort |
self | ) |
|
Open the serial interface.
- Returns
- true in case of success, false otherwise (use SerialPort_getLastError for a detailed error code)
◆ SerialPort_readByte()
PAL_API int SerialPort_readByte |
( |
SerialPort |
self | ) |
|
Read a byte from the interface.
- Returns
- number of read bytes of -1 in case of an error
◆ SerialPort_setTimeout()
PAL_API void SerialPort_setTimeout |
( |
SerialPort |
self, |
|
|
int |
timeout |
|
) |
| |
Set the timeout used for message reception.
- Parameters
-
timeout | the timeout value in ms. |
◆ SerialPort_write()
PAL_API int SerialPort_write |
( |
SerialPort |
self, |
|
|
uint8_t * |
buffer, |
|
|
int |
startPos, |
|
|
int |
numberOfBytes |
|
) |
| |
Write the number of bytes from the buffer to the serial interface.
- Parameters
-
buffer | the buffer containing the data to write |
startPos | start position in the buffer of the data to write |
numberOfBytes | number of bytes to write |
- Returns
- number of bytes written, or -1 in case of an error