modbus slaver

Committer:
yao6116601
Date:
Tue Sep 17 01:59:40 2019 +0000
Revision:
0:998a68b8defc
modbus server

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yao6116601 0:998a68b8defc 1 /*
yao6116601 0:998a68b8defc 2 modbus comuunication class
yao6116601 0:998a68b8defc 3 By modular-2 team 2018/8/3
yao6116601 0:998a68b8defc 4 modbus mode=RTU master/salve
yao6116601 0:998a68b8defc 5 usage:
yao6116601 0:998a68b8defc 6 master mode:
yao6116601 0:998a68b8defc 7 sendQuery
yao6116601 0:998a68b8defc 8 waitResponse
yao6116601 0:998a68b8defc 9 salve mode:
yao6116601 0:998a68b8defc 10 waitQuery
yao6116601 0:998a68b8defc 11 sendResponse
yao6116601 0:998a68b8defc 12 */
yao6116601 0:998a68b8defc 13 #ifndef MODBUS_H
yao6116601 0:998a68b8defc 14 #define MODBUS_H
yao6116601 0:998a68b8defc 15 #include "mbed.h"
yao6116601 0:998a68b8defc 16 class Modbus
yao6116601 0:998a68b8defc 17 {
yao6116601 0:998a68b8defc 18 public:
yao6116601 0:998a68b8defc 19 Modbus(PinName tx, PinName rx,PinName txEnable, int baud);
yao6116601 0:998a68b8defc 20 bool sendQuery(uint8_t address,uint8_t function,uint16_t startAddress,uint16_t points);
yao6116601 0:998a68b8defc 21 int waitResponse(uint8_t *data);
yao6116601 0:998a68b8defc 22 bool waitQuery(uint8_t &address,uint8_t &function,uint16_t &startAddress,uint16_t &points);
yao6116601 0:998a68b8defc 23 bool sendResponse(uint8_t *data,uint8_t length);
yao6116601 0:998a68b8defc 24 private:
yao6116601 0:998a68b8defc 25 uint8_t sbuf[32];
yao6116601 0:998a68b8defc 26 uint8_t rbuf[32];
yao6116601 0:998a68b8defc 27 Serial rs485;
yao6116601 0:998a68b8defc 28 DigitalOut dir;
yao6116601 0:998a68b8defc 29 uint8_t _address;
yao6116601 0:998a68b8defc 30 uint8_t _function;
yao6116601 0:998a68b8defc 31 uint16_t _startAddress;
yao6116601 0:998a68b8defc 32 uint16_t _points;
yao6116601 0:998a68b8defc 33 unsigned int calculateCRC16( uint8_t *puchMsg,unsigned int usDataLen);
yao6116601 0:998a68b8defc 34 };
yao6116601 0:998a68b8defc 35 #endif