You are on page 1of 5

FAQ

Instrument Solution FAQ


Solution Title
C#.NET 2010 example: VISABasic
Date:09/12/2011
Solution: We have created a small example to show how to remotely connect to an
instrument using NI VIS!
"his example allows you to esta#lish a message$#ased VIS session with the
instrument% send commands% and receive data &rom an instrument!
It utili'es !N(" &ramewor) *!0 and National Instruments VIS !
+ere is the design o& the &orm,
Added Controls
-ty 1 .om#o #ox,
cboVISARsrc - +olds instrument VIS resource I/!
-ty * 0uttons,
btnOpen - 1pens VIS session
btnClose $ .lose VIS session
btnWrite Writes to instrument
btnRead 2eads &rom instrument
-ty 2 "ext #ox
txtWrite "ext#ox to hold command to write
txtRead "ext#ox to show read data
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using NationalInstruments.VisaNS;
VIS!"asic is a small application created to gi#e
users an e$ample o% VIS! &ased instrument communications.

'(is app utili)es .N*' Framewor+ ,.- and t(e associated National Instruments VIS!
Common and VIS!NS
re%erences.

./ *nter VIS! resource ID


0/ 1ress 2pen &utton to created new message &ased VIS! session
3/ *nter instrument speci%ic command in Command Window
,/ 1ress Send "utton
4/ I% t(e command is a 5uery 6terminating in a 787/9 press :ead to return
instrument response

'(is application is pro#ided as-is. No support or warranty is e$pressed or implied.

!ut(or; <C
Company; :igol 'ec(nologies9 Nort( !merica
Date; -=.-=.0-..
namespace WindowsForms!pplication.
>
pu&lic partial class Form. ; Form
>
pri#ate Message"asedSession m&Session; Create Message &ased session

pu&lic Form.6/
>
Initiali)eComponent6/;
?

pri#ate #oid &tn2pen@Clic+6o&Aect sender9 *#ent!rgs e/ 2pen a VIS! Session
>
string strVIS!:src B c&oVIS!:src.'e$t; Cet VIS! resource ID %rom com&o&o$

try
>
m&Session B 6Message"asedSession/:esourceManager.CetDocalManager6/.2pen6strVIS!:src/;
Instantiate and open a Message "ased VIS! Session

?
catc(6In#alidCast*$ception/
>
Message"o$.S(ow6E:esource selected must &e a message-&ased sessionE/;
?
catc(6*$ception e$p/
>
Message"o$.S(ow6e$p.Message/;
?
?

pri#ate #oid &tnClose@Clic+6o&Aect sender9 *#ent!rgs e/ Close VIS! session
>
try
>
m&Session.Dispose6/;
?
catc( 6*$ception e$p/
>
Message"o$.S(ow6e$p.Message/;
?
?
pri#ate #oid &tnWrite@Clic+6o&Aect sender9 *#ent!rgs e/
Write command to VIS! resource
>
string strWrite B t$tWrite.'e$t; Cet command %rom te$t &o$
try
>
m&Session.Write6strWrite/; Send Write command to VIS! resource
?
catc( 6*$ception e$p/
>
Message"o$.S(ow6e$p.Message/;
?
?

pri#ate #oid &tn:ead@Clic+6o&Aect sender9 *#ent!rgs e/
:ead command %rom VIS! resource
>
string str:ead B null;
try
>
str:ead B m&Session.:eadString6/; :ead string %rom VIS! resource
t$t:ead.'e$t B str:ead;
?
catc( 6*$ception e$p/
>
Message"o$.S(ow6e$p.Message/;
?
?
?
Figure 1: Project properties and references.

You might also like