09-21-2011 07:35 AM
Hello:
I have a problem using the 7260 DSP Lock-in amplifier over the GPBI interface. I have created a program on C and is not working properly. I will tell you what is happening.
I need to obtain the amplitude peak's of the harmonic, so, what I am doing is, after initializate the device, to send the command write with the instruction and then check the Status byte so see if this command is ready (ReadStatusByte, for example) and then I do a read operation.
What I obtain is something weird. The data I have obtained is not correspoding with the data I am suppose to obtain (the device says the data is ready or the instruction has finished but the reality is another), or, the instructions don't update properly. If you want, I can copy the piece of code here, so maybe I am doing something wrong.
Here is my code sample
/*****************************************************************************
Simple programe to take the harmonics
*****************************************************************************/
#include <windows.h>
#include "ni488.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#define DATAREADY 0x80
#define COMPLETE 0x01
void GpibError(char *msg); /* Error function declaration */
int Device = 0; /* Device unit descriptor */
int BoardIndex = 0; /* Interface Index (GPIB0=0,GPIB1=1,etc.) */
int main() {
int PrimaryAddress = 12; /* Primary address of the device */
int SecondaryAddress = 0; /* Secondary address of the device */
char Buffer[101]; /* Read buffer */
short ResByte=0;
unsigned int time_sleep=350;
/*****************************************************************************
* Initialization - Done only once at the beginning of your application.
*****************************************************************************/
Device = ibdev( /* Create a unit descriptor handle */
BoardIndex, /* Board Index (GPIB0 = 0, GPIB1 = 1, ...) */
PrimaryAddress, /* Device primary address */
SecondaryAddress, /* Device secondary address */
T10s, /* Timeout setting (T10s = 10 seconds) */
1, /* Assert EOI line at end of write */
0); /* EOS termination mode */
if (ibsta & ERR) { /* Check for GPIB Error */
GpibError("ibdev Error");
}
ibclr(Device); /* Clear the device */
if (ibsta & ERR) {
GpibError("ibclr Error");
}
/*****************************************************************************
* Main Application Body - Write the majority of your GPIB code here.
*****************************************************************************/
ibwrt(Device, "*IDN?", 5); /* Send the identification query command */
if (ibsta & ERR) {
GpibError("ibwrt Error");
}
ibrd(Device, Buffer, 100); /* Read up to 100 bytes from the device */
if (ibsta & ERR) {
GpibError("ibrd Error");
}
Buffer[ibcntl] = '\0'; /* Null terminate the ASCII string */
printf("%s\n", Buffer); /* Print the device identification */
/*****************************************************************************
* Harmonic code.
*****************************************************************************/
printf("Requesting the first harmonic in the device %d\n ",Device);
ibwrt(Device,"REFN 1",6); // I set the device to measure the first harmonic
ResByte=0;
while ((ResByte && COMPLETE) == 0){
ReadStatusByte(0,12,&ResByte);
}
ibwrt(Device,"AQN",3);
ResByte=0;
while ((ResByte && COMPLETE) == 0){
ReadStatusByte(0,12,&ResByte);
}
ibwrt(Device,"MAG.",4);
ResByte=0;
while ((ResByte && DATAREADY) == 0){
ReadStatusByte(0,12,&ResByte);
}
ibrd(Device, Buffer,100); // I read the data I've applied
Buffer[ibcntl] = '\0';
printf("The first harmonic amplitude is %s\n", Buffer);
/*****************************************************************************
* Uninitialization - Done only once at the end of your application.
*****************************************************************************/
ibonl(Device, 0); /* Take the device offline */
if (ibsta & ERR) {
GpibError("ibonl Error");
}
exit(0);
}
I hope you can help me. Thank you so much