lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
hal_serial.h
Go to the documentation of this file.
1 /*
2  * hal_serial.h
3  *
4  * Copyright 2013-2021 Michael Zillgith
5  *
6  * This file is part of Platform Abstraction Layer (libpal)
7  * for libiec61850, libmms, and lib60870.
8  */
9 
10 #ifndef SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_
11 #define SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_
12 
13 #include "hal_base.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
39 typedef struct sSerialPort* SerialPort;
40 
41 typedef enum {
42  SERIAL_PORT_ERROR_NONE = 0,
43  SERIAL_PORT_ERROR_INVALID_ARGUMENT = 1,
44  SERIAL_PORT_ERROR_INVALID_BAUDRATE = 2,
45  SERIAL_PORT_ERROR_OPEN_FAILED = 3,
46  SERIAL_PORT_ERROR_UNKNOWN = 99
47 } SerialPortError;
48 
60 PAL_API SerialPort
61 SerialPort_create(const char* interfaceName, int baudRate, uint8_t dataBits, char parity, uint8_t stopBits);
62 
66 PAL_API void
67 SerialPort_destroy(SerialPort self);
68 
74 PAL_API bool
75 SerialPort_open(SerialPort self);
76 
80 PAL_API void
81 SerialPort_close(SerialPort self);
82 
88 PAL_API int
89 SerialPort_getBaudRate(SerialPort self);
90 
96 PAL_API void
97 SerialPort_setTimeout(SerialPort self, int timeout);
98 
102 PAL_API void
103 SerialPort_discardInBuffer(SerialPort self);
104 
110 PAL_API int
111 SerialPort_readByte(SerialPort self);
112 
122 PAL_API int
123 SerialPort_write(SerialPort self, uint8_t* buffer, int startPos, int numberOfBytes);
124 
128 PAL_API SerialPortError
129 SerialPort_getLastError(SerialPort self);
130 
135 #ifdef __cplusplus
136 }
137 #endif
138 
139 
140 #endif /* SRC_IEC60870_LINK_LAYER_SERIAL_PORT_H_ */
PAL_API int SerialPort_getBaudRate(SerialPort self)
Get the baudrate used by the serial interface.
PAL_API void SerialPort_close(SerialPort self)
Close (release) the serial interface.
PAL_API int SerialPort_readByte(SerialPort self)
Read a byte from the interface.
PAL_API bool SerialPort_open(SerialPort self)
Open the serial interface.
PAL_API void SerialPort_setTimeout(SerialPort self, int timeout)
Set the timeout used for message reception.
PAL_API SerialPort SerialPort_create(const char *interfaceName, int baudRate, uint8_t dataBits, char parity, uint8_t stopBits)
Create a new SerialPort instance.
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.
PAL_API SerialPortError SerialPort_getLastError(SerialPort self)
Get the error code of the last operation.
PAL_API void SerialPort_destroy(SerialPort self)
Destroy the SerialPort instance and release all resources.
PAL_API void SerialPort_discardInBuffer(SerialPort self)
Discard all data in the input buffer of the serial interface.