求助labview arduino+MAX6675讀取每隔一段時間會變成0

使用ARDUINO 讀取MAX6675 溫度,Labview擷取數據。
遇到一個問題是會每隔一段時間數據接收會掉到0,波特率、換線材都試過。
在arduino IDE監控’窗口都不會有這狀況發生。求各位協助
以下是ARDUINO程式:
#include “max6675.h”

// 定义 MAX6675 的引脚
int sckPins = {22, 22, 22, 22, 22, 22, 22, 22}; // 8组温度传感器的SCK引脚
int csPins = {2, 4, 6, 8, 10, 12, 14, 16}; // 8组温度传感器的CS引脚
int soPins = {3, 5, 7, 9, 11, 13, 15, 17}; // 8组温度传感器的SO引脚

MAX6675 Modules = {MAX6675(sckPins[0], csPins[0], soPins[0]),
MAX6675(sckPins[1], csPins[1], soPins[1]),
MAX6675(sckPins[2], csPins[2], soPins[2]),
MAX6675(sckPins[3], csPins[3], soPins[3]),
MAX6675(sckPins[4], csPins[4], soPins[4]),
MAX6675(sckPins[5], csPins[5], soPins[5]),
MAX6675(sckPins[6], csPins[6], soPins[6]),
MAX6675(sckPins[7], csPins[7], soPins[7])};

void setup() {
Serial.begin(4800);
Serial.setTimeout(10); // 设置串口通信的超时时间为100毫秒

}

void loop() {
int temp1 = 0;
int temp2 = 0;
int temp3 = 0;
int temp4 = 0;
int temp5 = 0;
int temp6 = 0;
int temp7 = 0;
int temp8 = 0;

for (int i = 0; i < 8; i++) {
float temperature = Modules[i].readCelsius();

if (isnan(temperature) || temperature == 0.00) {
  continue; // 如果温度无效,则跳过当前传感器的数据
}

if (i == 0) {
  temp1 = int(temperature);
} else if (i == 1) {
  temp2 = int(temperature);
} else if (i == 2) {
  temp3 = int(temperature);
} else if (i == 3) {
  temp4 = int(temperature);
} else if (i == 4) {
  temp5 = int(temperature);
} else if (i == 5) {
  temp6 = int(temperature);
} else if (i == 6) {
  temp7 = int(temperature);
} else if (i == 7) {
  temp8 = int(temperature);
}

}

if (temp1 != 0 || temp2 != 0 || temp3 != 0 || temp4 != 0 || temp5 != 0 || temp6 != 0 || temp7 != 0 || temp8 != 0) {
Serial.print(temp1);
Serial.print(“,”);
Serial.print(temp2);
Serial.print(“,”);
Serial.print(temp3);
Serial.print(“,”);
Serial.print(temp4);
Serial.print(“,”);
Serial.print(temp5);
Serial.print(“,”);
Serial.print(temp6);
Serial.print(“,”);
Serial.print(temp7);
Serial.print(“,”);
Serial.println(temp8);
}

// 检查连接是否丢失
if (!checkConnection()) {
Serial.println(“Connection lost!”);
// 这里可以添加处理连接丢失的逻辑,例如重启Arduino或其他操作
}

delay(1000);
}

bool checkConnection() {
// 检查连接是否丢失的逻辑
// 在这里你可以添加适合你的连接检查方法
// 如果连接丢失,返回false;否则返回true
return true; // 默认返回true,表示连接正常
}
以下為LABVIEW程式


以下為異常時圖片
image

    我覺得可能是時序問題,你可以看看是否讀不到值的現象會大約間隔差不多秒數就出現一次,之後又正常。雖然你兩邊都想用1000ms的delay控制更新率,但是實際上是會有誤差的,尤其是windows上的delay至少都會有+/- 1ms的誤差,再加上一些處理時間的累積誤差又會更大。
    因為你的Arduino是拋資料,Labview是收資料,建議你Labview端的scan rate要比arduino快,例如100ms或10ms 就檢查一次buffer有沒有資料,有資料才更新。

時間誤差示意圖