I wrote this program (mentioned below) to get a voltage reading (amplitude) from a TDS 540 scope.
But i only get an erroneous result ie the reading returned to me is a ridiculous 9.3e+37 or something to that effect.
I tried changing the type to RMS instead of AMPLITUDE but the result was still the same.
Infact the result is still 9.3e+37 even if I don't give an input to the concerned channel.
This has been vexing me for quite some time and I'd appreciate any help on the matter.
Here's the program:
#include
#include
#include
#include
#include
#define ARRAYSIZE 1024 // Size of read buffer
#define BDINDEX 0 // Board Index
#define PRIMARY_ADDR_OF_SCOPE 3 // Primary address of device
#define NO_SECONDARY_ADDR 0 // Secondary address of device
#define TIMEOUT T1s // Timeout value = 1 seconds
#define EOTMODE 1 // Enable the END message
#define EOSMODE 0 // Disable the EOS mode
FILE *f1;
int Dev,i;
char ValueStr[ARRAYSIZE + 1];
char ErrorMnemonic[21][5] = {"EDVR", "ECIC", "ENOL", "EADR", "EARG",
"ESAC", "EABO", "ENEB", "EDMA", "",
"EOIP", "ECAP", "EFSO", "", "EBUS",
"ESTB", "ESRQ", "", "", "", "ETAB"};
void GPIBCleanup(int Dev, char* ErrorMsg);
int main()
{
Dev = ibdev(BDINDEX, PRIMARY_ADDR_OF_SCOPE, NO_SECONDARY_ADDR,
TIMEOUT, EOTMODE, EOSMODE);
if (ibsta & ERR)
{
printf("Unable to open device\nibsta = 0x%x iberr = %d\n",
ibsta, iberr);
return 1;
}
ibclr (Dev);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to clear device");
return 1;
}
ibwrt (Dev, "*IDN?\n", 6L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to set oscilloscope");
return 1;
}
ibtmo(Dev,13);
ibwrt(Dev,":MEASUREMENT:MEAS1:SOURCE CH1;TYPE AMPLITUDE", 43);
if(ibsta&ERR)
GPIBCleanup(Dev, "Could not trigger Osc");
ibtmo(Dev,13);
ibwrt(Dev, "MEASUrement:MEAS1:VALue?",24);
if(ibsta&ERR)
GPIBCleanup(Dev, "Could not trigger Osc");
ibtmo(Dev,13);
ibrd (Dev, ValueStr, ARRAYSIZE);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to read data from oscilloscope");
return 1;
}
ValueStr[ibcntl - 1] = '\0';
printf("Data read: %s\n", ValueStr);
ibonl(Dev, 0);
getch();
return 0;
}
void GPIBCleanup(int Dev, char* ErrorMsg)
{
printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n",
ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]);
if (Dev != -1)
{
printf("Cleanup: Taking device offline\n");
ibonl (Dev, 0);
}
}
Thanx.