///////////////////////////////////////////////////////////////////////////////// // // modbus.h is part of TestModbus-Client. // ///////////////////////////////////////////////////////////////////////////////// #ifndef _MODBUS_H_ #define _MODBUS_H_ #include #include /* * this file will only contain the encoding and decoding functions */ struct { uint16_t transid; // transaction id uint16_t protid; // protocol id uint16_t length; // number of bytes followed uint8_t uid; // unit/slave id uint8_t fc; // function code uint16_t offset; // first register to read uint16_t number; // number of registers to read } typedef modbustcp_rq_header; struct { uint16_t transid; // transaction id uint16_t protid; // protocol id uint16_t length; // number of bytes followed uint8_t uid; // unit/slave id uint8_t fc; // function code uint8_t number; // number of registers to read } typedef modbustcp_res_header; char * modbustcp_pkt_headerrq (char *destbuffer, int bufsize, modbustcp_rq_header *srcmbh); char * modbustcp_unpkt_headerrq (modbustcp_rq_header *destmbh, char *srcbuffer, int bufsize); char * modbustcp_pkt_headerres (char *destbuffer, int bufsize, modbustcp_res_header *srcmbh); char * modbustcp_unpkt_headerres (modbustcp_res_header *destmbh, char *srcbuffer, int bufsize); #endif