LibmodbusWrapper.h 975 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <stdio.h>
  3. #include <errno.h>
  4. #include <string>
  5. #include <string.h>
  6. #include "modbus.h"
  7. namespace modbus
  8. {
  9. class CLibmodbusWrapper
  10. {
  11. public:
  12. CLibmodbusWrapper();
  13. virtual ~CLibmodbusWrapper();
  14. int initialize(const char *ip, int port, int slave_id);
  15. void deinitialize();
  16. public:
  17. int read_registers(int addr, int nb, uint16_t *dest);
  18. int write_registers(int addr, int nb, uint16_t *dest);
  19. int read_register(int addr, uint16_t *dest);
  20. int write_register(int addr, uint16_t *dest);
  21. inline bool is_connected() { return (0 == _ctx) ? false : true; };
  22. inline std::string getIP() { return _ip; };
  23. inline int getPort() { return _port; };
  24. inline int getSlave() { return _slave_id; };
  25. private:
  26. modbus_t* _ctx;
  27. private:
  28. std::string _ip;
  29. int _port;
  30. int _slave_id;
  31. };
  32. };