|
@@ -247,17 +247,16 @@ void Plc_Communicator::plc_update_thread(Plc_Communicator *plc_communicator)
|
|
|
while (!plc_communicator->m_plc_cond_exit.WaitFor(100))
|
|
|
{
|
|
|
// std::cout<<" thread 000 "<<std::endl;
|
|
|
- plc_communicator->m_plc_mutex.lock();
|
|
|
- plc_communicator->mb_plc_is_connected = plc_communicator->m_plc_wrapper.is_connected();
|
|
|
- plc_communicator->m_plc_mutex.unlock();
|
|
|
- // 判断是否初始化完成
|
|
|
- if (!plc_communicator->mb_plc_initialized)
|
|
|
- continue;
|
|
|
+
|
|
|
// 断线重连
|
|
|
if (!plc_communicator->mb_plc_is_connected)
|
|
|
{
|
|
|
- plc_communicator->connect();
|
|
|
- usleep(1000 * PLC_SLEEP_IN_MILLISECONDS * 10);
|
|
|
+ Error_manager code=plc_communicator->connect();
|
|
|
+ if(code!=SUCCESS)
|
|
|
+ {
|
|
|
+ LOG(ERROR)<<code.to_string();
|
|
|
+ }
|
|
|
+ usleep(1000 * 200);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -266,7 +265,8 @@ void Plc_Communicator::plc_update_thread(Plc_Communicator *plc_communicator)
|
|
|
int plc_length_temp = PLC_REGION_NUM * PLC_SIGNAL_NUM_PER_REGION;
|
|
|
uint16_t plc_data_temp[plc_length_temp];
|
|
|
int rc = plc_communicator->m_plc_wrapper.read_registers(PLC_SIGNAL_BEGIN_OFFSET, plc_length_temp, plc_data_temp);
|
|
|
- if(rc == -2){
|
|
|
+ if(rc <0)
|
|
|
+ {
|
|
|
std::cout<<"find plc disconnected while read. try to reconnect."<<std::endl;
|
|
|
plc_communicator->mb_plc_is_connected = false;
|
|
|
continue;
|