Thread: HP3458 Digitizing - Return Data in SINT Format


Permlink Replies: 9 - Pages: 1 - Last Post: Aug 29, 2011 8:54 AM Last Post By: spacecowboy
spacecowboy

Posts: 9
Registered: 06/13/11
HP3458 Digitizing - Return Data in SINT Format
Posted: Jul 15, 2011 9:46 AM
Click to report abuse...   Click to reply to this thread Reply
Hello!

Using the HP3458A In digitizing mode, we are trying to use the SINT data format, to allow
faster sampling rates for us.
We understand the SINT data comes back in binary format. We are having issue's
decoding the binary data into an integer or double number.

Quoting from User manuel:
'SINT Example The following program outputs 10 readings in SINT format, retrieves the
'scale factor and multiplies the scale factor times each reading. The readings
'are transfcrred to the controller using the TRANSFER statement (this
'100 Chapter 4 Making Measurements
'command is specific to Hewlett-Packard 200/300 controllers using BASlC
'language). The TRANSFER statement is the fastest way to transfer readings
'across the GPIB, especially when used with the direct memory access (DMA)
'GPIB interface. You should use the TRANSFER statement whenever
'measurement/transfer speed is important.

We are using the GPIB bus to transfer the data to the host pc.
Subset of our code:
Call ibwrt(dev, "PRESET DIG")
Call ibwrt(dev, "OFORMAT SINT")
Call ibwrt(dev, "APER, 0")
Call ibwrt(dev, "SWEEP 15.259e-6, " & numofdata)
Call ibwrt(dev, "MEM FIFO")
Call ibwrt(dev, "TRIG LEVEL")
Call ibwrt(dev, "SLOPE NEG")
Call ibwrt(dev, "Level 10, DC")
Call ibwrt(dev, "TARM SGL")
Call ibwrt(dev, "RMEM 0,1")
Call ibrd(dev, RRdata)

RRdata contains the data returned form the HP.
We'd like to know how to decode this. The manuel says it's a 2 byte's per sample.
When we change to an ASCII format, things are working fine. But we need the SINT
for faster rates.

Any help?
lhornburg

Posts: 475
Registered: 01/15/10
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Jul 18, 2011 10:07 AM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
Data formatting is a pain when using the 3458A, what programming environment are you using? C, C#, VB, VEE, Matlab, Labview, etc....

I can try and provide an example if I know which one you are using.
spacecowboy

Posts: 9
Registered: 06/13/11
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Jul 18, 2011 11:06 AM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
Hi, thanks for digging a bit.
We are in VB.
spacecowboy

Posts: 9
Registered: 06/13/11
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Aug 10, 2011 1:19 PM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
Hi, just following up.
C or C# will be fine too if that helps get an example.
Again, appreciate your help.
lhornburg

Posts: 475
Registered: 01/15/10
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Aug 10, 2011 6:01 PM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
#include <cstring>
#include <stdlib.h>
#include <stdio.h>
#include <visa.h>
#include <iostream>
#include <fstream>



using namespace std;


