|
|
@@ -46,10 +46,10 @@ bool Plc_Communicator::get_connection()
|
|
|
}
|
|
|
|
|
|
Error_manager Plc_Communicator::get_error(){
|
|
|
- if(mb_plc_is_connected){
|
|
|
- return Error_manager(Error_code::SUCCESS, Error_level::NORMAL, "连接正常");
|
|
|
+ if(mb_plc_initialized && mb_plc_is_connected){
|
|
|
+ return Error_manager(Error_code::SUCCESS, Error_level::NORMAL, "状态正常");
|
|
|
}else{
|
|
|
- return Error_manager(Error_code::PLC_CONNECTION_FAILED, Error_level::NEGLIGIBLE_ERROR, "连接失败");
|
|
|
+ return Error_manager(Error_code::PLC_CONNECTION_FAILED, Error_level::NEGLIGIBLE_ERROR, "状态异常");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -119,10 +119,10 @@ Error_manager Plc_Communicator::execute_task(Task_Base *task)
|
|
|
}
|
|
|
Plc_Task *plc_task_temp = (Plc_Task *)task;
|
|
|
plc_task_temp->update_statu(Task_statu::TASK_SIGNED, "received by plc_communicator.");
|
|
|
- std::cout << " execute task, update status " << std::endl;
|
|
|
+ LOG(INFO) << " execute task, update status ";
|
|
|
struct measure_result measure_result_temp;
|
|
|
Error_manager err = plc_task_temp->get_result(measure_result_temp);
|
|
|
- std::cout << " execute task, get result " << std::endl;
|
|
|
+ LOG(INFO) << " execute task, get result ";
|
|
|
if (err.is_equal_error_manager(Error_manager(Error_code::SUCCESS)))
|
|
|
{
|
|
|
Error_manager write_err = write_result_to_plc(measure_result_temp);
|
|
|
@@ -227,7 +227,7 @@ void Plc_Communicator::plc_update_thread(Plc_Communicator *plc_communicator)
|
|
|
plc_module::Plc_msg plc_msg;
|
|
|
int rc = plc_communicator->m_plc_wrapper.read_registers(PLC_SIGNAL_BEGIN_OFFSET, plc_length_temp, plc_data_temp);
|
|
|
if(rc == -2){
|
|
|
- std::cout<<"find plc disconnected while read. try to reconnect."<<std::endl;
|
|
|
+ LOG(WARNING)<<"find plc disconnected while read. try to reconnect.";
|
|
|
plc_communicator->mb_plc_is_connected = false;
|
|
|
plc_msg.set_status(plc_module::PLC_STATUS::ePLCDisconnected);
|
|
|
MeasureTopicPublisher* publisher = MeasureTopicPublisher::GetInstance();
|
|
|
@@ -294,8 +294,10 @@ void Plc_Communicator::plc_update_thread(Plc_Communicator *plc_communicator)
|
|
|
int address_temp = PLC_SIGNAL_BEGIN_OFFSET + PLC_SIGNAL_NUM_PER_REGION * terminal_id_temp + PLC_LASER_STATUS_ADDR;
|
|
|
uint16_t value_temp = plc_communicator->m_plc_region_status[terminal_id_temp].current_status;
|
|
|
int rc = plc_communicator->m_plc_wrapper.write_registers(address_temp, 1, &value_temp);
|
|
|
- if (rc != 0)
|
|
|
+ if (rc != 0){
|
|
|
+ LOG(ERROR)<<"状态1写入PLC失败";
|
|
|
plc_communicator->m_plc_current_error = Error_manager(Error_code::PLC_WRITE_FAILED, Error_level::MINOR_ERROR, "写入状态1失败");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -381,8 +383,10 @@ void Plc_Communicator::plc_update_thread(Plc_Communicator *plc_communicator)
|
|
|
int address_temp = PLC_SIGNAL_BEGIN_OFFSET + PLC_SIGNAL_NUM_PER_REGION * i + PLC_LASER_STATUS_ADDR;
|
|
|
uint16_t value_temp = plc_communicator->m_plc_region_status[i].current_status;
|
|
|
int rc = plc_communicator->m_plc_wrapper.write_registers(address_temp, 1, &value_temp);
|
|
|
- if (rc != 0)
|
|
|
+ if (rc != 0){
|
|
|
+ LOG(ERROR)<<i+1<<"号写入当前状态"<<value_temp<<"失败";
|
|
|
plc_communicator->m_plc_current_error = Error_manager(Error_code::PLC_WRITE_FAILED, Error_level::MINOR_ERROR, "写入当前状态失败");
|
|
|
+ }
|
|
|
plc_communicator->m_plc_mutex.unlock();
|
|
|
// std::cout<<" thread 555 "<<std::endl;
|
|
|
}
|