【发布时间】:2015-07-28 11:00:17
【问题描述】:
我正在尝试使 LED 以 Labview 中数值控件中给定的频率闪烁。我已经使用 COM4 将 Arduino 连接到 Labview。 I这是在Arduino IDE中编写的代码:
char command;
String string;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
}
void loop()
{
if (Serial.available() > 0)
{string = "";}
while(Serial.available() > 0)
{
command = ((byte)Serial.read());
if(command == ':')
{
break;
}
else
{
string += command;
}
delay(1);
}
if(string.toInt() > 0 )
{
TempOn();
TempOff();
}
}
void TempOn()
{
long y= string.toInt();
digitalWrite(13, HIGH);
delay(y);
}
void TempOff()
{
long y= string.toInt();
digitalWrite(13, LOW);
delay(y);
}
}
如果我尝试让它闪烁某个值,例如 1000(我从下面编写以下代码),它对于该值非常有效!
if(string == "1000" )
{
TempOn();
TempOff();
}
我不明白为什么它不适用于一般情况...
这是 Labview 中的代码(框图):
【问题讨论】:
-
看起来您的 Arduino 代码期望时间延迟字符串以冒号结尾,但您的 LabVIEW 代码没有在数字后发送冒号。此外,LabVIEW 代码将继续每 10 毫秒传输一次数字,因此如果(例如)数字控件设置为 1000,那么数据流将看起来像
10001000100010001000等。您希望将终止字符附加到在将其传递给 VISA Write 之前的字符串,并且可能仅在单击按钮或值更改时发送值(例如,使用控件的值更改事件)。