dream888 发表于 2014-5-28 16:50:53

linux平台实现modbus主机协议栈的动态库libMbpoll

libMbopll动态库是面向linux平台设计的modbus主机协议栈,可以运行在x86平台以及各种嵌入式linux平台;协议栈提供了简单明了的API接口提供给程序员进行应用层modbus主机程序开发;
libMbopll库支持modbus协议所有功能码操作,兼容modbus tcp及modbus rtu;
#ifndef _Mbpoll_H
#define _Mbpoll_H
#include <stdint.h>
class cMbpoll
{
        private:
                void *mp;
                unsigned int gettickcount();
                unsigned int limittime;
                void checklimit(void);
        protected:
        public:
                void pollnewrtu(const char *device, int baud, char parity,int data_bit, int stop_bit);//Function modbus rtu new
                void pollnewtcp(const char *ip_address, int port);//Function modbus tcp new
                void poll_set_response_timeout(const struct timeval *timeout);//Function set response timeout
                int poll_set_slave(int slave);//Function set slave id

                int read_bits(int addr, int nb, uint8_t *dest);//Function 01 (01hex) Read Coils
                int read_input_bits(int addr, int nb, uint8_t *dest);//Function 02 (02hex) Read Discrete Inputs
                int read_registers(int addr, int nb, uint16_t *dest);//Function 03 (03hex) Read Holding Registers
                int read_input_registers(int addr, int nb, uint16_t *dest);//Function 04 (04hex) Read Input Registers
                int write_bit(int coil_addr, int status);//Function 05 (05hex) Write Single Coil
                int write_register(int reg_addr, int value);//Function 06 (06hex) Write Single Register
                int write_bits(int addr, int nb, const uint8_t *data);//Function 15 (0Fhex) Write Multiple Coils
                int write_registers(int addr, int nb, const uint16_t *data);//Function 16 (10hex) Write Multiple Registers
                int write_and_read_registers(int write_addr, int write_nb,const uint16_t *src, int read_addr, int read_nb,uint16_t *dest);//Function 23 (17hex) Read/Write multiple registers

                cMbpoll();
                ~cMbpoll();
};
#endif







页: [1]
查看完整版本: linux平台实现modbus主机协议栈的动态库libMbpoll