Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use VB.NET and VISA for file transfer?

Solved!
Go to solution

thanks

yes,i need to transfer a image file from the instrument to the computer that is about 60k bytes.

0 Kudos
Message 21 of 31
(2,342 Views)

Have you downloaded the driver for Measurement Studio from this link? http://sine.ni.com/apps/utf8/niid_web_display.model_page?p_model_id=1164

 

If so, did it come with any example programs that show how to do this?

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 22 of 31
(2,331 Views)

Thank you
First of all, the entire program is designed based on visa32.dll. I don't want to change the way if it is not necessary. Such as "Ivi.Driver.Interop" or "Ivi.Visa.Interop". or visaNS. Especially because of your NI driver and Agilent drive conflicts. This caused us to encounter many problems during development. Use visa32.dll to compare two drivers.

Then, no one knows how to use "ViRead" continuously?

0 Kudos
Message 23 of 31
(2,316 Views)

Hi 

The viRead says that: "Only one synchronous read operation can occur at any one time"

0 Kudos
Message 24 of 31
(2,310 Views)

Thank you
It turned out to be because of this. So what function can send files to the computer in a subcontracted way? The instrument's buffer is only 4096 bytes at the maximum.

0 Kudos
Message 25 of 31
(2,306 Views)

Hello,

 

Your code 

 


 

If status <> VI_SUCCESS Then
VisaErrorHandler()

End If

is not correct if you want to read in several parts:  if the reading stops because the buffer gets full (EOI not asserted),  then viRead will return  VI_SUCCESS_MAX_CNT , you should not consider this as an error but an invitation to repeat the redaing to get the next part of the message.  BTW.  NI application engineers  should know that too 🙂

 

0 Kudos
Message 26 of 31
(2,175 Views)
Solution
Accepted by topic author xiaochouyu

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

A better way is to use "StringBuilder" instead of "String"!When you use .NET!

 

0 Kudos
Message 27 of 31
(2,079 Views)

A better way is to use "StringBuilder" instead of "String"!When you use .NET!

 


There is no difference here: both String and StringBuilder are marshalled via a null-terminated string (LPStr), see: https://docs.microsoft.com/dotnet/framework/interop/default-marshaling-for-strings

therefore your Buffer parameter is equivalent to:

<MarshalAs(UnmanagedType.LPString), Out()>ByVal Buffer As StringBuilder

Note that in both cases you need to provide an extra space for the null-termination. Anyway if your data is an image it is clearer and safer to pass it as a byte array rather than a string, so that there is no termination issue:

<MarshalAs(UnmanagedType.LPArray), Out()> ByVal Buffer As Byte()

 

 

 

 

0 Kudos
Message 28 of 31
(2,069 Views)

thanks

I've thought about using byte (), but Viread transfers files by "#" marking the length of the file. And it's passed in string format. Now it looks like the file transferred is wrong.

I didn't find out how to set up hexadecimal or Byte transfers in the document. Excuse me, how to deal with it?

0 Kudos
Message 29 of 31
(2,053 Views)

Just now I tried to use Byte (), and the result of transmission is the same as that of Stringbuilder.

 There are always "2Courier New" characters in the file.

0 Kudos
Message 30 of 31
(2,046 Views)