Symbols
loading...
Files
loading (2/5)...

mb_slave sample sample

mb_slave sample is a sample project defining the following symbols:

Most used functions

Name
Location
Summary
This function is wait for modbus master request finish and return result. Waiting result include request process success, request respond timeout, receive data error and execute function error.You can use the above callback function.
This function is take Mobus Master running resource. Note:The resource is define by Operating System.
Function to set bits in a byte buffer. This function allows the efficient use of an array to implement bitfields. The array used for storing the bits must always be a multiple of two bytes. Up to eight bits can be set or cleared in one operation.
ucBits[2] = {0, 0}; // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1) xMBUtilSetBits( ucBits, 4, 1, 1 ); // Set bit 7 to 1 and bit 8 to 0. xMBUtilSetBits( ucBits, 7, 2, 0x01 ); // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A; xMBUtilSetBits( ucBits, 8, 8, 0x5A);
This is modbus master user error handling funcion. If it is defined in the user application, then helps to handle the errors and received/sent buffers to transfer as well as handle the slave exception codes.
Function to read bits in a byte buffer. This function is used to extract up bit values from an array. Up to eight bit values can be extracted in one step.
UCHAR ucBits[2] = {0, 0}; UCHAR ucResult; // Extract the bits 3 - 10. ucResult = xMBUtilGetBits( ucBits, 3, 8 );
Callback function used if a Holding Register value is read or written by the protocol stack. The starting register address is given by \c usAddress and the last register is given by usAddress + usNRegs - 1.
Callback function used if a Holding Register value is read or written by the protocol stack. The starting register address is given by \c usAddress and the last register is given by usAddress + usNRegs - 1.
The helper function to set data of parameters according to its type
Callback function used if a Coil Register value is read or written by the protocol stack. If you are going to use this function you might use the functions xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
Callback function used if a Coil Register value is read or written by the protocol stack. If you are going to use this function you might use the functions xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
Initialize Modbus Master controller interface handle
This function will request read discrete inputs.
This function is release Modbus Master running resource. Note:The resource is define by Operating System. If you not use OS this function can be empty.
Release resources used by the protocol stack. This function disables the Modbus Master protocol stack and release all hardware resources. It must only be called when the protocol stack is disabled.
Enable the Modbus Master protocol stack. This function enables processing of Modbus Master frames. Enabling the protocol stack is only possible if it is in the disabled state.
Disable the Modbus Master protocol stack. This function disables processing of Modbus frames.
The main pooling loop of the Modbus Master protocol stack. This function must be called periodically. The timer interval required is given by the application dependent Modbus slave timeout. Internally the function calls xMBMasterPortEventGet() and waits for an event from the receiver or transmitter state machines.
This function will request read input register.
This function will request write holding register.
This function will request write multiple holding register.
This function will request read holding register.
This function will request read and write holding register.
This function will request read coil.
This function will request write one coil. @see eMBMasterReqWriteMultipleCoils
This function will request write multiple coils. @see eMBMasterReqWriteCoil
Enable the Modbus protocol stack. This function enables processing of Modbus frames. Enabling the protocol stack is only possible if it is in the disabled state.
Disable the Modbus protocol stack. This function disables processing of Modbus frames.
The main pooling loop of the Modbus protocol stack. This function must be called periodically. The timer interval required is given by the application dependent Modbus slave timeout. Internally the function calls xMBPortEventGet() and waits for an event from the receiver or transmitter state machines.
Initialize Modbus Slave controller interface handle
Initialize Modbus controller and stack
Initialize Modbus controller and stack for TCP slave
Create Modbus Master controller and stack for TCP port
Callback function used if a Input Discrete Register value is read by the protocol stack. If you are going to use his function you might use the functions xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
#include "mb_m.h"
The protocol stack does not internally allocate any memory for the registers. This makes the protocol stack very small and also usable on low end targets. In addition the values don't have to be in the memory and could for example be stored in a flash. Whenever the protocol stack requires a value it calls one of the callback function with the register address and the number of registers to read as an argument. The application should then read the actual register values (for example the ADC voltage) and should store the result in the supplied buffer. If the protocol stack wants to update a register value because a write register function was received a buffer with the new register values is passed to the callback function. The function should then use these values to update the application register values. The common callback function used to transfer common data as bytes from command buffer in little endian format.
Callback function used if the value of a Input Register is required by the protocol stack. The starting register address is given by \c usAddress and the last register is given by usAddress + usNRegs - 1.
This is modbus master respond timeout error process callback function.
This is modbus master receive data error process callback function.
This is modbus master execute function error process callback function.
This is modbus master request process success callback function.
Initialize the Modbus Master protocol stack. This functions initializes the ASCII or RTU module and calls the init functions of the porting layer to prepare the hardware. Please note that the receiver is still disabled and no Modbus frames are processed until eMBMasterEnable( ) has been called.
Initialize the Modbus Master protocol stack for Modbus TCP. This function initializes the Modbus TCP Module. Please note that frame processing is still disabled until eMBEnable( ) is called.
These Modbus functions are called for user when Modbus run in Master Mode.
Initialize the Modbus protocol stack. This functions initializes the ASCII or RTU module and calls the init functions of the porting layer to prepare the hardware. Please note that the receiver is still disabled and no Modbus frames are processed until eMBEnable( ) has been called.
Initialize the Modbus protocol stack for Modbus TCP. This function initializes the Modbus TCP Module. Please note that frame processing is still disabled until eMBEnable( ) is called.
Release resources used by the protocol stack. This function disables the Modbus protocol stack and release all hardware resources. It must only be called when the protocol stack is disabled.
Configure the slave id of the device. This function should be called when the Modbus function Report Slave ID is enabled ( By defining MB_FUNC_OTHER_REP_SLAVEID_ENABLED in mbconfig.h ).
#include "mb.h"
The protocol stack does not internally allocate any memory for the registers. This makes the protocol stack very small and also usable on low end targets. In addition the values don't have to be in the memory and could for example be stored in a flash. Whenever the protocol stack requires a value it calls one of the callback function with the register address and the number of registers to read as an argument. The application should then read the actual register values (for example the ADC voltage) and should store the result in the supplied buffer. If the protocol stack wants to update a register value because a write register function was received a buffer with the new register values is passed to the callback function. The function should then use these values to update the application register values. Callback function used if the value of a Input Register is required by the protocol stack. The starting register address is given by \c usAddress and the last register is given by usAddress + usNRegs - 1.
Callback function used if a Input Discrete Register value is read by the protocol stack. If you are going to use his function you might use the functions xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
Function to setup communication options for TCP/UDP Modbus port
Keeps FSM event handle and mask then wait for Master stack to start
Set network options for Master port
Read parameter from modbus slave device whose name is defined by name and has cid. The additional data for request is taken from parameter description (lookup) table.
Start Modbus communication stack
Set Modbus communication parameters for the controller
Destroy Modbus controller and stack
Wait for specific event on parameter change.
Specific interface functions ******************************************** Interface functions below provide basic methods to read/write access to slave devices in Modbus segment as well as API to read specific supported characteristics linked to Modbus parameters of devices in Modbus network. Assign parameter description table for Modbus controller interface.
Set characteristic's value defined as a name and cid parameter. The additional data for cid parameter request is taken from master parameter lookup table.
Set Modbus communication parameters for the controller
Start Modbus communication stack
Get information about supported characteristic defined as cid. Uses parameter description table to get this information. The function will check if characteristic defined as a cid parameter is supported and returns its description in param_info. Returns ESP_ERR_NOT_FOUND if characteristic is not supported.
Destroy Modbus controller and stack
Initialize Modbus Slave controller and stack for Serial port
Initialize Modbus controller and stack for TCP port
Initialize Modbus Master controller and stack for Serial port
Initialize Modbus Slave controller and stack for TCP port
Send data request as defined in parameter request, waits response from slave and returns status of command execution. This function provides standard way for read/write access to Modbus devices in the network.
The helper function to expose transaction info from modbus layer
Registers a callback handler for a given function code. This function registers a new callback handler for a given function code. The callback handler supplied is responsible for interpreting the Modbus PDU and the creation of an appropriate response. In case of an error it should return one of the possible Modbus exceptions which results in a Modbus exception frame sent by the protocol stack.
Modbus master coils callback function.
Modbus master discrete callback function.
Modbus master input register callback function.
Modbus master holding register callback function.
Modbus master holding register callback function.
Modbus master coils callback function.
Modbus master discrete callback function.
Modbus master input register callback function.
Registers a callback handler for a given function code. This function registers a new callback handler for a given function code. The callback handler supplied is responsible for interpreting the Modbus PDU and the creation of an appropriate response. In case of an error it should return one of the possible Modbus exceptions which results in a Modbus exception frame sent by the protocol stack.

