老 姚
/
modbusServer2
modbus for modular2_dio10
Embed:
(wiki syntax)
Show/hide line numbers
modbus.h
00001 /* 00002 modbus comuunication class 00003 By modular-2 team 2018/8/3 00004 modbus mode=RTU master/salve 00005 usage: 00006 master mode: 00007 sendQuery 00008 waitResponse 00009 salve mode: 00010 waitQuery 00011 sendResponse 00012 */ 00013 #ifndef MODBUS_H 00014 #define MODBUS_H 00015 #include "mbed.h" 00016 class Modbus 00017 { 00018 public: 00019 Modbus(PinName tx, PinName rx,PinName txEnable, int baud); 00020 bool sendQuery(uint8_t address,uint8_t function,uint16_t startAddress,uint16_t points); 00021 int waitResponse(uint8_t *data); 00022 bool waitQuery(uint8_t &address,uint8_t &function,uint16_t &startAddress,uint16_t &points); 00023 bool sendResponse(uint8_t *data,uint8_t length); 00024 private: 00025 uint8_t sbuf[32]; 00026 uint8_t rbuf[32]; 00027 Serial rs485; 00028 DigitalOut dir; 00029 uint8_t _address; 00030 uint8_t _function; 00031 uint16_t _startAddress; 00032 uint16_t _points; 00033 unsigned int calculateCRC16( uint8_t *puchMsg,unsigned int usDataLen); 00034 }; 00035 #endif
Generated on Fri Jul 22 2022 07:37:52 by 1.7.2