s7_plc.h 729 B

1234567891011121314151617181920212223242526272829303132
  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. {
  8. public:
  9. #define HTON(T) ((T) << 8) | ((T) >> 8)
  10. protected:
  11. bool bConnected_;
  12. std::mutex mutex_;
  13. TSnap7Client client_;
  14. public:
  15. S7PLC();
  16. ~S7PLC();
  17. bool connect(std::string ip);
  18. bool getConnection();
  19. bool ReadShorts(int DBNumber,int start,int size,short* pdata);
  20. bool WriteShorts(int DBNumber,int start,int size,short* pdata);
  21. void disconnect();
  22. private:
  23. bool read_dbs(int DBNumber,int start,int size,void* pdata);
  24. bool write_dbs(int DBNumber,int start,int size,void* pdata);
  25. void reverse_byte(void* pdata,int num_byte,void* out);
  26. };
  27. #endif // !S7__PLC__H