Other commonly used symbols

Name
Location
Summary
Offset for response data in PDU.
Socket ID of slave
Modbus controller handler structure
Characteristics descriptor type is used to describe characteristic and link it with Modbus parameters that reflect its data.
Modbus controller handler structure
TCP/UDP IP address
Modbus register request type structure
Device communication structure to setup Modbus controller
Offset of function code in PDU.
Modbus area descriptor list item
ID of the transaction
protocol stack in illegal state.
Characteristic cid
Slave information index
Modbus slave addr list item for the master
Modbus slave options
Pointers to information about connected clients
Parameter access event information type
I/O error.
Most modules in the protocol stack are completly optional and can be excluded. This is specially important if target resources are very small and program memory space should be saved. All of these settings are available in the file mbconfig.h
controller event group
Update register values.
illegal argument.
Modbus controller interface structure
communication info
Modbus controller semaphore
illegal register address.
master is busy now.
Request mode for parameter to use in data dictionary
buffer active position
The key (name) of the parameter
Modbus controller event group
Master information structure for each connected slave
The total slaves in Modbus Master system.
Transaction start flag
Read register values and pass to protocol stack.
illegal argument.
porting layer error.
Modbus communication info
Modbus data buffer pointer
Modbus data buffer size
controller notification queue
Parameter storage area descriptor
Modbus controller parameter description table
Write parameter values.
Size of mb parameter in registers
Client connection count
Receive buffer pointer
Master count of connected slaves
Modbus task handle
Transaction identifier (TID) for slave
Modbus Holding register.
Float, U8, U16, U32, ASCII, etc.
Modbus Input register.
Character for high nibble of byte.
Request process success.
Request receive data error.
Request execute function error.
No error, initial state.
Modbus start address for area descriptor
register area descriptors
TCP/UDP IP address (string)
Receive buffer position
Receiver is in idle state.
Receive frame data error.
Modbus controller parameter description table size
Interface method destroy
Interface method setup
Interface method start
Interface get_cid_info method
Interface get_parameter method
Interface send_request method
Interface set_descriptor method
Interface set_parameter method
Stack callback discrete rw method
Stack callback input rw method
Stack callback holding rw method
Stack callback coils rw method
Maximum number of Modbus functions codes the protocol stack should support. The maximum number of supported Modbus functions must be greater than the sum of all enabled functions in this file and custom function handlers. If set to small adding more functions will fail.
Interface method destroy
Interface method setup
Interface method start
Interface method check_event
Interface method get_param_info
buffer left bytes to receive transaction
Socket receive error
Send request time stamp
Master connection queue
Number of bytes in the parameter.
Type of storage area descriptor
Slave address information list
Modbus command to send
Modbus transacion info structure
Instance address for storage area descriptor
last TID counter from packet
Master current slave information
Modbus event type
TCP communication mode.
Offset of Modbus-PDU in Ser-PDU.
Modbus start address for area descriptor
Slave respond timeout.
Device communication parameters for master
Slave address of device in the Modbus segment
TCP IPV4 addressing
event itself.
If master send a frame which is not broadcast,the master will wait sometime for slave. And if slave is not respond in this time,the master will process this timeout error.
Device communication parameters for master
Interface method set_descriptor
Stack callback discrete rw method
Stack callback input rw method
Stack callback holding rw method
Stack callback coils rw method
receive response timestamp
Protocol type used by port
Receive response time stamp
the characteristic of the device are readable & writable & triggerable
Receiver is in idle state.
TCP IPV4 addressing
Frame is beeing received.
Character for low nibble of byte.
Maximum size of a Modbus frame.
Offset of slave address in Ser-PDU.
Instance address for storage area descriptor
Instance size for area descriptor (bytes)
Callback function for the porting layer when a new byte is available. Depending upon the mode this callback function is used by the RTU or ASCII transmission layers. In any case a call to xMBPortSerialGetByte() must immediately return a new character.
The slave address entry
Interface method init
RTU transmission mode.
Modbus slave address
Modbus start register
Modbus number of registers
Modbus parameter options for description table
illegal register address.
timeout error occurred.
Transaction information structure.
The macro to access arrays of elements for type conversion.
Number of bytes which should be allocated for the Report Slave ID command. This number limits the maximum size of the additional segment in the report slave id function. See eMBSetSlaveID( ) for more information on how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED is set to 1.
Interface method init
Master TCP/UDP handling task handle
represents the IP address of the slave
Modbus data storage address
Modbus Event Read Holding registers.
Modbus Event Read Input registers.
Modbus Event Read Coils.
Modbus Event Read Discrete bits.
Startup finished.
Type of modbus parameter
Modbus port type serial slave.
Modbus port type serial master.
Transmitter is in idle state.
Timestamp of Modbus Event (uS)
Modbus register offset
Modbus event register size (number of registers)
Modbus Event Write Holding registers.
Modbus Event Write Coils.
Execute function.
ASCII transmission mode.
Short slave address
Interface method set_descriptor
Read parameter values.
Modbus communication mode
the characteristic of the device are triggerable
Execute function error.
No error, processing completed.
timestamp of event posted
TCP mode.
receive data error.
execute function error.
The option is required for support of RTU over TCP.
Modbus communication mode
The Modbus area descriptor entry
Modbus info index
TCP/UDP port number
IP address to bind
IP protocol version
Master current processing slave index
index of the address info
Parameter options used to check limits and etc.
Receiver is in idle state.
Transmitter is in idle state.
ASCII transmission mode.
The physical units of the parameter
Parameter name (OFFSET in the parameter structure)
If the frame is invalid.
Transmitter is in idle state.
Default CR character for Modbus ASCII.
Transmitter is in transfer finish and wait receive state.
Startup finished.
Master sent broadcast ,then delay sometime.
RTU transmission mode.
Modbus UART parity settings
Index of the slave address
IP address string of the slave
Modbus port type
Modbus communication port (UART) number
Modbus port type TCP master.
Modbus port type TCP slave.
TCP IPV6 addressing
common interface method types Interface method init
Interface method destroy
This is the Modbus register address. This is the 0 based value.
the characteristic of the device are readable
the characteristic of the device are writable
Interface method setup
Interface method start
TCP IPV6 addressing
Execute function.
Master wait respond for slave.
insufficient resources.
Slave address field
Modbus communication port (UART) number
Modbus UART parity settings
Instance size for area descriptor (bytes)
send request timestamp
Network netif interface pointer for port
Slave short address
Master TCP/UDP port number
Master IP version
Master netif interface pointer
slave unit ID (UID) field for MBAP frame
Wait for End of Frame.
Transmitter is in transfer finish and wait receive state.
If the frame is invalid.
Receiver is in initial state.
Frame is beeing received.
If the frame is invalid.
Transmitter is in transfer state.
Master receive frame T3.5 timeout.
Modbus communication mode
Frame is beeing received.
Wait for End of Frame.
Starting transmission (':' sent).
Sending of data (Address, Data, LRC).
End of transmission.
Notify sender that the frame has been sent.
Receiver is in initial state.
Size of LRC field in PDU.
Size of CRC field in PDU.
Default LF character for Modbus ASCII.
Minimum size of a Modbus ASCII frame.
pointer to data structure
Interface get_cid_info method
Interface get_parameter method
Interface send_request method
Interface set_parameter method
Modbus unique transaction identificator
Modbus last transaction error type
Modbus destination short address (or UID)
Modbus last transaction function code
Modbus last transaction exception code returned by slave
the characteristic of the device are readable & writable
timestamp of event get
timeout error occurred.
If master send a broadcast frame, the master will wait time of convert to delay,
Type of storage area descriptor
Interface method get_param_info
Constants which defines the format of a modbus frame. The example is shown for a Modbus RTU/ASCII frame. Note that the Modbus PDU is not dependent on the underlying transport. +-----------+---------------+----------------------------+-------------+ | Address | Function Code | Data | CRC/LRC | +-----------+---------------+----------------------------+-------------+ | | | | (2) (3/2') (3') (4) (1) ... MB_SER_PDU_SIZE_MAX = 256 (2) ... MB_SER_PDU_ADDR_OFF = 0 (3) ... MB_SER_PDU_PDU_OFF = 1 (4) ... MB_SER_PDU_SIZE_CRC = 2 (1') ... MB_PDU_SIZE_MAX = 253 (2') ... MB_PDU_FUNC_OFF = 0 (3') ... MB_PDU_DATA_OFF = 1 Maximum size of a PDU.
TCP/UDP sock error
Master protocol type
Modbus communication mode
Modbus communication port (UART) number
Modbus UART parity settings
This option defines the number of data bits per ASCII character. A parity bit is added before the stop bit which keeps the actual byte size at 10 bits.
The character timeout value for Modbus ASCII. The character timeout value is not fixed for Modbus ASCII and is therefore a configuration option. It should be set to the maximum expected delay time of the network.
Starting transmission (':' sent).
Sending of data (Address, Data, LRC).
End of transmission.
Notify sender that the frame has been sent.
Receiver is in initial state.
Transmitter is in transfer state.
Minimum size of a Modbus RTU frame.
Minimum size of a Modbus RTU frame.
Modbus address table for connection
Modbus network interface
Modbus slave address field (dummy for master)
Modbus baudrate
UDP communication mode.
the characteristic of the device are readable & triggerable
the characteristic of the device are writable & triggerable
Access permissions based on mode
Double GHEFCDAB floating point, big endian, reversed register order
Double BADCFEHG floating point, little endian, reversed register order
Unsigned 8, register value
Signed 8, register value
Signed integer 64 size
Unsigned integer 64 size
I8 signed integer in high byte of register
I8 signed integer in low byte of register
U8 unsigned integer written to hi byte of register
U8 unsigned integer written to low byte of register
I16 signed integer, big endian
I16 signed integer, little endian
U16 unsigned integer, big endian
U16 unsigned integer, little endian
I32 ABCD signed integer, big endian
I32 CDAB signed integer, big endian, reversed register order
I32 BADC signed integer, little endian, reversed register order
I32 DCBA signed integer, little endian
U32 ABCD unsigned integer, big endian
U32 CDAB unsigned integer, big endian, reversed register order
U32 BADC unsigned integer, little endian, reversed register order
U32 DCBA unsigned integer, little endian
Float ABCD floating point, big endian
Float CDAB floating point big endian, reversed register order
Float BADC floating point, little endian, reversed register order
Float DCBA floating point, little endian
I64, ABCDEFGH signed integer, big endian
I64, HGFEDCBA signed integer, little endian
I64, GHEFCDAB signed integer, big endian, reversed register order
I64, BADCFEHG signed integer, little endian, reversed register order
U64, ABCDEFGH unsigned integer, big endian
U64, HGFEDCBA unsigned integer, little endian
U64, GHEFCDAB unsigned integer, big endian, reversed register order
U64, BADCFEHG unsigned integer, little endian, reversed register order
Double ABCDEFGH floating point, big endian
Double HGFEDCBA floating point, little endian
#include "mb.h"
This module defines the interface for the application. It contains the basic functions and types required to use the Modbus protocol stack. A typical application will want to call eMBInit() first. If the device is ready to answer network requests it must then call eMBEnable() to activate the protocol stack. In the main loop the function eMBPoll() must be called periodically. The time interval between pooling depends on the configured Modbus timeout. If an RTOS is available a separate task should be created and the task should always call the function eMBPoll().
// Initialize protocol stack in RTU mode for a slave with address 10 = 0x0A eMBInit( MB_RTU, 0x0A, 38400, MB_PAR_EVEN ); // Enable the Modbus Protocol Stack. eMBEnable( ); for( ;; ) { // Call the main polling loop of the Modbus protocol stack. eMBPoll( ); ... }
Use the default Modbus TCP port (502)
#include "mb.h"
This module defines the interface for the application. It contains the basic functions and types required to use the Modbus Master protocol stack. A typical application will want to call eMBMasterInit() first. If the device is ready to answer network requests it must then call eMBEnable() to activate the protocol stack. In the main loop the function eMBMasterPoll() must be called periodically. The time interval between pooling depends on the configured Modbus timeout. If an RTOS is available a separate task should be created and the task should always call the function eMBMasterPoll().
// Initialize protocol stack in RTU mode for a Master eMBMasterInit( MB_RTU, 38400, MB_PAR_EVEN ); // Enable the Modbus Protocol Stack. eMBMasterEnable( ); for( ;; ) { // Call the main polling loop of the Modbus Master protocol stack. eMBMasterPoll( ); ... }
Use the default Modbus Master TCP port (502)
Modbus baudrate
TCP/UDP port number
Modbus slave address field for UID
Parameter option1
Parameter option2
Parameter option3
Parameter minimum value
Parameter maximum value
Step of parameter change tracking

Dependencies