09-28-2016
06:18 AM
- last edited on
01-03-2025
05:01 PM
by
Content Cleaner
Hi,
I've created an app based on the following example.
I'm sending ByteArray to my device in packets of 32768 bytes.
If I check the data been transfered with NI I/O Trace I can see that the data is transfered with the exact packet size (32768).
If I try to send the data with a bigger size of packets (for example 65536 bytes) I can see that the data is transfered with that correct size (in NI I/O Trace) but the total time to send all the ByteArray remain the same, so I think that the buffer in visa is smaller and that is devided the size that I'm sending.
Is there any chance to change the buffer size?
I can't find the "viSetBuf" property.
Any help would be highly appreciated.
Thanks.
09-29-2016
05:15 PM
- last edited on
01-03-2025
05:01 PM
by
Content Cleaner
Hi,
Were you able to try this?
http://zone.ni.com/reference/en-XX/help/370627F-01/mstudiowebhelp/html/9505ee1c/
10-05-2016 01:46 AM
Hi,
Sorry for the delay with the reply.
I did try that already, unfortunately it seems that no matter the size of the buffer that is written in the DefaultBufferSize, the time it takes to send all the data is the same (I check with NI I/O Trace, and with a Stopwatch from System.Diagnostics ).
Regards.
10-06-2016 12:22 PM
You're calling the DefaultBufferSize function before you send your data, correct?
Have you tried very smaller buffer sizes, and do you get the same results?
Can you share any code snippets?
10-09-2016 12:54 AM
Hi,
I am setting the DefaultBufferSize parameter before sending the data.
I've tried to send the data in smaller packets but once again the overall time is nearly the same:
Sending data size of 32 MB in packets of 512 bytes take 41.19 seconds.
Sending data size of 32 MB in packets of 32768 bytes take 41.03 seconds.
Sending data size of 32 MB in packets of 131072 bytes take 40.92 seconds.
My code:
Stopwatch sw = Stopwatch.StartNew();
int NumOfDigits = 0;
byte[] sendArray;
string ResponseString = null;
try
{
//open a Session to the VNA
MbUnitSession = ( MessageBasedSession )ResourceManager.GetLocalManager().Open( UnitAddress );
Thread.Sleep( 100 );
// init mbUnitSession
MbUnitSession.Timeout = 15000;
MbUnitSession.SendEndEnabled = true;
MbUnitSession.TerminationCharacterEnabled = true;
MbUnitSession.DefaultBufferSize = Globals.BUFFER_SIZE; // buffer size is 32768
//** communication with device **//
//Send "*IDN?" command and read the response
ResponseString = WriteToVisa( MbUnitSession, "*IDN?" );
//Send "*rst" command
WriteToVisa( MbUnitSession, "*RST" );
Thread.Sleep( 1000 );
int s = Globals.CurrentWaveLength * 2; // waveLength is 32000000
WriteToVisa( MbUnitSession, ":FREQ:RAST" + "1e9" );
ResponseString = WriteToVisa( MbUnitSession, ":FREQ:RAST?" );
// Select User (Arbitrary Wave) Mode
WriteToVisa( MbUnitSession, ":FUNC:MODE USER" );
// Delete all segments
WriteToVisa( MbUnitSession, ":TRAC:DEL:ALL" );
// Define segment + select segment 1
string msg = ":TRAC:DEF 1," + Globals.CurrentWaveLength + ";:TRAC:SEL 1;";
ResponseString = WriteToVisa( MbUnitSession, msg );
// set new timeout
MbUnitSession.Timeout = Globals.CurrentWaveLength;
NumOfDigits = Convert.ToInt32( Math.Floor( Math.Log10( s ) + 1 ) );
WriteToVisaNoOPC( MbUnitSession, ":TRAC:DATA#" + NumOfDigits + ( s ) );
int arrSize = Globals.ByteArray.Count(); // ByteArray contain the bytes to send to the unit, size is 64000000
// loop that sends chunks of the array in the size of the buffer
for( int i = 0; i < Globals.ByteArray.Count(); i += Globals.BUFFER_SIZE )
{
if( arrSize >= Globals.BUFFER_SIZE )
{
sendArray = new byte[Globals.BUFFER_SIZE];
Buffer.BlockCopy( Globals.ByteArray, i, sendArray, 0, Globals.BUFFER_SIZE );
arrSize -= Globals.BUFFER_SIZE;
}
else
{
sendArray = new byte[arrSize];
Buffer.BlockCopy( Globals.ByteArray, i, sendArray, 0, arrSize );
}
//Write Binary Data
WriteToVisaByteArray( MbUnitSession, sendArray );
}
// select channel 1 + turn channel 1 outputs on
ResponseString = WriteToVisa( MbUnitSession, ":INST:SEL 1;:OUTP ON" );
// set amplitude
WriteToVisa( MbUnitSession, ":VOLT 2.000e0" );
// set selected channel on
WriteToVisa( MbUnitSession, "outp on" );
MbUnitSession.Dispose();
if( showTime == true )
{
// display the time it takes to download the data to the unit
MessageBox.Show( "Download time is: {0:f2} s" + sw.Elapsed.TotalSeconds );
}
}
catch( InvalidCastException )
{
MbUnitSession.Dispose();
}
catch( Exception )
{
MbUnitSession.Dispose();
}
WriteToVisa is a function that sends a string to the unit with "*OPC?" command and return a response.
WriteToVisaNoOPC is a function that sends a string to the unit without "*OPC?" command and return a response.
WriteToVisaByteArray is a function that sends a byte array to the unit and not return anything.
Thank you for all your help.
10-10-2016 04:14 PM
What is your goal? Are you trying to speed up the transmitting of this file?
If you are trying to speed up the transmitting of the file, you will need to change the file size or baud rate. Changing the packet size won’t change the overall time significantly.
What VISA protocol are you using (UART,SPI, etc.)?
10-18-2016 12:05 AM
My goal is to speed up the transmission of my data.
The data size can vary between 384 bytes to 64000000 bytes.
The communication protocol is USB, LAN or GPIB.
How can I change the baud rate?
Thanks.
10-19-2016
10:33 AM
- last edited on
01-03-2025
05:03 PM
by
Content Cleaner
You can see how to change the baud rate in the NI VISA Programmer Manual (see first link).
https://www.ni.com/docs/en-US/bundle/ni-visa/page/user-manual-welcome.html
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YFtTCAW&l=en-US#toc3