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

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

串口通信和对话框,急求解答

我通过串口通信从visa read 读string。

我有附件我的程序。

read buffer的string是我读到的。当读到的是lose1就显示对话框youlose,如果是win0,就显示对话框you win。

现在问题是有时候detect到lose1或者win0(有时候是detect不到的),可以detect lose1或者win0,却没有进入case structure,没有弹出对话框。

 

版本为8.6

 

非常感谢!!!

0 项奖励
1 条消息(共 10 条)
5,371 次查看

Hi

 

First of all, are you using the same COM port for read and write? If so, do not use two initialization VI but one.

 

Place the VISA Configure Serial Port outside and before entering the while-loop as it should be run once.

(In your case, placing it within the loop causing it to keeping on re-configuring the serial port.)

 

The same goes to VISA Close.

 

For VISA Read, you may perform a check on if string is valid, followed by a trim whitespace. In the attached sample, enum is used as Case selector value for readability.

 

PS: re-configuring the serial port during execution is inefficient and may cause data lose as well.

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 项奖励
2 条消息(共 10 条)
5,356 次查看

Hi  ian fung,

 

Thank you for your reply!!

 

firstly, i am using different COM port to read and write.

secondly, i moved out the VISA Configure Serial Port outside and place in a flat sequence structure which can make it run once only. but still cannot work properly.

 

I have one more question.

As for my program, i need VISA Write first and VISA read, there is a sequence, if i use two parallel while loop, is there any problem?

 

i attach 2 VIs.

pls have a look.

 

 

thanks!!!

下载全部
0 项奖励
3 条消息(共 10 条)
5,325 次查看

Hi Elsa,

 

In your write.vi, I see that you have set the VISA Read to read 1000 bytes. This might cause timeout error if you device does not return 1000 bytes of data.

If you know the expected number of bytes to be read, may I suggest that you check the return byte count using Bytes at Port, and perform VISA Read only when Bytes at Port is equal or greater than the set byte count.

 

As for writing to and reading from different ports, there should not be any problem with that as long as the target device is capable of handling them.

 

If VISA Read must be perform after VISA Write, why not you have both in the same loop instead? What you may try is...

 

 

  1. Initialize both ports (and passing in the VISA Resource handlers to the while-loop)
  2. While-loop starts
  3. Write command (to receiving port of the target device)
  4. Wait for N ms or Check for expected number of bytes returned (from the transmitting port of the target device)
  5. Perform VISA Read (from the transmitting port of the target device)
  6. While-loop ends
  7. VISA Close for both ports

 

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
0 项奖励
4 条消息(共 10 条)
5,318 次查看

hi ian fung,

 

when i detect the string lose1 then come out the dialogue box you lose.

when i detect the string win00 then come out the dialogue box you won.

 

i jst test the program you gave me, when i run it, it immediately come out the dialogue box..

 

i attach the vi (i added up the VISA part)

 

 

regards,

0 项奖励
5 条消息(共 10 条)
5,317 次查看

Hi

 

this is the new VI, visa write and visa read in the same while loop.

but i cannot find Bytes at Port.

And my number of bytes is not fixed , so i m not sure whether can work or not..

0 项奖励
6 条消息(共 10 条)
5,314 次查看

Hi

 

this is the new VI, visa write and visa read in the same while loop.

but i cannot find Bytes at Port.

And my number of bytes is not fixed , so i m not sure whether can work or not..

下载全部
0 项奖励
7 条消息(共 10 条)
5,314 次查看

Hi

 

this is the new VI, visa write and visa read in the same while loop.

but i cannot find Bytes at Port.

And my number of bytes is not fixed , so i m not sure whether can work or not..

下载全部
0 项奖励
8 条消息(共 10 条)
5,314 次查看

Hi Elsa,

 

That example was just meant for showing you an idea of calling cases. The conditions set for the Case (True/False) have to be altered to suit your needs.

 

Mine, it calls the dialog at when the "buffer string changed" AND "it is not empty". For your case, you might have to alter the conditions to call the dialog. Or, even set Default Case as no dialog, Case 1 as lose1, Case 2 as win0 etc.

 

Hope you are able to alter the code and get it up and running soon! Cheers!

Ian F
Since LabVIEW 5.1... 7.1.1... 2009, 2010, 2014
依恩与LabVIEW
LVVILIB.blogspot.com
9 条消息(共 10 条)
5,313 次查看

Hi ian fung,

 

Thank you for your great help.

 

I will let you know when i get it up!

 

 

regards,

Elsa 🙂

0 项奖励
10 条消息(共 10 条)
5,310 次查看