Myriota Flex SDK 2.5.0
Loading...
Searching...
No Matches
Serial (RS-485/RS-232)

Configure and control the FlexSense serial interface. More...

Classes

struct  FLEX_SerialExOptions
 Serial Interface - Serial Extended Configuration Options. More...
 

Enumerations

enum  FLEX_SerialProtocol { FLEX_SERIAL_PROTOCOL_RS485 , FLEX_SERIAL_PROTOCOL_RS232 }
 Serial Interface - Protocol Options. More...
 
enum  FLEX_SerialParity { FLEX_SERIAL_PARITY_NONE , FLEX_SERIAL_PARITY_EVEN , FLEX_SERIAL_PARITY_ODD }
 Serial Interface - Parity Options. More...
 
enum  FLEX_SerialDatabits { FLEX_SERIAL_DATABITS_EIGHT , FLEX_SERIAL_DATABITS_NINE }
 Serial Interface - Databits Options. More...
 
enum  FLEX_SerialStopbits { FLEX_SERIAL_STOPBITS_ONE , FLEX_SERIAL_STOPBITS_HALF , FLEX_SERIAL_STOPBITS_ONEANDHALF , FLEX_SERIAL_STOPBITS_TWO }
 Serial Interface - Stopbits Options. More...
 

Functions

int FLEX_SerialInit (FLEX_SerialProtocol Protocol, uint32_t BaudRate)
 
int FLEX_SerialInitEx (const FLEX_SerialExOptions Options)
 
int FLEX_SerialWrite (const uint8_t *Tx, size_t Length)
 
int FLEX_SerialRead (uint8_t *Rx, size_t Length)
 
int FLEX_SerialDeinit (void)
 

Detailed Description

Configure and control the FlexSense serial interface.

The FlexSense Serial interface supports RS-485 and RS-232. The RS-232 is configurable to support a wide range of interface requirements.

Warning
To maximise the battery life of your FlexSense, we recommend initialising and de-initialising the Serial interface each time the job using it is called. This will reduce the idle power usage of your FlexSense.

Enumeration Type Documentation

◆ FLEX_SerialProtocol

Serial Interface - Protocol Options.

Enumerator
FLEX_SERIAL_PROTOCOL_RS485 

use RS-485 as the Serial Protocol

FLEX_SERIAL_PROTOCOL_RS232 

use RS-232 as the Serial Protocol

◆ FLEX_SerialParity

Serial Interface - Parity Options.

Enumerator
FLEX_SERIAL_PARITY_NONE 

No parity for serial device.

FLEX_SERIAL_PARITY_EVEN 

Even parity for serial device.

FLEX_SERIAL_PARITY_ODD 

Odd parity for serial device.

◆ FLEX_SerialDatabits

Serial Interface - Databits Options.

Enumerator
FLEX_SERIAL_DATABITS_EIGHT 

Eight databits for serial device.

FLEX_SERIAL_DATABITS_NINE 

Nine databits for serial device.

◆ FLEX_SerialStopbits

Serial Interface - Stopbits Options.

Enumerator
FLEX_SERIAL_STOPBITS_ONE 

1 stopbits for serial device

FLEX_SERIAL_STOPBITS_HALF 

0.5 stopbits for serial device

FLEX_SERIAL_STOPBITS_ONEANDHALF 

1.5 stopbits for serial device

FLEX_SERIAL_STOPBITS_TWO 

2 stopbits for serial device

Function Documentation

◆ FLEX_SerialInit()

int FLEX_SerialInit ( FLEX_SerialProtocol Protocol,
uint32_t BaudRate )

Initialise the selected serial interface (RS-485 or RS-232).

Note
RS-485 and RS-232 cannot be initialised at the same time
De-initialise the Serial Interface before a job is completed to preserve device power.
Parameters
[in]Protocolrequired protocol for serial communication.
[in]BaudRaterequired baudrate.
Returns
FLEX_SUCCESS (0) if succeeded and < 0 if failed.
Return values
-FLEX_ERROR_EALREADYdevice already initialised
-FLEX_ERROR_IO_EXPANDERfailed to initialise or configure expander device
-FLEX_ERROR_SERIALfailed to initialise serial device
-FLEX_ERROR_POWER_OUTfailed to enable power to serial interface

◆ FLEX_SerialInitEx()

int FLEX_SerialInitEx ( const FLEX_SerialExOptions Options)

Initialise the selected serial interface (RS-485 or RS-232).

Note
RS-485 and RS-232 cannot be initialised at the same time
De-initialise the Serial Interface before a job is completed to preserve device power.
Parameters
[in]Optionsextended configuration options for serial protocol.
Returns
FLEX_SUCCESS (0) if succeeded and < 0 if failed.
Return values
-FLEX_ERROR_EALREADYdevice already initialised
-FLEX_ERROR_IO_EXPANDERfailed to initialise or configure expander device
-FLEX_ERROR_SERIALfailed to initialise serial device
-FLEX_ERROR_POWER_OUTfailed to enable power to serial interface

◆ FLEX_SerialWrite()

int FLEX_SerialWrite ( const uint8_t * Tx,
size_t Length )

Write to the serial interface synchronously.

Parameters
[in]Txpointer to the transmit buffer to be sent.
[in]Lengthlength of data to be sent.
Returns
FLEX_SUCCESS (0) if succeeded and < 0 if failed.
Return values
-FLEX_ERROR_NOT_INITdevice not initialised

◆ FLEX_SerialRead()

int FLEX_SerialRead ( uint8_t * Rx,
size_t Length )

Read from the input buffer of the serial interface. The buffer size is 50 bytes.

Parameters
[out]Rxpointer to the receive buffer.
[in]Lengthlength of the receive buffer.
Returns
number of bytes read back or < 0 if read failed.
Return values
-FLEX_ERROR_NOT_INITdevice not initialised

◆ FLEX_SerialDeinit()

int FLEX_SerialDeinit ( void )

De-initialise the serial interface.

Note
De-initialise the Serial Interface before a job is completed to preserve device power.
Returns
FLEX_SUCCESS (0) if succeeded and < 0 if failed.
Return values
-FLEX_ERROR_POWER_OUTfailed to disable power to serial interface