//
// This macro simplifies the reading of code and yet provides error checking
//
#define CHECK(func) \
do {\
ViStatus _s = (func);\
if (_s < 0)\
{\
fprintf(stderr, "Error: %s returned %d\n", #func, _s);\
exit(0);\
}\
} while (0)

// Specify the VISA addresses for instruments
// GPIB, USB 2.0, or LAN are illustrated
// Use Primary VISA Configurator to obtain VISA addresses
// Configuration handled by Agilent Connection Expert
// You must determine your system's VISA Address for each instrument

#define DEFAULT_ADDRESS_3458 "GPIB0::22::INSTR"

void main()
{
ViSession viDefaultRM, Inst_dmm;
ViRsrc TxtAddress_dmm = DEFAULT_ADDRESS_3458;
float dummyRead;

// float* array = NULL;
// array = new float 1000000;

// float* scaled = NULL;
// scaled = new float 1000000;

float array512;
float scaled512;










//
// Initialize Instruments for communication and set them to reset condition
// Configure the interface for 20 second timeout
//
CHECK(viOpenDefaultRM(&viDefaultRM));
// Open path to DMM
CHECK(viOpen(viDefaultRM, TxtAddress_dmm, VI_NULL, 20000, &Inst_dmm));
CHECK(viSetAttribute(Inst_dmm, VI_ATTR_TMO_VALUE, 700000));


//max speed readings
viClear(Inst_dmm);
viPrintf(Inst_dmm,"reset\n");
viPrintf(Inst_dmm,"end on\n");
viPrintf(Inst_dmm,"preset dig\n");
viPrintf(Inst_dmm,"dcv 10\n");
viPrintf(Inst_dmm,"aper 1.4E-6\n");
viPrintf(Inst_dmm,"trig auto\n");
viPrintf(Inst_dmm,"mem off\n");



// set number of readings and trigger the instrument

viPrintf(Inst_dmm,"nrdgs 512\n");

viPrintf(Inst_dmm,"tarm sgl\n");



//Remove Readings and scale factor from the 3458A

viScanf(Inst_dmm, "%512hy",&array[0]);



viPrintf(Inst_dmm,"iscale?\n");
viScanf(Inst_dmm,"%f\n",&dummyRead);

cout << "Reading results" << endl;





//multiply by iscale

for (int i=0;i<512;i++)
{


scaled[i]=dummyRead*array[i];

cout << scaled[i] << endl;


}









/*
// Output data to file, can be analyzed with excel, matlab, etc...

ofstream DMMwaveform;
DMMwaveform.open("DMMwaveform.csv");

for (int g = 0; g<500; g++)
DMMwaveform << scaled[g] << endl;
DMMwaveform.close();



*/



CHECK(viClose(Inst_dmm));
CHECK(viClose(viDefaultRM));

// cout<< "DMMwaveform.csv created" <<endl;
cout<< "Press any key to exit" << endl;

char wait = getchar();

}
spacecowboy

Posts: 9
Registered: 06/13/11
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Aug 22, 2011 9:18 AM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
Hi, thanks for the code. However we are still having SINT format issues.
---------------------------------
A single DCV measurement is working. A digitizer with ASCII format is working, too. However 'SINT format' does not work when I use the sample code.
I think "viScanf(Inst_dmm, "%512hy",&array[0]);" is not working correctly. The return value does not match input voltage(8.6Vdc) . Even not close.
---------------------------------
This command is confusing, "viScanf(Inst_dmm, "%512hy",&array)
{
float array512;
float array2256;
float scaled512;
float retScale=0;
char cbuff 256 = {0};

//printf("Hello HP3458!\n");

ViSession defaultRM, Inst_dmm;
char buf 256 = {0};

/* Open session to GPIB device at address 22 /
viOpenDefaultRM(&defaultRM);
viOpen(defaultRM, "GPIB::22::INSTR",VI_NULL,VI_NULL,&Inst_dmm);
viSetAttribute(Inst_dmm, VI_ATTR_TMO_VALUE, 700); // Time out MilliSeconds

viClear(Inst_dmm);
/
Initialize device /
viPrintf(Inst_dmm, "RESET\n");

viPrintf(Inst_dmm, "END ON\n");
/
Send an *IDN? string to the device /
viPrintf(Inst_dmm, "ID?\n");

/
Read results /
viScanf(Inst_dmm, "%s", buf);

/
Print results /
printf("Instrument identification string:%s\n", buf);



/
Single Read This is working*/

/* NORM /
viPrintf(Inst_dmm, "PRESET NORM\n");

//TRIG
viPrintf(Inst_dmm, "TARM SGL\n");

viScanf(Inst_dmm, "%s", buf); // This is working

/
Print results /
printf("Ascii Foramt(Voltage):%s\n", buf);// This is working

/
End of Sigle Read /

/
Clear /
viClear(Inst_dmm);
/
Initialize device /
viPrintf(Inst_dmm, "RESET\n");


/
High Speed DCV ASCII /
viPrintf(Inst_dmm, "END ON\n");
/
FAST /

viPrintf(Inst_dmm, "PRESET FAST\n");

viPrintf(Inst_dmm, "APER 1.4E-6\n");

viPrintf(Inst_dmm, "OFORMAT ASCII\n");

viPrintf(Inst_dmm, "MEM FIFO\n");

viPrintf(Inst_dmm, "NRDGS 512,AUTO\n");


viPrintf(Inst_dmm, "TARM SGL\n");

for (int i=0 ;i<512;i++)
{
//GET DATA
viScanf(Inst_dmm, "%s",cbuff); // This is working

/
Print results /
printf("Ascii:%s\n",cbuff) ; // This is working
}

//GET Scale
viPrintf(Inst_dmm, "ISCALE?\n");
viScanf(Inst_dmm, "%f\n",&retScale);

/
Print results /
printf("Scale:%f\n", retScale);

/
retScale is 1. Because of ascii format*/

//////////////////////////////////////////////////////////////////




/* High Speed DCV /
viPrintf(Inst_dmm, "END ON\n"); //ASCII format sends the cr lf. SINT and DINT format does not send.
/
FAST /

viPrintf(Inst_dmm, "PRESET FAST\n");

viPrintf(Inst_dmm, "APER 1.4E-6\n");

viPrintf(Inst_dmm, "OFORMAT SINT\n");

viPrintf(Inst_dmm, "MEM FIFO\n");

viPrintf(Inst_dmm, "NRDGS 512,AUTO\n");


viPrintf(Inst_dmm, "TARM SGL\n");

//GET DATA
viScanf(Inst_dmm, "%512hy",&array[0]); // No error but value is wrong.

/
Print results /
for ( i=0 ;i<512;i++)
{
printf("Data:%f\n", array[i]);
}

//GET Scale
viPrintf(Inst_dmm, "ISCALE?\n");
viScanf(Inst_dmm, "%f\n",&retScale);

/
Print results /
printf("Scale:%f\n", retScale);

/
retScale is 0.000431. Is this resonable value? I guess so. FULL scale is about 32000. 32000 X 0.000431 = about 1.4V. /


/
Print results */

for ( i=0 ;i<512;i++)
{
printf("Data;%f\n",array[i]);

scaled[i]=retScale*array[i]; // No error but value is wrong.

printf("%f\n",scaled[i]);
}


/* End of High Speed DCV /



/
Clear /
viClear(Inst_dmm);
/
Initialize device /
viPrintf(Inst_dmm, "RESET\n");

viPrintf(Inst_dmm, "END ON\n"); // EOI mode to END ON for High-Speed Mode

/
PRESET DIG*/
viPrintf(Inst_dmm, "PRESET DIG\n");

/* 10V range /
viPrintf(Inst_dmm, "DCV 10\n");

viPrintf(Inst_dmm, "APER 1.4E-6\n");

viPrintf(Inst_dmm, "TRIG AUTO\n");

viPrintf(Inst_dmm, "MEM OFF\n");
//viPrintf(Inst_dmm, "MEM FIFO\n");


// 512 samples/Trigger
viPrintf(Inst_dmm, "NRDGS 512\n");

//TRIG
viPrintf(Inst_dmm, "TARM SGL\n");

//GET DATA
viScanf(Inst_dmm, "%512hy", &array[0]); // No error but return value is wrong. Does not make sense.

//GET Scale
viPrintf(Inst_dmm, "ISCALE?\n");
viScanf(Inst_dmm, "%f\n",&retScale);

/
Print results */
printf("Scale:%f\n", retScale);

for ( i=0 ;i<512;i++)
{
printf("Data;%f\n",array[i]);

scaled[i]=retScale*array[i];

printf("%f\n",scaled[i]); // No error but value is wrong.
}


/* Close session */
viClose(Inst_dmm);
viClose(defaultRM);

return 0;
}
lhornburg

Posts: 475
Registered: 01/15/10
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Aug 23, 2011 3:00 PM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
Your right, my mistake. I didn't test it before I sent it out. I know had it working at one point in time, but I tested this last night and was getting the same data errors you are seeing. Maybe this was an early version of a program I wrote. I probably won't have anything for you till tomorrow, but I know I can get a working program to you. Really sorry about that.
lhornburg

Posts: 475
Registered: 01/15/10
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Aug 25, 2011 1:51 PM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
I'm still having problems, which is very frustrating since I know I had this working before. My colleague who is more of a programming guru than myself is currently out. When he gets back in the office I should be able to figure out what's going on.

A little background on where the %hy comes from:

The 3458A uses a Big Endian format, while our PC’s use a Little Endian format. Since the 3458A is sending a short (2 byte), the bytes are swapped. Instrument sends 0xCDAB, but we need 0xABCD. The ‘y’ command will read back a byte array, while swapping the bytes by default. The ‘h’ modifier says that it is 2 bytes.
lhornburg

Posts: 475
Registered: 01/15/10
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Aug 25, 2011 3:16 PM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
Alright I figured it out. Dumb mistake I should have caught sooner. I had my array as a float instead of a short, try this one out should work:

// 3458A_100K_vstudio08.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <cstring>
#include <stdlib.h>
#include <stdio.h>
#include <visa.h>
#include <iostream>
#include <fstream>



using namespace std;


//
// This macro simplifies the reading of code and yet provides error checking
//
#define CHECK(func) \
do {\
ViStatus _s = (func);\
if (_s < 0)\
{\
fprintf(stderr, "Error: %s returned %d\n", #func, _s);\
exit(0);\
}\
} while (0)

// Specify the VISA addresses for instruments
// GPIB, USB 2.0, or LAN are illustrated
// Use Primary VISA Configurator to obtain VISA addresses
// Configuration handled by Agilent Connection Expert
// You must determine your system's VISA Address for each instrument

#define DEFAULT_ADDRESS_3458 "GPIB0::1::INSTR"

void main()
{
ViSession viDefaultRM, Inst_dmm;
ViRsrc TxtAddress_dmm = DEFAULT_ADDRESS_3458;
float dummyRead;



short rawdata512;
float scaled512;










//
// Initialize Instruments for communication and set them to reset condition
// Configure the interface for 20 second timeout
//
CHECK(viOpenDefaultRM(&viDefaultRM));
// Open path to DMM
CHECK(viOpen(viDefaultRM, TxtAddress_dmm, VI_NULL, 20000, &Inst_dmm));
CHECK(viSetAttribute(Inst_dmm, VI_ATTR_TMO_VALUE, 700000));


//max speed readings
viClear(Inst_dmm);
viPrintf(Inst_dmm,"reset\n");
viPrintf(Inst_dmm,"end always\n");
viPrintf(Inst_dmm,"preset dig\n");
viPrintf(Inst_dmm,"mformat SINT\n");
viPrintf(Inst_dmm,"oformat SINT\n");
viPrintf(Inst_dmm,"dcv 10\n");
viPrintf(Inst_dmm,"aper 1.4E-6\n");
viPrintf(Inst_dmm,"trig auto\n");
viPrintf(Inst_dmm,"mem off\n");



// set number of readings and trigger the instrument

viPrintf(Inst_dmm,"nrdgs 512\n");



viPrintf(Inst_dmm,"tarm sgl\n");



//Remove Readings and scale factor from the 3458A

viScanf(Inst_dmm, "%512hy\n",&rawdata[0]);

viPrintf(Inst_dmm,"iscale?\n");
viScanf(Inst_dmm,"%f\n",&dummyRead);



cout << "Reading results" << endl;





//multiply by iscale

for (int i=0;i<512;i++)
{


scaled[i]=dummyRead*rawdata[i];

cout << scaled[i] << endl;


}









/*
// Output data to file, can be analyzed with excel, matlab, etc...

ofstream DMMwaveform;
DMMwaveform.open("DMMwaveform.csv");

for (int g = 0; g<500; g++)
DMMwaveform << scaled[g] << endl;
DMMwaveform.close();



*/



CHECK(viClose(Inst_dmm));
CHECK(viClose(viDefaultRM));

// cout<< "DMMwaveform.csv created" <<endl;
cout<< "Press any key to exit" << endl;

char wait = getchar();

}
spacecowboy

Posts: 9
Registered: 06/13/11
Re: HP3458 Digitizing - Return Data in SINT Format
Posted: Aug 29, 2011 8:54 AM   in response to: spacecowboy in response to: spacecowboy
Click to report abuse...   Click to reply to this thread Reply
Hi!
Yes, this code is working! Thanks!
We are moving forward now with speed improvements...
Appreciate your time! :D

Point your RSS reader here for a feed of the latest messages in all forums