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

1,yes, I'm trying to read a file that is larger than the default buffer. 

2,I changed different viSetBuf and viRead  values in this code. They don't work.Setting the buffer size does not seem to work. It may be because the instrument itself has a memory limit.

3,The viSetBuf is called twice because the second setting is set back to the default value.

 

0 Kudos
Message 11 of 31
(1,619 Views)

I see... what type of instrument are you using? Perhaps the buffer size of the instrument is smaller than what you're trying to set it to. Have you tried setting a buffer size larger than 4096 but smaller than 60,000 (since that's a pretty big leap and likely over the memory limit)? Did you mean to set it to 6000 instead of 60,000? 

Francine P.
Applications Engineering
National Instruments
0 Kudos
Message 12 of 31
(1,611 Views)

   I use Rohde & Schwarz FSEA30 and Keysight  82357B USBGPIB converter.

I emphasize that this problem is not in the buffer size. Even if you can set the buffer to the maximum, but if the file is larger, it will not be transferred. Therefore, the focus of the discussion should be on how to ensure that the second reading is correct.

0 Kudos
Message 13 of 31
(1,598 Views)

Hi xiaochouyu,

 

What driver are you using to communicate with these instruments? Also how did you come to the conclusion that you are seeing a maximum buffer size of 4096? Are you receiving an error when you try to run your program?

 

According to our help documentation for the VISA Set I/O Buffer Size: Not all serial drivers support user-defined buffer sizes so some implementations of VISA might not be able to perform this operation. If an application requires a specific buffer size for performance reasons and the VISA implementation cannot guarantee that size, use some form of handshaking to prevent overflow conditions.

 

http://zone.ni.com/reference/en-XX/help/371361N-01/lvinstio/visa_set_i_o_buffer_size/

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 14 of 31
(1,584 Views)

thanks

I emphasize that this problem is not in the buffer size. Even if you can set the buffer to the maximum, but if the file is larger, it will not be transferred. Therefore, the focus of the discussion should be on how to ensure that the second reading is correct.

0 Kudos
Message 15 of 31
(1,580 Views)

Hi xiachoyu,

 

Thank you for the clarification. The reason that I emphasized buffer size in my last post is because not all drivers may be able to perform the operation of setting the buffer size to the maximum. Do you get an error when you try to set the buffer to the maximum but the file does not transfer? If so, could you post a screenshot? 

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 16 of 31
(1,569 Views)

Regardless of whether I use loops or not, the result is only 30-50 bytes:

This is one of the results, and it's only 36 bytes. And in fact, he should have 59936 bytes.

“#559936淄茪      ??     sW  u ”

0 Kudos
Message 17 of 31
(1,562 Views)

No matter how big my buffer is (than 4096). The number of bytes returned is 4096 bytes.You can know the number of bytes read by the return value "retCount".

viRead(vi, Buffer, Count, retCount)

 viReadToFile(vi, filename, Count, retCount)——"Count"is the target number of bytes,"retCount"is the number of bytes actually read.

 

Of course, I also tried different ways of using "viRead" and "viReadToFile".

viRead——only read 36 bytes(but retCount is 4096)

viReadToFile——can read 4096bytes

but they all can't  read the second time.

 

so I think the root of the problem lies in how to use "viRead" multiple times.

 

Attachments are the results that are read in two different ways.

 

Download All
0 Kudos
Message 18 of 31
(1,559 Views)

I add a code that judges the error:

 

If status <> VI_SUCCESS Then
VisaErrorHandler()

End If

 

"ViRead" directly causes the program to crash.

 

"ViReadtoFile" show this error:

Error:VI_ERROR_TMO:A timeout occurred

 

Whether my time is set to 20,000 seconds or 200000 seconds. Also, whether my Count value is set to 5000 or 50000.The result is always a timeout error and 4096 bytes.

 

 I found that setting the buffer size failed.

Error:VI_ERROR_ALLOC:insufficient system resources/memory.

So the instrument's buffer is only 4096 bytes.

0 Kudos
Message 19 of 31
(1,522 Views)

Hi xiaochouyu,

 

I'm glad you were able to narrow down the error you are getting and determine that your instrument's buffer size is what is causing the 4096 byte limit. This explains why you have not been able to increase the buffer size to be greater than 4096.

 

Taking a step back, your goal is to transfer a file from the instrument to the computer that is larger than 4096 bytes, correct?

Adena L.
Technical Support Engineer
National Instruments
0 Kudos
Message 20 of 31
(1,505 Views)