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

hi:

   I want to save the screenshot to the instrument and transfer it to the computer via GPIB.But I can only pass 4096 bytes!

   I tried to use loops,viSetBuf, viRead,viReadToFile and viVScanf , but they all failed.

 

This's my code:

 

status = viSetBuf(vi, VI_READ_BUF, 60000)
status = viSetBuf(vi, VI_WRITE_BUF, 60000)

 

status = viVPrintf(vi, ":SYST:COMM:GPIB:RTER EOI" + vbCrLf, 0) 
status = viVPrintf(vi, ":HCOP:DEV:LANG WMF" + vbCrLf, 0)

status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 20000) 
status = viVPrintf(vi, ":HCOP:DEST1 'MMEM'" + vbCrLf, 0) 
status = viVPrintf(vi, ":MMEM:NAME 'C:\USER\DATA\FILE.WMF'" + vbCrLf, 0) 

status = viVPrintf(vi, ":HCOP" + vbCrLf, 0) 
Threading.Thread.Sleep(2000)

status = viVPrintf(vi, ":MMEM:MSIS 'C’" + vbCrLf, 0) 

status = viVPrintf(vi, ":MMEM:CDIR '\USER\DATA\'" + vbCrLf, 0) 
status = viVPrintf(vi, ":MMEM:DATA? 'FILE.WMF'" + vbCrLf, 0) 

Dim fanal As String = ""
Do
status = viRead(vi, strRes, 4096, retCount)
Dim x As Integer = Val(Mid(strRes, 2, 1))
Dim y As Integer = Val(Mid(strRes, 3, x))
strRes = Mid(strRes, x + 3, y)
fanal = fanal & strRes

Loop Until (retCount < 4096)

 

 

 

FileOpen(1, Application.StartupPath + "\YouName.WMF", OpenMode.Output) 
Print(1, fanal)
FileClose(1)

status = viSetBuf(vi, VI_READ_BUF, 4096) 
status = viSetBuf(vi, VI_WRITE_BUF, 4096) 
status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 2000) 
status = viVPrintf(vi, ":SYST:COMM:GPIB:RTER LFEOI" + vbCrLf, 0)

  

 

0 Kudos
Message 1 of 31
(3,950 Views)

Is the issue that the screenshot is larger than 4096 bytes? Maybe we can compress it to make it smaller. Have you been able to test your code with another file that is less than 4069 bytes? 

 

I found this forum post with a similar question that you may find useful. Take a look at the solution and see if it helps!

https://forums.ni.com/t5/Instrument-Control-GPIB-Serial/How-to-Transfer-File-from-PC-to-Instrument-v...

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 31
(3,923 Views)

Thank you for your reply
First, this is not a screenshot file larger than 4096 bytes, but a file transfer can only pass 4096 bytes. So the question should be how to transfer large files instead of compressing them.
Second, instead of writing the file to the instrument, the file is transferred from the instrument.

0 Kudos
Message 3 of 31
(3,918 Views)

To clarify, you're trying to transfer a file larger than 4096 bytes to your instrument, correct? 

What instrument are you using? The protocol will likely be specific to your hardware. 

I think the easiest way to overcome the 4096 byte limit would be to break the files into chunks and transfer them separately, or compress them. What's stopping you from doing so? 

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 31
(3,909 Views)

I want to transfer files larger than 4096 bytes from the instrument to the PC. The instrument's buffer is only 4096 bytes. I can only read the first package, after which the package is lost.

0 Kudos
Message 5 of 31
(3,905 Views)

It looks like you can change the buffer size using the DefaultBufferSize command. See this document for details:

http://zone.ni.com/reference/en-XX/help/370627F-01/mstudiowebhelp/html/9505ee1c/

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 6 of 31
(3,889 Views)

I had try to set buffer size. but it no impact.

status = viSetBuf(vi, VI_READ_BUF, 60000)
status = viSetBuf(vi, VI_WRITE_BUF, 60000)

0 Kudos
Message 7 of 31
(3,869 Views)

Since you are using VISA .NET, I would recommend checking out the VISA .NET library as it lists a different method than viSetBuf() for setting the buffer size. You can download the library from the linked website and navigate in the help .CHM file to the SetBufferSize Method page, which shows an example of how to use it as well as additional help details.

Applications Engineering
National Instruments
0 Kudos
Message 8 of 31
(3,862 Views)

thanks

1,I am using visa.dll instead of NationalInstruments.Common.dll

2,I don't think it's a buffer size problem, but how to read it continuously.

0 Kudos
Message 9 of 31
(3,855 Views)

What do you mean by "read continuously"? It sound like you are trying to read a file that is larger than the default buffer. 

 

I noticed this part of your code references the 4096 buffer size too. Have you changed this to your larger buffer size of 6000? 

 

Dim fanal As String = ""
Do
status = viRead(vi, strRes, 4096, retCount)
Dim x As Integer = Val(Mid(strRes, 2, 1))
Dim y As Integer = Val(Mid(strRes, 3, x))
strRes = Mid(strRes, x + 3, y)
fanal = fanal & strRes

Loop Until (retCount < 4096)

 

Also, the viSetBuf command is called twice, once at the beginning and again at the end. Make sure to change both of these to 6000.

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 10 of 31
(3,847 Views)