Skip to content
Savindra Kumar edited this page Jul 7, 2019 · 2 revisions

modbus-tcp-server Wiki

This code implements modbus tcp server application. This code is written so that user do not need to modify in the modbus-tcp-server application . User can pass the data and callback function at the time of initialisation only and then pass the query to process function and get the response .

There are below source and header files for modbus tcp server application:

  1. mbap.c(Implement modbus validation and parsing of modbus tcp query data)
  2. mbap.h(Contains macros and configuration for mbap.c)
  3. mbap_user.c(Implement user functions for reading/writing modbus data)
  4. mabp_user.h
  5. mbap_conf.h(Contains configuration for modbus tcp server application)
  6. mbap_debug.h(Control debug option for modbuss tcp server application)

Mutex or semaphore can be used in user defined functions implemented in mbap_user.c for thread safe environment. Definition of user defined functions should not be changed. Only the modbus data reading/writing code can be modify in user defined functions.

Supported Function Codes

  1. Read Coils
  2. Read Discrete Inputs
  3. Read Input Registers
  4. Read Holding Registers
  5. Write Single Coil
  6. Write Single Holding Registers
  7. Write Multiple Coils
  8. Write Multiple Holding Registers

Configure modbus-tcp-server

  1. This code can be configured by macros defined in mbap_conf.h and mbap_debug.h

  2. Each function code can be enable/disable by macro defined in mbap_conf.h Debug msg and warning can be controlled macros defined in mbap_debug.h by default printf is used as debug function for printing messages on console if any other function is used then it should replace the printf and studio.h header file should be replaced by user function header file.

  3. Modbus data should be initialized before using the modbus application. This should be done by passing ModbusData_t structure into mbap_DataInit function.

  4. Received query and length from tcp stack is passed into mbap_ProcessRequest function which gives response length and copies response into response buffer.

Clone this wiki locally