1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // Created by wk on 2022/12/6.
- //
- #ifndef PLC_SOCKET_TEST_PLC_SOCKET_H
- #define PLC_SOCKET_TEST_PLC_SOCKET_H
- #include <string.h>
- #include <string>
- #include <queue>
- #include "communication_socket.h"
- typedef void (*ReadCallback)(char*,void*);
- class Plc_socket
- {
- public:
- Plc_socket();
- virtual ~Plc_socket();
- public://API functions
- bool plc_socket_init(std::string ip, unsigned short port);//初始化
- void set_read_callback(ReadCallback rcb,void* client);//设置回调函数
- void write_data(std::string data);//写入PLC数据
- void plc_socket_uninit();//初始化
- private:
- //读取数据线程
- void read_plc_data_thread();
- //写入数据线程
- void write_plc_data_thread();
- //自动重连线程
- void reconnect_thread();
- private:
- Communication_socket m_socket; //socket
- ReadCallback m_read_callback; //接收数据回调
- void* client_= nullptr;
- std::string m_ip; //IP地址
- unsigned short m_port; //端口
- std::thread* mp_reconnect_thread; //重连线程
- bool m_reconnect_condition; //重连线程条件变量
- std::thread* mp_read_data_thread;//读取线程
- bool m_read_data_condition;//读取线程的条件变量
- std::thread* mp_write_data_thread; //写线程
- bool m_write_data_condition; //写线程条件变量
- std::queue<std::string> m_write_data_queue;//写入数据queue
- };
- #endif //PLC_SOCKET_TEST_PLC_SOCKET_H
|