Browse Source

从plc获取间隙并赋值

LiuZe 1 year ago
parent
commit
d1b2b27161
2 changed files with 13 additions and 20 deletions
  1. 1 16
      include/plc/snap7_clamp.cpp
  2. 12 4
      mainwindow.cpp

+ 1 - 16
include/plc/snap7_clamp.cpp

@@ -85,30 +85,15 @@ Error_manager Snap7Clamp::updata_receive_buf()
 {
     std::unique_lock<std::mutex> t_lock1(m_receive_buf_lock);
     std::unique_lock<std::mutex> t_lock2(m_data_lock);
-//    static unsigned short heart;
+
     memcpy(&plcData, m_receive_buf_map[0].mp_buf_obverse, m_receive_buf_map[0].m_size);
 
     Error_manager ret = Error_code::SUCCESS;
-
-//    if (heart == m_heart) {
-//        printf("---Debug %s %d : heart not change %d ---> %d\n", __func__, __LINE__, m_heart, heart);
-//        ret = Error_code::FAILED;
-//    }
-//    m_heart = heart;
 	return ret;
 }
 
 Error_manager Snap7Clamp::updata_send_buf()
 {
-	std::unique_lock<std::mutex> t_lock1(m_send_buf_lock);
-	std::unique_lock<std::mutex> t_lock2(m_data_lock);
-
-    if (plcData.pingpong != 0) {
-        plcData.info();
-    }
-
-	memcpy(m_send_buf_map[0].mp_buf_obverse, &plcData, m_send_buf_map[0].m_size);
-
     return Error_code::SUCCESS;
 }
 

+ 12 - 4
mainwindow.cpp

@@ -316,9 +316,17 @@ void MainWindow::on_AutoGetDistance_clicked()
     }
     std::unique_lock<std::mutex> t_lock1(m_snap7_client->m_data_lock);
     Snap7Clamp::PLCData plc_value = m_snap7_client->plcData;
-    std::cout << plc_value.wheels[0].gap << std::endl;
-    std::cout << plc_value.wheels[1].gap << std::endl;
-    std::cout << plc_value.wheels[2].gap << std::endl;
-    std::cout << plc_value.wheels[3].gap << std::endl;
+
+    if (ui->Forward->isChecked()) {
+        ui->LeftFrontDIstance->setValue(plc_value.wheels[0].gap);
+        ui->RightFrontDistance->setValue(plc_value.wheels[1].gap);
+        ui->LeftRearDistance->setValue(plc_value.wheels[2].gap);
+        ui->RightRearDistance->setValue(plc_value.wheels[3].gap);
+    } else {
+        ui->LeftFrontDIstance->setValue(plc_value.wheels[3].gap);
+        ui->RightFrontDistance->setValue(plc_value.wheels[2].gap);
+        ui->LeftRearDistance->setValue(plc_value.wheels[1].gap);
+        ui->RightRearDistance->setValue(plc_value.wheels[0].gap);
+    }
 }