Posted Fri, 02 Dec 2022 03:55:10 GMT by Wu, Wenjian
我使用C#语言,使用的using Ivi.Visa.Interop;引用 
当我在子线程使用readstring()函数读取电压扫描数据时,函数必须等待仪器扫描完毕获取到数据之后才能运行。
这就导致在电压扫描过程中我的主线程和其他线程无法运行,软件处于卡死状态!

大家有谁了解这是什么原理为什么?
Posted Sun, 04 Dec 2022 21:59:18 GMT by C, Andrea
Hello,

Seems you are attempting to use NI VISA from multiple threads in C#.

Can you clarify which exact model of instrument you have?
Also, can you give us an idea of the operation you are attempting with that instrument.

Sometimes a multi-point sweep can take a long time to run and in that case it would be expected that attempts to read the information would not be processed until after the sweep operation completes.

This NI forum post seems to have some good info about using VISA from threads:
https://forums.ni.com/t5/Instrument-Control-GPIB-Serial/What-is-the-difference-between-doing-a-VISA-read-asyncronous-vs/m-p/60673?requireLogin=False
Posted Mon, 05 Dec 2022 03:31:50 GMT by Wu, Wenjian
I am using KEITHLEY 2410 Source Measure Units
I want to use my own software to for remote line sweep.
For example, when I want to implement the sweep function, after I configure the start value, stop value, step value, sweep point, etc. and activate the measurement with command 'FETCh?'. Because I don't know how long the device will run before it finishes, I will try to send the software command 'instrument_control_object.ReadString()' to read the data to the instrument in a sub-thread, but the software will be stuck until the instrument finishes the test and returns the scan data.
The software command 'instrument_control_object.ReadString()' is cone from Ivi.Visa.Interop;
The user's guide 《Getting Started with Instrument Control Using Microsoft Visual Studio C Sharp》using VISA Reference in VISA COM 5.9 Type Library, so I use this reference too.
 
Posted Thu, 08 Dec 2022 13:22:31 GMT by C, Andrea
When the SourceMeter is busy performing the sweep, most SCPI commands sent to the instrument during the active sweep will not be processed by the command parser until the sweep is completed.  This is normal/expected behavior for the product.

When a large number of steps is used or other factors that make the sweep take a long time, it becomes important to synchronize the PC code with instrument state.

It is not uncommon for customers to experience a VISA timeout on the attempted ReadString() after starting the sweep.  The default duration of VISA timeout is usually 10 seconds.
Moving ReadString to a separate thread will not resolve the underlying issue.

The way to work this out is to use the status system of the instrument.  The PC code can read status byte information from the instrument during the active sweep.  Just you need to setup some flags in the status system to give bit change signals such as when the expected buffer is full.  Often times this is called Service Request or SRQ.

I'll dig up a C# sample.
Posted Fri, 09 Dec 2022 15:51:54 GMT by C, Andrea
Hello,

I do not happen to have a 2400 or 2410 SourceMeter.
But I used a DAQ6510 in a 2700 SCPI emulation mode to get close to same command set and behavior as your 2410.

The point of my file attachment was to show how to use VISA and the ReadSTB feature to know when the instrument has data for you.
Use of ReadSTB can allow coordination between the Windows PC side code and the instrument state.

 




						
Posted Mon, 12 Dec 2022 01:50:15 GMT by Wu, Wenjian
Thankfully, by reading the manual I learned how to use SRQ to get the status of the instrument as it executes, and when the instrument sweeping, I can avoid querying data into the buff before the scan is complete simply by reading the sweep bit in the operating condition register. Your documentation is very detailed, thank you very much!

You must be signed in to post in this forum.