ModbusUtils.h 551 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef _GATEWAY_SCHEDULER_MODBUS_UTILS_H_
  2. #define _GATEWAY_SCHEDULER_MODBUS_UTILS_H_
  3. #include <modbus/modbus.h>
  4. #include <cstdint>
  5. #include <string>
  6. #include <vector>
  7. namespace server {
  8. namespace utils {
  9. class ModbusUtils {
  10. public:
  11. ModbusUtils();
  12. ~ModbusUtils();
  13. bool connect();
  14. bool disconnect();
  15. std::vector<uint16_t> read();
  16. private:
  17. std::string device;
  18. std::int32_t baudrate;
  19. bool parity;
  20. std::int32_t dataBits;
  21. std::int32_t stopBits;
  22. modbus_t *context;
  23. };
  24. } // namespace utils
  25. } // namespace server
  26. #endif