02-10-2015 03:32 AM
Hi,
I'm trying to use the VISA event in order to read data from a serial port. I created a simple VI to test this (see attachment).
1. I initialize the port and event
2. in a while loop: every time I press a button the command "help" is sent to my board that answers with a few help instructions, which should be trigger a series of events and the lines be read.
The event is set on term characters. The weird thing is that every time I press help, I get "5 event", or 5 lines printed, not all the 8 lines that are actually sent from the board. If I then press "help" again, the remaining 3 lines (plus 2 new from the latest help request) are read on the VI. I don't understand what is going on??
I've tried changing the max queue length (which has no effect, whether it is set to 1 or 100).
I've tried changing the timeout from 50ms, but also this has no effect.
I'm sure the board is outputting the right commands I can read this in a terminal.
If I skip the event functionality (just read bytes at port) I can output all lines as expected, however I've had other issues with that approach and would really like to solve this with an event approach. Also, I would like to understand what's going on... I'd be grateful for any advise!
Best,
Maria
Solved! Go to Solution.
02-10-2015 07:01 AM
Do NOT use the Bytes At Port for this. Just set the number of bytes to read so something really high. The VISA Read will stop when the termination character is found.
Furthermore, I would actually just make a seperate loop that does nothing but read from the port. No VISA events needed. Just let the timeouts happen on the VISA Read if nothing is coming in.
02-10-2015 08:02 AM
Hi,
Thanks for your reply! I did as you first suggested (attachment), unfortunately it does not solve my problem... However, now it reads 6 lines at a time instead of 5 (same result whether I set the read bytes to 100 or something really high)... Also, I'm not sure I understand why it is a bad idea to use Bytes at Port?
For your second suggestion, I'm not sure how to make the VISA read timeout (this is what I was trying to acheive with the event), and what is the benefit of placeing it in a seperate loop?
Cheers,
Maria
02-10-2015 08:39 AM
Ok! Thanks, I got it to work with the second suggestion! I added timeout value of 50ms to the property node, now the vi is behaving as I would like.
But I still don't understand why the event approach fails!? To my understanding there should be 8 events queued, when 8 lines are sent to the port. why on earth does it only react to a subset of these and buffer the rest (and only react to these when the button is pressed again and new data arrives at port)?
Best,
Maria