我通过串口通信从visa read 读string。
我有附件我的程序。
read buffer的string是我读到的。当读到的是lose1就显示对话框youlose,如果是win0,就显示对话框you win。
现在问题是有时候detect到lose1或者win0(有时候是detect不到的),可以detect lose1或者win0,却没有进入case structure,没有弹出对话框。
版本为8.6
非常感谢!!!
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.
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!!!
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...
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,
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..
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..
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..
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!