API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
ModBUS

Modules

 Port
 
 Master
 
 Slave
 

Detailed Description

This is the Modbus communication stack for the TSmarT platform

The stack works with the following interfaces in both master/slave modes:

After porting initialization, an instance must be created for each required mode in the system. See:

In case of slave mode, function handlers must be registered within the stack. These handlers are called when a Modbus request is received. There are four standard handlers (one for each Modbus function):

More information about Modbus at:

Serial Modbus

Modbus stack can be configured to be used with a serial interface (e.g. Rs485) in RTU.

In order to use the serial mode, Modbus porting layer must be previously initialized (see vMBPInit). After porting initialization, use the function eMBMSerialInit or eMBSSerialInit to create the serial instance.

Modbus RTU Slave

Serial slave is initialized using the function eMBSSerialInit. After initialization and callback registration, the slave task must poll the Modbus stack for incoming requests. This is an example of polling loop:

* // Modbus polling loop
* for (;;) {
* // Poll the communication stack
* eStatus = eMBSPoll(MBSHandle);
* if (eStatus != MB_ENOERR) {
* // Handle error and exit loop
* break;
* }
* }
*

Modbus RTU Master

Serial Master is initialized using the function eMBMSerialInit. After initialization, remote nodes may be accessed using the functions:

An example of accessing coils at addresses 0x0000 to 0x0002 in node 0x01:

* // Main task loop
* for (;;) {
* for (i=0 ; i<3 ; i++) {
* eStatus = eMBMWriteSingleCoil(MBMHandle, 0x01, i, TRUE);
* if (eStatus != MB_ENOERR) {
* // Handle error
* }
* eStatus = eMBMReadCoils(MBMHandle, 0x01, i, 1, data);
* if (eStatus != MB_ENOERR) {
* // Handle error
* }
* eStatus = eMBMWriteSingleCoil(MBMHandle, 0x01, i, FALSE);
* if (eStatus != MB_ENOERR) {
* // Handle error
* }
* eStatus = eMBMReadCoils(MBMHandle, 0x01, i, 1, data);
* if (eStatus != MB_ENOERR) {
* // Handle error
* }
* }
* mdelay(1000);
* }
*