From 2ad852ee08e21ee681950f1d6058499248baf88e Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期五, 18 七月 2025 15:04:22 +0800
Subject: [PATCH] 完成串口读取数据和处理

---
 src/components/TableDisplay.vue |   54 ++++++------------------------------------------------
 1 files changed, 6 insertions(+), 48 deletions(-)

diff --git a/src/components/TableDisplay.vue b/src/components/TableDisplay.vue
index 1a11ada..0fc93f1 100644
--- a/src/components/TableDisplay.vue
+++ b/src/components/TableDisplay.vue
@@ -1,10 +1,6 @@
 <script setup lang="ts">
-import { ref, onMounted, onUnmounted } from 'vue';
-import { sendToPipe } from '../pipe_client';
-
-const props = defineProps<{
-  pipeName: string;
-}>();
+import { ref, onMounted, onUnmounted} from 'vue';
+import { createDataReceiver } from '../utils/dataFetcher';
 
 interface ForceData {
   timestamp: string;
@@ -42,52 +38,14 @@
   }
 }
 
-// 鐘舵�佸彉閲忥紝鐢ㄤ簬鎺у埗閿欒鏄剧ず棰戠巼
-const errorCount = ref(0);
-const maxConsecutiveErrors = 5;
-const showingError = ref(false);
-
-// 鎺ユ敹绠¢亾鏁版嵁鐨勫嚱鏁�
-async function receiveData() {
-  try {
-    const response = await sendToPipe(props.pipeName, 'GET_FORCE_DATA');
-    
-    // 閲嶇疆閿欒璁℃暟
-    errorCount.value = 0;
-    showingError.value = false;
-    
-    // 瑙f瀽鏁版嵁
-    try {
-      const forceData = JSON.parse(response);
-      if (Array.isArray(forceData) && forceData.length === 6) {
-        updateTable(forceData);
-      }
-    } catch (parseErr) {
-      console.error('鏁版嵁瑙f瀽閿欒:', parseErr);
-    }
-  } catch (err) {
-    // 澧炲姞閿欒璁℃暟
-    errorCount.value++;
-    
-    // 鍙湪杩炵画閿欒杈惧埌闃堝�间笖灏氭湭鏄剧ず閿欒鏃舵樉绀�
-    if (errorCount.value >= maxConsecutiveErrors && !showingError.value) {
-      console.error('绠¢亾閫氫俊澶辫触:', err);
-      showingError.value = true;
-    }
-  }
-}
-
-let dataInterval: number | null = null;
-
 onMounted(() => {
-  // 姣�500ms鑾峰彇涓�娆℃暟鎹�
-  dataInterval = window.setInterval(receiveData, 500);
+ createDataReceiver((forceData) => {
+    updateTable(forceData);
+  });
 });
 
 onUnmounted(() => {
-  if (dataInterval !== null) {
-    clearInterval(dataInterval);
-  }
+
 });
 </script>
 

--
Gitblit v1.9.3