lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
Typedefs | Enumerations | Functions
Access to serial interfaces
Collaboration diagram for Access to serial interfaces:

Typedefs

typedef struct sSerialPort * SerialPort
 

Enumerations

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
}
 

Functions

PAL_API SerialPort SerialPort_create (const char *interfaceName, int baudRate, uint8_t dataBits, char parity, uint8_t stopBits)
 Create a new SerialPort instance. More...
 
PAL_API void SerialPort_destroy (SerialPort self)
 Destroy the SerialPort instance and release all resources.
 
PAL_API bool SerialPort_open (SerialPort self)
 Open the serial interface. More...
 
PAL_API void SerialPort_close (SerialPort self)
 Close (release) the serial interface.
 
PAL_API int SerialPort_getBaudRate (SerialPort self)
 Get the baudrate used by the serial interface. More...
 
PAL_API void SerialPort_setTimeout (SerialPort self, int timeout)
 Set the timeout used for message reception. More...
 
PAL_API void SerialPort_discardInBuffer (SerialPort self)
 Discard all data in the input buffer of the serial interface.
 
PAL_API int SerialPort_readByte (SerialPort self)
 Read a byte from the interface. More...
 
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. More...
 
PAL_API SerialPortError SerialPort_getLastError (SerialPort self)
 Get the error code of the last operation.
 

Detailed Description

Serial interface abstraction layer. This functions have to be implemented to port lib60870 to new platforms when the serial link layers are required.

Function Documentation

◆ 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
interfaceNameidentifier or name of the serial interface (e.g. "/dev/ttyS1" or "COM4")
baudRatethe baud rate in baud (e.g. 9600)
dataBitsthe number of data bits (usually 8)
paritydefines what kind of parity to use ('E' - even parity, 'O' - odd parity, 'N' - no parity)
stopBitsthe 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
timeoutthe 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
bufferthe buffer containing the data to write
startPosstart position in the buffer of the data to write
numberOfBytesnumber of bytes to write
Returns
number of bytes written, or -1 in case of an error