Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Beginner still needs help with SimpleReadWrite

Solved!
Go to solution

After reviewing NI-488.2\Examples\DotNet3.5\SimpleReadWrite\vb (which runs very well) in the "step" mode I still cannot discover the command that

 

sends string information to the device. If I declare: Dim BoardID As String ="0", Dim PrimaryAddress As String = "13", Dim SecondaryAddress As String =

 

 "0", Dim Command1 As String = "*IDN?" what comes next?. Is this the correct approach? What else do I need to know and where/how can I find it?

0 Kudos
Message 1 of 7
(5,372 Views)
The SimpleReadWrite example is fairly self-explanatory. The openButton_Click function opens the GpibDevice. Clicking on the Write button executes the writeButton_Click function which calls the GpibDevice.Write method with the string to send. Are you having problems understanding the VB code, or the library? The library help file can be accessed from the Start -> All Programs -> National Instruments -> NI-488.2 -> NI-488.2 .NET Framework 3.5 Help.
0 Kudos
Message 2 of 7
(5,361 Views)

I have stepped through the program and can see fundamentally how it works. Yes being new to VB code I'm still near the bottonm of the learning curve; many commands and syntax I do not yet understand. I would like to  put text boxes, button clicks and error handling aside for now and just send a simple command string to the instrument, like in the example attached, which, of course won't work until I find the magic words.

 

ATTEMPT1.jpg

0 Kudos
Message 3 of 7
(5,338 Views)

If you're new to VB.NET then you should really find some tutorials on the internet or pick up a book. You don't want to be fighting trying to decipher the language while you're also trying to figure out how to use a library.

 

Your screenshot is all scrunchy, so it's hard to read. However, it seems as if you just have a form with no controls, so you basically want to send a command as soon as the form loads. Hence, the code being in the Form1_Load function. As far as the code, you need to declare the object "GpibDevice". Thus, you need an additional Dim statement:

Dim GpibDevice As Device

That will get rid of the squiggly lines that you see in your code.

 

Then, your first statement in Form1_Load should be 

GpibDevice = New Device(BoardID, PrimaryAddress)

if your device has just a primary address. Otherwise, it would be

GpibDevice = New Device(BoardID, PrimaryAddress, SecondayAddr)

Note that BoardID should be an Integer, not a String, and both PrimaryAddr and SecondaryAddr should be a Byte datatype, not a String.  If you keep them as String then you will need to use the CInt and CByte functions as shown in the NI example (see the openButton_Click function).

 

You can the write your command to the device with GpibDevice.Write(Cmd1).  If your device requires a termination character, like a linefeed, then you can just follow the method that's shown in the NI example. There, the command string that's in the textbox has a "\n" to indicate a linefeed as a termination character. A support function is in the example to convert these "escape" characters to control characters. That's the "ReplaceCommonEscapeSequences" function. Thus, the write command would be GpibDevice.Write(ReplaceCommonEscapeSequences(Cmd1)).

 

Finally, you should close the device with GpibDevice.Dispose().

 

Thus, your Form1_Load would look like this:

GpibDevice = New Device(BoardID, PrimaryAddress)

GpibDevice.Write(ReplaceCommonEscapeSequences(Cmd1))

GpibDevice.Dispose()

 

NOTE: Be sure that the NationalInstruments.Common and NationalInstruments.NI4882 assemblies are in your project's list of references. Again, refer to example.

0 Kudos
Message 4 of 7
(5,333 Views)

I will surely find a tutorial or pick up a book to learn more about VB.NET as soon as I can get this thing going. Any recommendations for study?

I have entered the code that you supplied in your last reply and went back through the example to find out what might be going wrong. There are still some errors (please see attached). Can you help once again?

EXAMPLE.jpg

0 Kudos
Message 5 of 7
(5,302 Views)
Solution
Accepted by topic author TesTech

You did not add the assemblies to your project's list of references, as I indicated in my note at the end of my lat reply. This is done via the Project -> Add Reference ... menu item. Be sure to select the assemblies that are in the VS2008 folder, in case you installed support for more than one .NET version. This is separate from the requisite Imports statements. The Imports statement simply allows you to not have to write out the full name of the class. So, by having an Imports NationalInstruments.NI4882 you can declare a variable as

Private GpibDevice As Device

instead of the full name

Private GpibDevice As NationalInstruments.NI4882.Device

 

As for the ReplaceCommonEscapeSequences error, well, you actually need that function in your form. Copy that function from the SimpleReadWrite example.

 

You should verify what your device expects for the command. Does it require a carriage return after the command? Does it require a linefeed? If so, you need to change the definition of Cmd1 to include these characters, as is done in the SimpleReadWrite example.

 


TesTech wrote:

I will surely find a tutorial or pick up a book to learn more about VB.NET as soon as I can get this thing going.


That's just making life 100x more difficult for you. The above errors would have been clear if you knew how to program in VB.NET.

 

Message 6 of 7
(5,296 Views)
Thanks for your help. The code seems to work now. I can use this to build on.
0 Kudos
Message 7 of 7
(5,288 Views)