LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

viRead taking 100% CPU

I am using an Agilent's driver. Reading some param from the instrument
was taking 30sec. (case of timeout). And it was taking 100%CPU even and
sucking resources from all other apps. BTW - The call to the instrumnet
driver runs in its own thread (using async timer).

Looked at the agilent's code, and it seems default VISA timeout was
20seconds. Don't know why my call took 30sec to return. Anyhow changed
timeout to 5 sec. When queried back. it says 10sec. But CPU is still
100% during that time. It is viRead which is doing this.

I would like to know what how viRead is implememented. How come it take
100% CPU?

Second question, is there a min granularity as far as VISA timeout are
concerned. if I set timeout of say 2sec. I should read back timeou
t of 2
sec. not 3 secs (which is happening with the driver that I have, I have
looked at the driver code, there is nothing in there, which could
explain this).

BTW - I ran into an issue with another Agilent driver recently. Some
intelligent fellow over there decide to put hard coded delay of 1-2
seconds after each low-level call to the instrument, even when the call
was successfull (his comment, PC are too fast so we don't want users to
send GOIB commands too fast) . He was using some windows function for
delay which was sucking 100% of the resources and my whole app as
running like a big resource hog. Took the delay out and things became
ok. Enought of ranting, have a Happy New year!!!.


vishi
0 Kudos
Message 1 of 5
(3,217 Views)
Hello Vishi,

- When you wrote "timeout to 5 sec. When queried back. it says 10sec." do you mean that you performed a viSetAttribute to set a timeout value of 5 sec and when you did a viGetAttribute, you read back a value of 10?

- The timeout is defined as a minimum timeout, so if you set a timeout of 5 seconds, your timeout will be at least 5 seconds.

- Make sure your code is not opening and closing VISA sessions in every iteration of your main loop.

- Put a small delay at the end of your loop (10 ms is fine) to allow the CPU to take care of background services.

- If none of the above suggestions work, let me know if you are using NI-VISA or HP-VISA.

-Ray
0 Kudos
Message 2 of 5
(3,217 Views)
Ray,

I am using NI VISA, version 3.0.1 with CVI ver 7.0. My main concern is
that when I call (actually I am calling the driver which in turn calls
viRead) viRead, why does the CPU utilization goes to 100%?

The agilent driver that I am using only calls viSetAttribute once (at
initialization) to set the timeout. I don't find timeout of 10sec, as
long as, it doesn't slow down my other apps.


vishi

Ray K wrote:
> Hello Vishi,
>
> - When you wrote "timeout to 5 sec. When queried back. it says 10sec."
> do you mean that you performed a viSetAttribute to set a timeout value
> of 5 sec and when you did a viGetAttribute, you read back a value of
> 10?
>
> - The timeout is defined as a minimum timeout, so if you set a timeout
> of 5 seconds, your timeout wi
ll be at least 5 seconds.
>
> - Make sure your code is not opening and closing VISA sessions in
> every iteration of your main loop.
>
> - Put a small delay at the end of your loop (10 ms is fine) to allow
> the CPU to take care of background services.
>
> - If none of the above suggestions work, let me know if you are using
> NI-VISA or HP-VISA.
>
> -Ray
0 Kudos
Message 3 of 5
(3,217 Views)
Anyone know why viRead take 100%. I have seen same thing happen with
RS232 read fns, but there I can just change timeout to very small number
(100msec. or something) and keep waiting in a loop (with a timeout &
processSystemEvents). I guess I could do something similar but I am
trying to avoid changing the vendors driver code.


vishi

Vishi Anand wrote:
> Ray,
>
> I am using NI VISA, version 3.0.1 with CVI ver 7.0. My main concern is
> that when I call (actually I am calling the driver which in turn calls
> viRead) viRead, why does the CPU utilization goes to 100%?
>
> The agilent driver that I am using only calls viSetAttribute once (at
> initialization) to set the timeout. I don't find timeout of 10sec, as
> long as, it doesn't slow do
wn my other apps.
>
>
> vishi
>
> Ray K wrote:
>
>> Hello Vishi,
>>
>> - When you wrote "timeout to 5 sec. When queried back. it says 10sec."
>> do you mean that you performed a viSetAttribute to set a timeout value
>> of 5 sec and when you did a viGetAttribute, you read back a value of
>> 10?
>>
>> - The timeout is defined as a minimum timeout, so if you set a timeout
>> of 5 seconds, your timeout will be at least 5 seconds.
>>
>> - Make sure your code is not opening and closing VISA sessions in
>> every iteration of your main loop.
>>
>> - Put a small delay at the end of your loop (10 ms is fine) to allow
>> the CPU to take care of background services.
>>
>> - If none of the above suggestions work, let me know if you are using
>> NI-VISA or HP-VISA.
>>
>> -Ray
>
>
0 Kudos
Message 4 of 5
(3,217 Views)
Vishi:

The answer to how the timeout works is pretty easy. NI-VISA uses NI-488 for GPIB I/O, and the NI-488 API has only certain predefined timeout values - for example, 1 msec, 3 msec, ... 1 sec, 3 sec, 10 sec, etc. As someone else mentioned, the timeout you specify is a minimum, so we just round up to the next available NI-488 timeout.

Why does it take 100% CPU? Good question. I don't know the answer yet. But it is definitely a different code path than Serial (where we did address similar CPU issues in the 2.5.x releases). Since NI-VISA depends on NI-488, the answer to this question will depend at least partially on the type of GPIB controller, the OS, and the version of NI-488. If you can provide those details, that may help.

Dan Mondrik
Nation
al Instruments
0 Kudos
Message 5 of 5
(3,217 Views)