LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Questions on viRead

I used to use the function of "ComRd" to get a R232 response. For example, if I want to read 10 bytes from input queue of COM1 into buf, The command "n = ComRd (1, buf, 100);" could be used. And, return will be given on timeout or when 100 bytes have been read. Also I can set timeout by using "SetComTime."
Now I'm converting to develop COM Port communications driver by using IVI. In IVI viRead has the same role with "ComRd", however:
1, How to set Timeout in IVI?
2, Before getting expected number of bytes, viRead will keep reading until timeout ?
 
 
Thanks!
Jacky
0 Kudos
Message 1 of 3
(4,283 Views)
> 1, How to set Timeout in IVI?
To set I/O timeout, use viSetAttribute() function.  The time unit is milliseconds:
vs = viSetAttribute( vi, VI_ATTR_TMO_VALUE, 3000); 
 
> 2, Before getting expected number of bytes, viRead will keep reading until timeout ?
 
viRead() will complete successfully when the specified number of bytes has been read, or when the specified Termination Character has been encountered.  When the specified timeout has elapsed before completing by num of bytes or by termination character, the viRead() will return VI_ERROR_TMO.
 
The following example reads a response string from instrument, it terminates when 256 bytes have been read or 0x0A byte (Line Feed char) has been encountered.
 
ULONG dwLen;
char sz[512];
vs = viSetAttribute( vi, VI_ATTR_TERMCHAR, 0x0A); 
vs = viSetAttribute( vi, VI_ATTR_TERMCHAR_EN, VI_TRUE); 
dwLen = 256;
vs = viRead( vi, (unsigned char*)sz, dwLen, &dwLen);
By the way, viRead() is a VISA function, not IVI.Smiley Wink
 
Hope this helps,
Makoto
0 Kudos
Message 2 of 3
(4,279 Views)

A little addition to Makoto good explanation.

> 2, Before getting expected number of bytes, viRead will keep reading until timeout ?
Definitely YES: viRead is a syncronous function. That is: the function will not return control to your application until one of the following occur:
- Timeout
- Received expected number of bytes, or
- Received termination character

After the function terminates you will need to test return value and if not timeout handle the received message.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 3
(4,272 Views)