LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Asynchronous serial

It appears that when calling viReadAsync, it will not return until it times out or it receives at least as many bytes as I requested.  Is there a way to make it return when it finds any data in the buffer?  Currently, I am setting 'count' to 1, but this seems a bit inefficient. 
 
Once viReadAsync and viWaitOnEvent have completed, I am having problems getting the number of bytes read.  Is this always going to be the same number I requested?  I tried using viGetAttribute to get VI_ATTR_RET_COUNT, but couldn't make that work.  When I use the device session as the first arg, it returns VI_ERROR_NSUP_ATTR.  When I use the job ID from viReadAsync or VI_EVENT_IO_COMPLETION, VI_ERROR_INV_OBJECT is returned.  What is the secret to getting the number of bytes read?
 
Will viReadAsync ever return more bytes than I requested?  What do I need to do to get all bytes in the input buffer?  Do I need to check the number of bytes in the buffer, then request that many?  How do I do this (I can't find that function/attribute)?
 
0 Kudos
Message 1 of 2
(2,612 Views)
Are you using CVI? This is the LabVIEW forum. I can tell you though, that you can be use the VI_ATTR_ASRL_AVAIL_NUM to determine how many bytes are actually in the buffer and only do a read if the byte count is greater than 0. You will never get more bytes than what you request but you can get less. You will get less if you have the termination character enabled and the data includes the character. A VISA read will then terminate when the term character is detected, no matter how many bytes you specify.
0 Kudos
Message 2 of 2
(2,604 Views)