Agilent Technologies N5183A MXG User Manual

Page 342

Advertising
background image

332

Agilent N518xA, E8663B, E44x8C, and E82x7D Signal Generators Programming Guide

Creating and Downloading User-Data Files
Save and Recall Instrument State Files

string retValue = "";

byte[] buf = new byte[MAX_READ_DEVICE_STRING]; // 1024 bytes maximum read

uint retCount;

if (VisaInterop.Read(device, buf, (uint)buf.Length -1, out retCount) == 0)

{

retValue = Encoding.ASCII.GetString(buf, 0, (int)retCount);

}

return retValue;

}

/* The following method reads a SCPI definite block from the signal generator

and writes the contents to a file on your computer. The trailing

newline character is NOT consumed by the read.*/

static public void ReadFileBlock(uint device, string fileName)

{

// Create the new, empty data file.

FileStream fs = new FileStream(fileName, FileMode.Create);

// Read the definite block header: #{lengthDataLength}{dataLength}

uint retCount = 0;

byte[] buf = new byte[10];

VisaInterop.Read(device, buf, 2, out retCount);

VisaInterop.Read(device, buf, (uint)(buf[1]-'0'), out retCount);

uint fileSize = UInt32.Parse(Encoding.ASCII.GetString(buf, 0, (int)retCount));

// Read the file block from the signal generator

byte[] readBuf = new byte[TRANSFER_BLOCK_SIZE];

uint bytesRemaining = fileSize;

while (bytesRemaining != 0)

{

uint bytesToRead = (bytesRemaining < TRANSFER_BLOCK_SIZE) ?

bytesRemaining : TRANSFER_BLOCK_SIZE;

VisaInterop.Read(device, readBuf, bytesToRead, out retCount);

fs.Write(readBuf, 0, (int)retCount);

bytesRemaining -= retCount;

}

// Done with file

fs.Close();

}

/* The following method writes the contents of the specified file to the

specified file in the form of a SCPI definite block. A newline is

Advertising
This manual is related to the following products: