|
@@ -10,7 +10,7 @@ Snap7_communication_base::Snap7_communication_base()
|
|
|
m_communication_status = SNAP7_COMMUNICATION_UNKNOWN;
|
|
|
m_communication_delay_time_ms = SNAP7_COMMUNICATION_DELAY_TIME_MS;
|
|
|
mp_communication_thread = NULL;
|
|
|
-
|
|
|
+ m_error_count = 0;
|
|
|
}
|
|
|
|
|
|
Snap7_communication_base::~Snap7_communication_base()
|
|
@@ -21,7 +21,7 @@ Snap7_communication_base::~Snap7_communication_base()
|
|
|
//初始化 通信 模块。如下三选一
|
|
|
Error_manager Snap7_communication_base::communication_init()
|
|
|
{
|
|
|
- return communication_init_from_protobuf(SNAP7_COMMUNICATION_PARAMETER_PATH);
|
|
|
+ return communication_init_from_protobuf(SETTING_PATH SNAP7_COMMUNICATION_PARAMETER_PATH);
|
|
|
}
|
|
|
//初始化 通信 模块。从文件读取
|
|
|
Error_manager Snap7_communication_base::communication_init_from_protobuf(std::string prototxt_path)
|
|
@@ -125,6 +125,13 @@ Error_manager Snap7_communication_base::set_communication_delay_time_ms(int time
|
|
|
return Error_code::SUCCESS;
|
|
|
}
|
|
|
|
|
|
+//修改状态
|
|
|
+Error_manager Snap7_communication_base::set_snap7_communication_statu(Snap7_communication_base::Snap7_communication_statu statu)
|
|
|
+{
|
|
|
+ m_communication_status = statu;
|
|
|
+ return Error_code::SUCCESS;
|
|
|
+}
|
|
|
+
|
|
|
//通信连接
|
|
|
Error_manager Snap7_communication_base::communication_connect(std::string ip_string)
|
|
|
{
|
|
@@ -198,6 +205,17 @@ Error_manager t_error;
|
|
|
//接受数据, 读取DB块,
|
|
|
t_error = read_data_buf(iter->second);
|
|
|
if (t_error == Error_code::SNAP7_READ_ERROR)
|
|
|
+ {
|
|
|
+ m_error_count++;
|
|
|
+ LOG(INFO) << "find plc connection error, error_conut = "<< m_error_count;
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ m_error_count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( m_error_count >= SNAP7_COMMUNICATION_ERROR_COUNT_MAX )
|
|
|
{
|
|
|
m_communication_status = SNAP7_COMMUNICATION_DISCONNECT;
|
|
|
std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
|
|
@@ -226,6 +244,17 @@ Error_manager t_error;
|
|
|
//发送数据, 写入DB块,
|
|
|
t_error = write_data_buf(iter->second);
|
|
|
if (t_error == Error_code::SNAP7_WRITE_ERROR)
|
|
|
+ {
|
|
|
+ m_error_count++;
|
|
|
+ LOG(INFO) << "find plc connection error, error_conut = "<< m_error_count;
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ m_error_count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( m_error_count >= SNAP7_COMMUNICATION_ERROR_COUNT_MAX )
|
|
|
{
|
|
|
m_communication_status = SNAP7_COMMUNICATION_DISCONNECT;
|
|
|
std::cout << " huli test :::: " << " t_error = " << t_error << std::endl;
|