NI LabVIEW,CVI,数据采集等产品讨论区

取消
显示结果 
搜索替代 
您的意思是: 

串口通信问题,急寻解答!

控制器上位机.png程序框图如附件所示。现在我可以控制下位机,并接收下位机传上来的完整数据。

      问题是:(1)程序最初运行时,第一次点击合闸按钮或分闸按钮时,下位机动作,可读取缓冲区没有数据显示;点击第二次按钮时,下位机动作,读取缓冲区才显示正确数据。(2)当点击合闸按钮读取缓冲区有数据显示时,接着点击分闸按钮,读取缓冲区显示的数据还是合闸数据,再点击一次才显示分闸数据。

     不知道大家是否明白我的意思,总之,就是我的预期结果是点击合闸按钮,下位机动作,接收合闸数据;点击分闸按钮,下位机动作,接收分闸数据;可现在的状况如(1)(2)所述,上下不同步。

     请大家指点一下!谢谢
0 项奖励
1 条消息(共 13 条)
7,342 次查看

Hi,

 

That is because you perform a VISA Read right after VISA Write; the expected (full) set of data may not be already available for reading back.

 

I assume that you already know how many bytes of data are expected (to be read back), you may at a sub-loop with timeout after VISA Write to check if Bytes at Port is equal or greater than the expected byte count. Perform a VISA Read only when Bytes at Port is equal or greater than the set byte count, else wait till timeout.

 

You may also perform a VISA Read of Bytes at Port right before the VISA Write to clear whatever data in the buffer. 

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
2 条消息(共 13 条)
7,337 次查看

可否用简单的程序框图明示一下啊?谢谢啊!

0 项奖励
3 条消息(共 13 条)
7,324 次查看

Attached is one example code for (Serial) VISA Read with timeout.

 

LVVILIB_Serial_Read with Timeout.PNG 

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
4 条消息(共 13 条)
7,318 次查看

非常感谢你的耐心指点,能不能把程序visa read with timeout的例子通过附件的形式附上啊!

谢谢!

0 项奖励
5 条消息(共 13 条)
7,307 次查看

I hope that you can re-construct the exact code by yourself... this way, you might be able to really understand 😉

 

You may omit the hidden Case(s). It will still works!

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
6 条消息(共 13 条)
7,301 次查看

握已经尝试重建了你的例子,错误的地方请您指正,谢谢!

第一个case,没想明白它的条件,还有左上角的局部变量。

0 项奖励
7 条消息(共 13 条)
7,283 次查看
今天我按你的建议修改了自己的程序,调试了一下,还是不能解决先前的问题!麻烦你看看!
0 项奖励
8 条消息(共 13 条)
7,188 次查看

All you need is the code inside the Fixed Bytes Case. Please remove the Byte Count control and the first Case.

As for the local variable (top-left corner), it is merely to reset the Timeout error at entry of this VI. 

Message Edited by ian fung on 01-11-2010 01:19 PM
Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
9 条消息(共 13 条)
7,184 次查看

现在还是不能做到发送命令与接收数据的同步

123.png

0 项奖励
10 条消息(共 13 条)
7,171 次查看