文件名称:
5989-6338EN.pdf VB.ET 编程
开发工具:
文件大小: 949kb
下载次数: 0
上传时间: 2019-07-03
详细说明:安捷伦仪器通讯说明。Keysight Using VISA COM 1/0 API
ppl cation No
Getting started
The examples in this application note
The visual Studio environment with the Solution Explcrer window
were developed using C# 2003 and Visual
VisaComDotNetclient-Microsoft Visual CH. NET [design- VisaComClient, cs Design]
-回
Basic 2003 as part of Visual Studio 2003 El Ed yiew proiect Bild cbug Data Iock TEAM Tolt window Hedlp
Professional Edit on. We will commonly
,彻·萨副电岛“,(·副,四
call them C# and vb throughout this
引罪山非机图创囤固,来③短看对0,
Too box
n x Start Pace Visacomclient cs [Design].
4 pX sOlution Explorer - cmO:Bet Cient 9 x
application note. In addition, Keysight IO
T&M Tools-
Libraries suite 14.2 was used
10 Client Test Appl.--x
4 5obtion'viseCamDotNetdlient'(I project
arenas
哮 saComDotNetclient
windows Forms
First you must install Keysight VISA
xPointer
so System
-a System. Data
心5y丈em, Draving
COM1/0, Which is installed as part of
LinkLabel
O System, wind/.Forms
ab Button
-O 5ystem, xI
the Keysight IO Libraries Suite. You can
abi TextBox
download the latest version of the io
国
visacomdent, cs
M Chad: Box
LibrariesSuiteatwww.keysight.com/find/oradicestton
lib. After installing the Io Libraries Suite
M GroupBox
4 PictureBox
cherries
you are ready to add vISA COM 1/0 to
□pare
your C# Microsoft Visual Studio project
DataGrid
To use VISA COM 1/0, you need to create
sia Ched:. Box
FarmBcrdertyd: Stable
as ComboBox
RightToLeit
a reference to it in your project. To add a
VISA COM I/o client
COM reference to your proect, click the
Treevie
Dboard Ring
The bex contained n the coned
Solution Explorer"window in your C#
project and right-click the"References
Properties Dynamic Help
menu item
Ready
The visual studio Add reference
dialog
You will see the "Add Reference"dialog
The Visual Studio Add Reference dia.og
Click on the“COM” tab to lcok for the
Add Reference
VISA COM reference vau will need. Select
the VISA COM 3.0 Type Library"reterence
ET COM
Pe
so that you can instantiate the Keysight
Component Name
TypeLib Ver. Path
VISA COMI/O implementation. The VISA
WCS_ SQL 7.0 Type Library
1.0
C: pRogram Files Microsoft Vi
Select
COM 3.0 Type Library also includes the
wCWiz 7 1 Type Library
7,1
C: Program Files\ Microsoft Vi.
type information for VISA COM 1/0
wCWiz 8.0 Type Library
C: PRogram Files\Microsoft Vi
VEGAS Shell 5.0
C: \Program Files( ommon Fil
viewModel 1. 0 Type Library 1.0
C: Program Files Microsoft Vi
VISA COM 1.0 Type Library
1,0
C: 1VXIPNP/Visa ComiGlobMgr, d‖l
WISA COM 3.0 Type Library
3,0
C: 1VXIPNP!Visa Com GlobMgr, dll
VISA COM 488. 2 Formatted I., 1.0
C: VXIPNP\ Visa Com BasFrmI
VisAED
C: \Program Files Microsoft Vi
Visio 2000 Type Library [servi., 4.8
C: Program Files\Microsoft Vi
Wisio Graph 2. 60 (Visio version., 2.60
Wisin HTMI Fxnort Su snort oh.. 1.0
C:pRogram files microsoft Vi. y
Selected C
omponent Name
T
Source
Remove
Ⅵ SA COM30 Type Library
COM
C:XIPNP\Visa Com GlobMgr dll
Help
Keysight Using VISA COM I/0 API in NET -Appl cation Note
Get familiar with the object
Browser
Now that you have added the appropriate The visual Studio Oject Browser dialog
references into your application, it is
a good time to look at the interfaces
Start Page Visa Client. cs [Design]* Object Browser
4X
and classes available to use. Press
Browse: Selected Components
CTRL+ALT+J or go to the View men
e
Members of ' AccessMode
and select Object Browser to open
三. visa. interop
呼 EXCLUSIVE LOCK
the object browser. This window allows
+0 Ivi
oap LOAD_CONFIG
you to examine the class hierarchies of all
+0 Ivi,Visa
回NL0CK
the currently referenced com and NeT
O IviVisa. Interop
daP SHARED LOCK
projects and libraries. Take a look at Ivi
+eP AccessMode
的 Addressspace
Visa Interop to see the classes and
+"EP AssertInterrupt Const
interfaces you will be using
AssertOr量 ty Const
+-EP ATNControlConst
+EP Buffer Mask
+EP Conf lictHandler Type
t的 EyentMechanism
EP EventType
+的 FDCMode
+o-o FormattedIO488
t FormattedIo488Class
+EP GPIBAddressState
+eP HardwareInterface Type
IBaseMessag
IEEEASCIType
+EP IEEEBinary Type
+o EVent
+o-o EVent GpibCIC
+-o-0 IEventHandler
+-o-o IEventIOCompletion
+-0-o IEventManager
IEventTrigger
∞ o IEventUsbInterrupt
public sealed enum AccessMode: System Enum
Member of Ivi, Visa. Interop
Summary
The enumeration of locking access modes
ppl cation No
Instantiating and using Keysight's
VISA COM 1/0 in. NET
Once you have your reterences to VISA
COM in your project, you are ready to
create and use VISA COM I/0 objects
Included is an example of a simple method
that creates a resource and uses the ViSa
COM 488.2 Formatted 1/0 component
to communicate with a keysight 54501A
Oscilloscope. It is shown using both c#
and
C
private void doInstrumentIo()
Ivi Visa Interop. ResourceManagerClass rm new Ivi Visa Interop. ResourceManagerclass()i
Ivi Visa Interop. FormattedIo488Class ioobj= new Ivi Visa Interop. FormattedIo488Class()i
try
object[] idr
ioob. IO=(Ivi Visa Interop. IMessage)rm. Open("GPIB2: 10: INSTR",
Ivi Visa Interop. AccessMode NO LOCK ,0,l)i
ioob]. Writestring ("*IDN?", true)i
idnItems =(object[ ] )ioobj ReadList(Ivi Visa Interop. IEEEASCIIType ASCIIType Any,",")
foreach(object idnItem in idnItems
System. Console. Out. WriteLine("IDN Item of type " idnItem. GetType(). Tostring());
System. Console. Out. Writeline("\tvalue of item is"+ idnItem ToString())
catch(Exception e)
A YStem Console. Out. WriteLine("An error occurred: "+e Message)i
finall
yi ioobj IO Close(i y
catch i
tryi
System. Runtime InteropServices. Marshal. ReleaseComobject(ioob]);
catch i
tryi
System. Runtime InteropServices. Marshal. ReleaseComobject(rm)i
catch I
Keysight Using VISA COM I/O API in NET -Appl cation Note
VB
Private Sub DoInstrumentIO(
Dim rm As Ivi Visa Interop. ResourceManagerclass
Dim ioob] As Ivi Visa Interop. FormattedIo488Class
Dim idnItem As object
Dim idnItems As Object()
rm New Ivi Visa Interop. ResourceManagerClass
ioobj New Ivi Visa. Interop. FormattedIo488Class
ioob].Io= rm. Open("GPIB2:: 10:: INSTR")
ioobj.Writestring("*IDN?", True)
idnItems ioobj ReadList(IviVisaInterop. IEEEASCIIType ASCIIType Any, ",")
For each idnitem In idnttems
Ms gBox("IDN Item of type idnItem. GetType(). Tostring())
MsgBox("Value of item is " idnItem. Tostring()
Next idnitem
Catch e As Exception
MsgBox ("An error occurred: t e Message
Finall
ioob. IO. Close()
Catch ex As Exception
Try
System. Runtime InteropServices. Marshal. ReleaseComobject(ioob])
Catch ex As Exception
End卫
Tr
System. Runtime InteropServices. Marshal. ReleaseComobject(rm)
Catch ex As Exception
End T
y
End Sub
ppl cation No
Using Keysight VISA COM /0 in After creating the VISA COM/O
Advanced VISa Com/o
Microsoft visual studio
objects to be used, you see a call to
WriteString(). This call sends the
operations in. NET
The line Ivi Visa. Interop
*IDN? string to the instrument. The next
ResourceManagerclass rm
ine uses the readlist() method to
One of the design goals of Microsoft
newIviVisa Interop
parse the *IDN? return value. The method COM technology was to try to simplify
ResourceManagerclass()creates the returns an object, which you can cast to threading for typical COM programmers
Global Resource Manager(GRM), which an array based on the type parameter They used the concept of Apartments
can instantiate(create) any VISA COM
of the ReadList()Method. With type where certain threading behaviors were
resource installed on the system. Here AScIIType Any, the return value is an guaranteed so as to limit the possible
you see it used to open a GPIB resource at array of obiects
multithreading interaction the programmer
GPIB2. 10: INSTR". The line Ivi, visa
would have to detend against Perversely,
Interop. FormattedIo488Class
The code in the Finally block is designed this made thread programming signiticantly
iob]= new Ivi Visa. Interop. to clean up the l/0 to be sure that the
nore difficult in some cases. Microsofts
FormattedIo488Class()creates an 1/0 session is closed immediately, all
NET architecture has placed themulti-
instance of the 488.2 Formatted 1/0 Class, hardware v/O resources are released and threading burden back on the program-
which can help with parsing and writing
any valid Com ob ects are released. In
mer, and there are some interactions that
out the data types most instruments use. COM environments like Visual C++, it was must be guarded against when dealing
Setting the lO property of the formatted possible to destroy objects by removing
ith possible multithreaded situations
/0 object prepares the object for reading the last reference to them. but in the. NEt during VISA COM /O programming
and writing
environment, you must explicitly close
the session. Call the close( method
The programmer must worry about VISA
You may notice a few differences between on the Keysight VISA COM Formatted 1/0 COM/0 and threading when VISA events
C# and VB. These differences in large part session to cause the session to release any are used to communicate with a device
mirror the differences between Microsoft hardware 1/0 resources
This can take the form of asynchronous
Visual C++ 6 and Microsoft Visual Basic
170, handling service requests, and
6. Aside from the obvious syntactic
other VISA events. The following code
differences there is a capability difference
demonstrates handing an SRQ event on a
in how you can use vIsa CoM i/o. the
keysight 34401A multimeter. Only the VB
optional parameters on the o
version is included for brevity
methad in VB are not optional in C#t, and
optional parameters in general are lost
in c#
08 Keysight Using VISA COM I/O API in NET -Appl cation Note
VB
Public class form1
Inherits System. Windows Forms Form
Implements Ivi Visa Interop. IEventHandler
(extra VB stuff omitted)
Dim rm As Ivi Visa Interop. ResourceManager Class
Dim msg As Ivl. Visa. Interop. IMessage
Delegate Sub t srqEvent(Byval man As IviVisa Interop. IEventManager,
ByVal evnt As Ivi Visa Interop. IEvent
Public sub SrqEvent(ByVal man As Ivi Visa Interop. IEventManager,
ByVal evnt As Ivi Visa. Interop. IEvent)
man. Close()
evnt Close()
System. Runtime InteropServices. Marshal. ReleaseComobject( rm)
Catch
End Try
MsgBox("SRQ Occurred! " Ms gBoxStyle OKOnly,"SRQ Event")
End Sub
Private Sub DoAdvancedIO(
rm= New Ivi Visa Interop. ResourceManagerclass
msg= rm. Open("GPIB1:: 22:: INSTR")
DOGenerateSRQ(msg)
End sub
Public Sub DoGenerateSRQ(ByVal msg As Ivi Visa Interop. IMessage)
Dim eventman As Ivl. Visa. Interop. IEventmanager
eventman =msg
Reset dmm and clear DMm status registers
msg. Writestring("*RST; *CLs"& vlf
System. Threading Thread. sleep(500)
eventman. InstallHandler(Ivi Visa Interop. EventType EVENT SERVICE REQ, Me, 1000)
eventman. EnableEvent(Ivi Visa Interop. Eventrype EVENT SERVICE REQ
Ivi Visa Interop. EventMechanism EVENT HNDLR)
09 Keysight I Using VISA. COM I 0 API in. NET -Appl cation Note
Enable ' operation complete bit to set standard event bit in status byte
msg Writestring("*ESE 1"& vlf)
System. Threading. Thread. Sleep(500
Enable 'standard event bit in status byte to pull the IEEE-488 SRo line
String("sre 32 " vlf
System. Threading. Thread. Sleep(500
Assure synchronization
msg. Writestring(*OPC?"&vlF)
System. Threading. Thread. Sleep(500
recieve *oPc? result
msg. Readstring (1000)
set dmm to 10 volt dc range
msg Writestring("Configure: Voltage: dc 10& vbLf)
set integration time to 10 Power line cycles (PLC
msg Writestring("voltage: DC: NPLC 10"& vlf)
System. Threading. Thread. Sleep(500)
set dmm to accept 1 trigger
msg. Writestring(Trigger: count 1"& voLf
System. Threading Thread. Sleep(500)
Place dmm in 'wait-for-trigger, state
msg. Writestring("Init"& vlf
System. Threading Thread. Sleep(500)
Set ' operation complete bit in standard event registers when measurement is complete
msg.Writestring("*OPC"& vlf
End Sub
Public Sub HandleEvent(ByVal man As Ivi Visa Interop. IEventManager,
ByVal evnt As Ivi visa Interop. IEvent, ByVal unused As Integer) Implements
Ivi Visa. Interop. IEventHandler HandleEvent
Dim args()As Object
the threadsafe Invoke methods are the only safe thing to do in a CoM callback
args New Object(1)(man, evntH
Me BeginInvoke(New t srqEvent(Addressof Me. SrqEvent), args
End Sub
ppl cation No
Advanced /0 in Microsoft Visual VISA COM /0 and VB threading Conclusion
Studio
One of the few safe method calls in such
The doAdvancedIo( method creates
a context is the BeginInvoke()method VISA COM I/0 is a viable method
the /0 session and passes it to the
of the. NET System. WindowsForms
of programming instruments in Microsoft's
Control class. This method accepts a
B and Ct languages, which live in the
DoGeneratesro( method, which
NET Delegate cass, which is a wrapper
NET execution environment. Both tools
generates a service request and
for a method. We wrap up a method on
can quickly import the VISA COM1/0
enables event handling. The VB class
Forml implements the VISA COM/0
the form abject called SrqEvent() that types for use in a relatively straightforward
interface EventHandler. This class ha
we want to do useful things on the VB. Et fashion. While the Keysight T&M Toolkit
one method, HandleEvent(), which
orm class when an event occurs. The
provides the best solution for simple. NE
is called by VISA COM 1/0 whenever an BeginInvoke()method then queues up
T&M programming tasks, basic and even
event the client is interested in occurs
a request on the application's main thread advanced l/0 operations are possible with
The InstallHandler() method call
to call the delegate's underlying method
VISA COM I/O and the Microsoft. NET
informs visa COM to call the forms
on the form's main thread when it is free. programming languages
HandleEvent() method implementation As a consequence, you have to make sure
whenever an SrQ event occurs. The
that the application s main thread is active
EnableEvent()call turns on asynchro
and not occupied in a blocking task. Also
nous handler invocation for SrQ events
to receive the visa com event at all your
application cannot be blocking if it is
The HandleEvent() method does not
single-threaded. In a console application,
have much code in it. This is because whel
this usually means calling Applic.
you rece ve an event from VISA COM 1/0
DoEvents()occasionally to give queued
ye don't know what thread it
asynchronous COM events an opportunty
InVB 6, you could be certain that it was to execute on the application s only thread
the applications main thread because VB
6 used apartment threading, guaranteeing ySA COM 1 /0 and VB threading
a single-threaded environment for Com
VISA COM 1/0
B application
and VB methods. In an attempt to reduce
erhead and complex implementation
errors. Microsoft has abandoned this
VISA COM
VB Form1
strategy and it is up to the user to
1/0 worker
object main
recognize that this method call occurs
re
VISA COM
thread
Methods
in an unknown thread context. As a
VISA COM
Write(, Read(), etc
consequence, you must know which. NET
asynchronous
Srq event(
methods are thread-specific and which
event threat
BeginInvoke()
ones are not, and be aware of your current
threading context. Most form methods ar
Handle Event() VISA
CoM 1/0 callback
thread-specifiC, so you must be carefu
lEventManager
Handle Event(
what methods you use
This diagram shows the thread interaction
going on in the sample code above
assuming the application is multi-
threaded
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.