s7_plc.h 743 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef S7__PLC__H
  2. #define S7__PLC__H
  3. #include <s7_client.h>
  4. #include <mutex>
  5. #include <iostream>
  6. class S7PLC {
  7. public:
  8. #define HTON(T) ((T) << 8) | ((T) >> 8)
  9. protected:
  10. bool bConnected_;
  11. std::mutex mutex_;
  12. TSnap7Client client_;
  13. public:
  14. S7PLC();
  15. ~S7PLC();
  16. bool connect(std::string ip);
  17. bool getConnection();
  18. bool ReadShorts(int DBNumber, int start, int size, short *pdata);
  19. bool WriteShorts(int DBNumber, int start, int size, short *pdata);
  20. void disconnect();
  21. private:
  22. bool read_dbs(int DBNumber, int start, int size, void *pdata);
  23. bool write_dbs(int DBNumber, int start, int size, void *pdata);
  24. void reverse_byte(void *pdata, int num_byte, void *out);
  25. };
  26. #endif // !S7__PLC__H