GaIA BIOS Library
Loading...
Searching...
No Matches
modbus.h File Reference

Modbus interface to the application. More...

#include <stdint.h>
#include <modbus_core/modbus_types.h>

Data Structures

struct  mb_pdu_t
 Represents a modbus Protocol Data Unit (PDU). More...
struct  mb_data_handlers_t
 This structure contains pointers to data handlers. More...
struct  mb_info_t
 Contains information for message processing. More...

Macros

#define MODBUS_MAX_PDU_DATA_SIZE   (252)
 Maximum size of data field in a modbus PDU including checksum.
#define ADR_BROADCAST   (0x00)
 Broadcast address for modbus messages.
#define MSG_RECEIVED   (2)
 Modbus message received.
#define MSG_TIMEOUT   (3)
 Modbus message not received within timeout.
#define MB_JBUS   (1)
 Jbus mode.
#define MB_MODBUS   (0)
 Modbus mode.
#define MB_FC_READ_COILS   (0x01)
 Modbus function code for reading coils.
#define MB_FC_READ_DISCRETE_INPUTS   (0x02)
 Modbus function code for reading discrete inputs.
#define MB_FC_READ_HOLD_REGISTERS   (0x03)
 Modbus function code for reading holding registers.
#define MB_FC_READ_INPUT_REGISTERS   (0x04)
 Modbus function code for reading input registers.
#define MB_FC_WRITE_SINGLE_COIL   (0x05)
 Modbus function code for writing a single coil.
#define MB_FC_WRITE_SINGLE_REGISTER   (0x06)
 Modbus function code for writing a single register.
#define MB_FC_WRITE_MULTI_COILS   (0x0F)
 Modbus function code for writing multiple coils.
#define MB_FC_WRITE_MULTI_REGISTERS   (0x10)
 Modbus function code for writing multiple registers.
#define MB_RC_OK   (0)
 No errors.
#define MB_RC_NO_RESPONSE   (-1)
 No response within timeout.
#define MB_RC_ERR_BYTE_COUNT   (-2)
 No response error in response length.

Functions

uint8_t mb_is_func_supported (uint8_t function_code)
 Checks if the function identified by the given number is supported.
uint8_t mb_process_pdu (mb_pdu_t *req_pdu, mb_pdu_t *resp_pdu, mb_info_t *info)
 Processes a modbus PDU and creates the corresponding response if it is necessary.
void mb_queue_byte (uint8_t val, mb_pdu_t *pdu)
 Writes a byte in the message.
void mb_queue_word (uint16_t val, mb_pdu_t *pdu)
 Writes a word in the message.

Detailed Description

Modbus interface to the application.

Author
Tecnologix, 2014

Function Documentation

◆ mb_is_func_supported()

uint8_t mb_is_func_supported ( uint8_t function_code)

Checks if the function identified by the given number is supported.

Parameters
function_codenumber corresponding to the function to test the support for.
Returns
0 if the function corresponding to the given function code is unsupported.

◆ mb_process_pdu()

uint8_t mb_process_pdu ( mb_pdu_t * req_pdu,
mb_pdu_t * resp_pdu,
mb_info_t * info )

Processes a modbus PDU and creates the corresponding response if it is necessary.

Parameters
[in]req_pdumodbus PDU to process.
[out]resp_pduresponse PDU. It can be a response PDU or an exception PDU.
[in]infoinformations needed to process the message.
Returns
MB_NOERROR if everything was ok, an error code otherwise.

◆ mb_queue_byte()

void mb_queue_byte ( uint8_t val,
mb_pdu_t * pdu )

Writes a byte in the message.

Parameters
valbyte to write.
pdupointer to the pdu.

◆ mb_queue_word()

void mb_queue_word ( uint16_t val,
mb_pdu_t * pdu )

Writes a word in the message.

Parameters
valbyte to write.
pdupointer to the pdu.