Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

viwrite byte

Hello
 
I am having problems passing a string into my viwrite command.  I am doing a translation from VB to C# and obviously things are not as straightforward. The piece of code that does not work is
 
The string I am passing is "*IDN?" - it works in VB but NOT in C# - how can I typecast or find a way to pass in the string ?
 
C#
 
byte[] buffer
public static extern int viWrite(int vi, byte[] buffer, int count, out int retCount);
 
VB

by val buffer as string
 viWrite Lib "VISA32.DLL" (ByVal vi As Long, ByVal Buffer As String, ByVal count As Long, retCount As Long) As Long
0 Kudos
Message 1 of 6
(5,115 Views)
Hey slowslc,

Thank you for contacting National Instruments.  There is a great example in Visual Studio of how to program simple read and write in C#.  The file is located in
C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\Visa\SimpleReadWrite\cs
This example will show you how to correctly pass in the string in C#.  The only thing you need to have is Visual Studio support installed with the driver you are using.  If you have Visual Studio 2003 the only difference in the location of the directory will be \MeasurementStudioVS2003\

Regards,
Jason W
Application Engineer
National Instruments


0 Kudos
Message 2 of 6
(5,086 Views)
I have a similar problem, but this directory does not exist:
 
C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\Visa\SimpleReadWrite\cs
I do have up to here:
 
C:\Program Files\National Instruments\MeasurementStudioVS2005\DotNET\Examples\GPIB\
Jacob Christ
0 Kudos
Message 3 of 6
(4,941 Views)
Actually, I would like to elabirate on my problem...
 
I've ported an old VB6 application that uses NIVISA32.DLL to VB.NET 2005 and I'm trying to call viReadBytes but when when the COM function ported over it delclaried the Buffer as a referance to a Byte and I can't pass a referance to an array of Bytes.
 

Declare Function viReadBytes Lib "VISA32.DLL" Alias "#256" (ByVal vi As Integer, ByRef Buffer As Byte, ByVal count As Integer, ByRef retCount As Integer) As Integer

Alternativly, can use viRead and use a String buffer, but I have binary data comming back from my Tek220 and the conversion of the data from a string is acting funny.  (Incomplete data or sometime wrong data).
 
Jacob Christ
 
0 Kudos
Message 4 of 6
(4,935 Views)
Hey Jacob,

Do you have the NI-VISA driver installed?  You will not have the VISA DotNET examples if you do not have the driver installed or if you didn't install Measurement Studio VS 2005 support when you installed the VISA driver.  You can get the latest version of the driver here.
 
If you do have NI-VISA installed, what version is it? 

Also, when you say the
conversion of the data from a string is "acting funny", what do you mean by this?

Regards,

Jason W
Applications Engineer
National Instruments
0 Kudos
Message 5 of 6
(4,916 Views)

Sorry, I forgot to post the link.


Latest version of NI-VISA

Jason W

 
0 Kudos
Message 6 of 6
(4,913 Views)