奥特QT DDS 插件库
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #ifdef _WIN32
  3. #ifdef SNAP7_EXPORTS
  4. #define S7API __declspec(dllexport)
  5. #else
  6. #define S7API __declspec(dllimport)
  7. #endif
  8. #else
  9. #define S7API
  10. #endif
  11. #include <snap7.h>
  12. class PLCController {
  13. public:
  14. PLCController() : client_(nullptr), connected_(false) {
  15. client_ = new TS7Client();
  16. }
  17. ~PLCController() {
  18. if (client_) {
  19. if (connected_) {
  20. client_->Disconnect();
  21. }
  22. delete client_;
  23. }
  24. }
  25. bool connect(const char* ip = "192.168.0.1", int rack = 0, int slot = 1) {
  26. int result = client_->ConnectTo(ip, rack, slot);
  27. connected_ = (result == 0);
  28. return connected_;
  29. }
  30. bool readDB(int dbNumber, int start, int size, void* buffer) {
  31. if (!connected_) return false;
  32. int result = client_->DBRead(dbNumber, start, size, buffer);
  33. return (result == 0);
  34. }
  35. bool writeDB(int dbNumber, int start, int size, void* buffer) {
  36. if (!connected_) return false;
  37. int result = client_->DBWrite(dbNumber, start, size, buffer);
  38. return (result == 0);
  39. }
  40. private:
  41. TS7Client* client_;
  42. bool connected_;
  43. };