Modbus Library Development Note IX: Using protocol stacks to develop Modbus TCP server applications

Source: Internet
Author: User

We have already completed the development of the Modbus protocol stack, but this is not our goal. The purpose of our development is of course to use it to solve our practical problems. Next we will use the newly developed Modbus protocol stack to develop a Modbus TCP server application.

The development of Modbus TCP server first needs to have TCP server support and network configuration, etc., but these have nothing to do with Modbus itself, we do not discuss again. We stipulate that the network and TCP server are configured properly. Next we discuss the implementation process of Modbus TCP server.

Based on the previous encapsulation of the protocol stack, we need to refer to the relevant encapsulation of Modbus TCP server. After the command is received, the parse function is called to parse, and the parse function is prototyped:

uint16_t Parsingclientaccesscommand (uint8_t *receivedmessage,uint8_t *respondbytes);

The function is passed to the TCP Server as a function pointer and the callback resolves the received list of information.

In addition, we need to implement 8 callback functions according to the specific needs to complete the operation of the Modbus object, the prototype of the 8 functions are as follows:

/* Get the value of the amount of coil you want to read */

void Getcoilstatus (uint16_t startaddress,uint16_t quantity,bool *statuslist);

/* Get the value of the amount of inputstatus you want to read */

void Getinputstatus (uint16_t startaddress,uint16_t quantity,bool *statusvalue);

/* Get the value of the hold register you want to read */

void Getholdingregister (uint16_t startaddress,uint16_t quantity,uint16_t *registervalue);

/* Get the value of the input register you want to read */

void Getinputregister (uint16_t startaddress,uint16_t quantity,uint16_t *registervalue);

/* Set the value of a single coil */

void Setsinglecoil (uint16_t coiladdress,bool coilvalue);

/* Set the value of a single register */

void Setsingleregister (uint16_t registeraddress,uint16_t registervalue);

/* Set values for multiple coils */

void Setmultiplecoil (uint16_t startaddress,uint16_t quantity,bool *statusvalue);

/* Set values for multiple registers */

void Setmultipleregister (uint16_t startaddress,uint16_t quantity,uint16_t *registervalue);

These 8 functions implement the operation of data objects according to the specific requirements of the application, and implement several methods to determine how to implement them according to their application requirements and data structures.

Modbus Library Development Note IX: Using protocol stacks to develop Modbus TCP server applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.