Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

need help with my code

Hi,
I'm trying to make a driver for an instrument with NAT9914 chipset and I'm having some problems. Sometimes, my Read lost the first character and my Write always get stuck waiting for BO after sending the first character.

Can somebody points me out what is wrong?

Here is my code:

/*
* Initialization
*/

// enable 9914 chip reset state
GPIBout(&(hDev->pIo->w.auxcr, 0x1c);

// disable all interrupts
GPIBout(&(hDev->pIo->w.imr0, 0);
GPIBout(&(hDev->pIo->w.imr1, 0);

// clear status registers by reading
GPIBin(&(hDev->pIo->r.isr0);
GPIBin(&(hDev->pIo->r.isr1);

// set GPIB address;
GPIBout(&(hDev->pIo->w.adr,(25 & 0x1f));

// speed is 4Mhz
GPIBout(&(hDev->pIo->w.accr), 0x0100 );

// Set T1 Delay to vstdl
GPIBout(&(hDev->pIo->w.auxcr), 0x97 );

// release 9914 chip reset state
GPIBout(&(hDev->pIo->w.auxcr), 0x00);

/*
* Read
*/

// Wait to be Active Listener
while( !((GPIBin(&(hDev->pIo->r.adsr)) & HR_LAPS)) );

// set and get eos
ibeos(hDev, (REOS << 😎 | '\n');
eos = bdGetEOS();

// reading loop
while(1)
{
// send RHDF
GPIBout(&(hDev->pIo->w.auxcr),AUX_RHDF);

// wait for BI or stop on end
while(!((isreg1 = GPIBin(&(hDev->pIo->r.isr0)) & HR_BI) && !(isreg1 & HR_END ) && NotTimedOut());

// No BI
if( (isreg1 & HR_END) || TimedOut() )
break;

// read byte
bin[j++] = GPIBin(&(hDev->pIo->r.dir);
}

// read last character
bin[j] = GPIBin(&(hDev->pIo->r.dir));

// make string readable
if((eosmodes & REOS) && (bin[j] == eos ))
{
bin[j] = '\0';
}
else
bin[j+1] = '\0';

/*
* Write
*/

// Wait to be Active Talker
while( !((GPIBin(&(hDev->pIo->r.adsr)) & HR_TPAS)) );

// writting loop
while(i{
// write byte to register
GPIBout(&(hDev->pIo->w.cdor), buf[i++]);

// wait for BO or ERR
while( !((GPIBin(&(hDev->pIo->r.isr0)) & HR_BO))
|| !((GPIBin(&(hDev->pIo->r.isr1)) & HR_ERR)) )
{
// if error, stop
if((GPIBin(&(hDev->pIo->r.isr1)) & HR_ERR))
break;
}
}

// if no error, send EOI with last byte
if(!((GPIBin(&(hDev->pIo->r.isr1)) & HR_ERR)))
{
GPIBout(&(hDev->pIo->w.auxcr ), 0x08 );
GPIBout(&(hDev->pIo->w.cdor), buf[i]);
}

Thanks,
Michael
0 Kudos
Message 1 of 2
(2,961 Views)
Try visiting the NI web site for Registry Level programming. It contains Manuals, Notes, Examples and KB entries that should help with your application:

ni.com>>Technical Support>>GPIB>>GPIB Register Level Programming
0 Kudos
Message 2 of 2
(2,961 Views)