Exemple #1
0
/**
  Close opened device connected to GPIB
  */
void GPIB::close()
{
    if (isOpen()) {
        ibsre(devId, 0);
        ibonl(devId, 0);
    }
}
Exemple #2
0
void GPIBCleanup(int ud, char* ErrorMsg)
{
	printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n",
		ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]);
	printf("Cleanup: Taking board offline\n");
	ibonl(ud, 0);
}
static int scpi_gpib_close(void *priv)
{
	struct scpi_gpib *gscpi = priv;

	ibonl(gscpi->descriptor, 0);

	return SR_OK;
}
Exemple #4
0
int gpibPort::portClose(void)
{
    int ret;

    ret = ibonl( handle, 0 );

    return ret;
}
Exemple #5
0
void d_GPIBCleanup(int ud, char* ErrorMsg)
{
	printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n",
		ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]);
	if (ud != -1)
	{
		printf("Cleanup: Taking device offline\n");
		ibonl(ud, 0);
	}
}
Exemple #6
0
void dvmerr(char *msg,char spr) {

    printf ("%s\n", msg);
    printf("Status byte = %x\n", spr);

    ibonl (dvm,0);               /* Disable the hardware and software.  */

    exit(1);                     /* Abort program.                      */

}
Exemple #7
0
int wxGPIB::CloseDevice()
{
    if(m_hd != -1) {
	   // goto local...
	   ibloc(m_hd);
	   // ...and switch device offline
	   ibonl(m_hd,0);
	   m_hd = -1;
	   m_board = -1;
    }
    return 0;
};
Exemple #8
0
bool CGPIBDevice::Close()
{
	if(m_nDev >= 0)
	{
		ibloc(m_nDev);
		ibonl(m_nDev, 0);
		m_nDev = -1;
	}

	Log(_T("GPIB device closed!"));

	return true;
}
Exemple #9
0
void gpiberr(char *msg) {

    printf ("%s\n", msg);
 
    printf ("ibsta = &H%x  <", ibsta);
    if (ibsta & ERR )  printf (" ERR");
    if (ibsta & TIMO)  printf (" TIMO");
    if (ibsta & END )  printf (" END");
    if (ibsta & SRQI)  printf (" SRQI");
    if (ibsta & RQS )  printf (" RQS");
    if (ibsta & SPOLL) printf (" SPOLL");
    if (ibsta & EVENT) printf (" EVENT");
    if (ibsta & CMPL)  printf (" CMPL");
    if (ibsta & LOK )  printf (" LOK");
    if (ibsta & REM )  printf (" REM");
    if (ibsta & CIC )  printf (" CIC");
    if (ibsta & ATN )  printf (" ATN");
    if (ibsta & TACS)  printf (" TACS");
    if (ibsta & LACS)  printf (" LACS");
    if (ibsta & DTAS)  printf (" DTAS");
    if (ibsta & DCAS)  printf (" DCAS");
    printf (" >\n");             
 
    printf ("iberr = %d", iberr);
    if (iberr == EDVR) printf (" EDVR <DOS Error>\n");
    if (iberr == ECIC) printf (" ECIC <Not CIC>\n");
    if (iberr == ENOL) printf (" ENOL <No Listener>\n");
    if (iberr == EADR) printf (" EADR <Address error>\n");
    if (iberr == EARG) printf (" EARG <Invalid argument>\n");
    if (iberr == ESAC) printf (" ESAC <Not Sys Ctrlr>\n");
    if (iberr == EABO) printf (" EABO <Op. aborted>\n");
    if (iberr == ENEB) printf (" ENEB <No GPIB board>\n");
    if (iberr == EOIP) printf (" EOIP <Async I/O in prg>\n");
    if (iberr == ECAP) printf (" ECAP <No capability>\n");
    if (iberr == EFSO) printf (" EFSO <File sys. error>\n");
    if (iberr == EBUS) printf (" EBUS <Command error>\n");
    if (iberr == ESTB) printf (" ESTB <Status byte lost>\n");
    if (iberr == ESRQ) printf (" ESRQ <SRQ stuck on>\n");
    if (iberr == ETAB) printf (" ETAB <Table Overflow>\n");
 
    printf ("ibcnt = %d\n", ibcnt);
    printf ("\n");

    ibonl (dvm,0);               /* Disable the hardware and software.  */

    exit(1);                     /* Abort program.                      */

}
Exemple #10
0
int _cdecl main(void) {
	// Ensure that the board being used is Controller-In-Charge

	SendIFC(GPIB0);
	if (ibsta & ERR)
	{
		GPIBCleanup(GPIB0, "Unable to open board");
		return 1;
	}

	// Assign the scope an identifier

	int Dev = ibdev(BDINDEX, PRIMARY_ADDRESS, SECONDARY_ADDRESS,
		TIMEOUT, EOTMODE, EOSMODE);
	if (ibsta & ERR)
	{
		d_GPIBCleanup(Dev, "Unable to open device");
		return 1;
	}

	ibclr(Dev);
	if (ibsta & ERR)
	{
		d_GPIBCleanup(Dev, "Unable to clear device");
		return 1;
	}

	// Preliminary querying

	printf("Querying scope with [*IDN?] ...\n");

	ibwrt(Dev, "*IDN?", 5L);
	if (ibsta & ERR)
	{
		d_GPIBCleanup(Dev, "Unable to write to device");
		return 1;
	}

	ibrd(Dev, ReadBuffer, 80);
	if (ibsta & ERR)
	{
		d_GPIBCleanup(Dev, "Unable to read data from device");
		return 1;
	}

	ReadBuffer[ibcntl] = '\0';
	printf("%s\n\n", ReadBuffer);

	// Prepare scope for waveform

	ibwrt(Dev, "DAT:SOU CH1", 11L);
	ibwrt(Dev, "DAT:ENC RIB;WID 1", 17L);
	ibwrt(Dev, "HOR:RECORDL 500", 15L);
	ibwrt(Dev, "DAT:STAR 1", 10L);
	ibwrt(Dev, "DAT:STOP 500", 12L);
	ibwrt(Dev, "HEAD OFF", 8L);

	if (ibsta & ERR)
	{
		d_GPIBCleanup(Dev, "Unable to initialize waveform parameters");
		return 1;
	}

	ibwrt(Dev, "ACQ:STATE RUN", 13L);

	if (ibsta & ERR)
	{
		d_GPIBCleanup(Dev, "Unable to acquire waveform");
		return 1;
	}

	ibwrt(Dev, "CURV?", 5L);
	ibrd(Dev, &c, 1);
	ibrd(Dev, &c, 1);
	rslt = atoi(&c);
	ibrd(Dev, ReadBuffer, rslt);
	ReadBuffer[rslt] = '\0';
	rslt = atoi(ReadBuffer);
	ibrd(Dev, wfm, rslt);
	ibrd(Dev, &c, 1);

	if (ibsta & ERR)
	{
		d_GPIBCleanup(Dev, "Unable to read waveform");
		return 1;
	}

	ibwrt(Dev, "WFMPRE:CH1:NR_PT?;YOFF?;YMULT?;XINCR?;PT_OFF?;XUNIT?;YUNIT?", 59L);

	memset(ReadBuffer, 0, 80);

	ibrd(Dev, ReadBuffer, 80);

	if (ibsta & ERR)
	{
		d_GPIBCleanup(Dev, "Unable to read waveform preamble");
		return 1;
	}

	sscanf_s(ReadBuffer, "%d;%e;%e;%e;%d;%[^;];%s", &nr_pt, &yoff, &ymult, &xincr, &pt_off, xunit, yunit);

	//outfile = fopen("WFM_DATA.dat", "wb");

	//_strdate(date);
	//_strtime(timenow);

	//fprintf(outfile, "%s,%s,\"%s\",\"%s\",\"%s\"\n", xunit, yunit, date, timenow, "CH1");

	//for (i = 0; i<nr_pt; i++)
	//{
	//	fprintf(outfile, "%14.12f,%14.12f\n", (float)(i - pt_off)*(float)(xincr),
	//		(float)(((float)wfm[i] - (float)yoff) * ymult));
	//}

	//fclose(outfile);
	// Offline the board and end
	ibonl(GPIB0, 0);
	return 0;
	//// Ensure that the board being used is Controller-In-Charge
	//SendIFC(GPIB0);
	//if (ibsta & ERR)
	//{
	//	GPIBCleanup(GPIB0, "Unable to open board");
	//	return 1;
	//}

	//// Create an array containing valid GPIB primary addresses to
	//// pass to FindLstn, terminated by decl-32's NOADDR
	//for (loop = 0; loop < 30; loop++) {
	//	Instruments[loop] = (Addr4882_t)(loop + 1);
	//}
	//Instruments[30] = NOADDR;

	//// Find all instruments on the bus, store addresses in Result
	//printf("Finding all instruments on the bus...\n\n");

	//FindLstn(GPIB0, Instruments, Result, 31);
	//if (ibsta & ERR)
	//{
	//	GPIBCleanup(GPIB0, "Unable to issue FindLstn Call");
	//	return 1;
	//}

	//// Assign the number of isntruments found and print such a number
	//Num_Instruments = ibcntl;

	//printf("Number of instruments found = %d\n\n", Num_Instruments);

	//Result[Num_Instruments] = NOADDR;

	////Print out each instrument's PAD and SAD

	//for (loop = 0; loop < Num_Instruments; loop++)
	//{
	//	PAD = GetPAD(Result[loop]);
	//	SAD = GetSAD(Result[loop]);
	//	Primary_Addr[loop] = PAD;

	//	if (SAD == NO_SAD)
	//	{
	//		Secondary_Addr[loop] = 0;
	//		printf("The instrument at Result[%d]: PAD = %d SAD = NONE\n\n",
	//			loop, PAD, SAD);
	//	}
	//	else
	//	{
	//		Secondary_Addr[loop] = SAD;
	//		printf("The instrument at Result[%d]: PAD = %d SAD = %d\n\n",
	//			loop, PAD, SAD);
	//	}

	//}

	//// Assign each device an identifier, then clear the device

	//for (loop = 0; loop < Num_Instruments; loop++)
	//{
	//	Dev[loop] = ibdev(BDINDEX, Primary_Addr[loop], Secondary_Addr[loop],
	//		TIMEOUT, EOTMODE, EOSMODE);
	//	if (ibsta & ERR)
	//	{
	//		d_GPIBCleanup(Dev[loop], "Unable to open device");
	//		return 1;
	//	}

	//	ibclr(Dev[loop]);
	//	if (ibsta & ERR)
	//	{
	//		d_GPIBCleanup(Dev[loop], "Unable to clear device");
	//		return 1;
	//	}
	//}

	//// Communicate with each device
	//// Currently, only querying with "*IDN?"

	//printf("Querying each device with [*IDN?] ...\n\n");

	//for (loop = 0; loop < Num_Instruments; loop++)
	//{
	//	ibwrt(Dev[loop], "*IDN?", 5L);
	//	if (ibsta & ERR)
	//	{
	//		d_GPIBCleanup(Dev[loop], "Unable to write to device");
	//		return 1;
	//	}

	//	ibrd(Dev[loop], ReadBuffer, ARRAYSIZE);
	//	if (ibsta & ERR)
	//	{
	//		d_GPIBCleanup(Dev[loop], "Unable to read data from device");
	//		return 1;
	//	}

	//	ReadBuffer[ibcntl] = '\0';
	//	printf("Returned string from Result[%d]: %s\n\n", loop, ReadBuffer);
	//}

	//scanf_s("%c", &c);

	//// Offline the board and end
	//ibonl(GPIB0, 0);
	//return 0;
}
Exemple #11
0
void GPIB_Close()
{
	int index;
	for (index=0; index<num_devices; index++) ibonl (device[index], 0); 
	for (index=0; index<num_controllers; index++) ibonl (enet_controller[index], 0);  
}
Exemple #12
0
void main() {

    printf("Read 10 measurements from the Fluke 45...\n");
    printf("\n");

/*
 *  Assign a unique identifier to the Fluke 45 and store in the variable
 *  DVM.  IBDEV opens an available device and assigns it to access GPIB0
 *  with a primary address of 1, a secondary address of 0, a timeout of
 *  10 seconds, the END message enabled, and the EOS mode disabled.
 *  If DVM is less than zero, call GPIBERR with an error message.
 */

    dvm = ibdev (0, 1, 0, T10s, 1, 0);
    if (dvm < 0) gpiberr("ibdev Error");

/*  Clear the internal or device functions of the Fluke 45.             */

    ibclr (dvm);
    if (ibsta & ERR) gpiberr("ibclr Error");

/*
 *  Reset the Fluke 45 by issuing the reset (*RST) command.  Instruct the 
 *  Fluke 45 to measure the volts alternating current (VAC) using auto-ranging
 *  (AUTO), to wait for a trigger from the GPIB interface board (TRIGGER 2),
 *  and to assert the IEEE-488 Service Request line, SRQ, when the measurement
 *  has been completed and the Fluke 45 is ready to send the result (*SRE 16). 
 */

    ibwrt (dvm,"*RST; VAC; AUTO; TRIGGER 2; *SRE 16", 35L);
    if (ibsta & ERR) gpiberr("ibwrt Error");

/*  Initialize the accumulator of the 10 measurements to zero.              */

    sum = 0.0;

/*
 *  Establish FOR loop to read the 10 measuements.  The variable m will
 *  serve as the counter of the FOR loop.
 */

    for (m=0; m < 10 ; m++) {

     /*  Trigger the Fluke 45.                                       */

         ibtrg (dvm);
         if (ibsta & ERR) gpiberr("ibtrg Error");

     /*
      *  Request the triggered measurement by sending the instruction
      *  "VAL1?". 
      */

         ibwrt (dvm,"VAL1?", 5L);
         if (ibsta & ERR) gpiberr("ibwrt Error");

     /*
      *  Wait for the Fluke 45 to request service (RQS) or wait for the 
      *  Fluke 45 to timeout(TIMO).  The default timeout period is 10 seconds. 
      *  RQS is detected by bit position 11 (hex 800).   TIMO is detected
      *  by bit position 14 (hex 4000).  These status bits are listed under
      *  the NI-488 function IBWAIT in the Software Reference Manual.  
      */

         ibwait (dvm,TIMO|RQS);
         if (ibsta & (ERR|TIMO)) gpiberr("ibwait Error");

     /*  Read the Fluke 45 serial poll status byte.                  */

         ibrsp (dvm, &spr);
         if (ibsta & ERR) gpiberr("ibrsp Error");

     /*
      *  If the returned status byte is hex 50, the Fluke 45 has valid data to
      *  send; otherwise, it has a fault condition to report.  If the status
      *  byte is not hex 50, call DVMERR with an error message.
      */

         if (spr != 0x50) dvmerr("Fluke 45 Error", spr);
     
     /*  Read the Fluke 45 measurement.                              */
         
         ibrd (dvm,rd,10L);
         if (ibsta & ERR) gpiberr("ibrd Error");

     /*
      *  Use the null character to mark the end of the data received
      *  in the array RD.  Print the measurement received from the
      *  Fluke 45.  
      */

         rd[ibcnt] = '\0';
         printf("Reading :  %s\n", rd);

     /*  Convert the variable RD to its numeric value and add to the
      *  accumulator.    
      */

         sum = sum + atof(rd);

    }  /*  Continue FOR loop until 10 measurements are read.   */

/*  Print the average of the 10 readings.                                  */

    printf("   The average of the 10 readings is : %f\n", sum/10);

    ibonl (dvm,0);         /* Disable the hardware and software            */

}
Exemple #13
0
bool CGPIBDevice::ScanDevice(CArray<IO_ADDRESS> &addresses)
{
	IO_ADDRESS addrnode;
	addresses.RemoveAll();
	int res;

	if (m_hGPIBDLL == NULL && !LoadGPIBDriver())
	{
		return false;
	}

	short primary_addrs[MAX_GPIB_PRIM_ADDR];
	short addr[MAX_ADDRESSES];

	for (int nAddr = 0; nAddr < MAX_ADDRESSES; nAddr++)
	{
		addr[nAddr] = (short)0xFFFF;
	}

	for (int nAddr = 0; nAddr < (MAX_GPIB_PRIM_ADDR - 2); nAddr++)
	{
		primary_addrs[nAddr] = (short)(nAddr + 1);
	}

	primary_addrs[MAX_GPIB_PRIM_ADDR - 2] = (short)0xFFFF;

	Log(_T("GPIB device scanning start!"));

	for (int nBus = 0; nBus < MAX_GPIB_CARD; nBus++)
	{
		ibonl(nBus, 1); if (ibsta & ERR) continue;
		ibconfig(nBus, IbcSC, 1); if (ibsta & ERR) continue;
		ibsic(nBus); if (ibsta & ERR) continue;
		ibconfig(nBus, IbcSRE, 1); if (ibsta & ERR) continue;
		ibconfig(nBus, IbcTIMING, 1); if (ibsta & ERR) continue;
		ibask(nBus, IbaPAD, &res); if (ibsta & ERR) continue;
		ibask(nBus, IbaSAD, &res); if (ibsta & ERR) continue;

		FindLstn(nBus, primary_addrs, addr, MAX_ADDRESSES - 1);

		if (ibsta & ERR) continue;

		for (int i = 0; i < (MAX_ADDRESSES - 1); i++)
		{
			if (addr[i] == -1) break;

			memset(&addrnode, 0, sizeof(IO_ADDRESS));

			addrnode.nBus = nBus;
			addrnode.eType = DRV_GPIB;
			addrnode.nPrimAddr = (addr[i] & 0xFF);
			addrnode.nSecAddr = ((addr[i] & 0xFF00) >> 8);

			addrnode.bPrimary = (i == 0 || addresses[i - 1].nPrimAddr != addrnode.nPrimAddr);

			if (addrnode.bPrimary && !Open(nBus, addrnode.nPrimAddr, addrnode.nSecAddr)) continue;

			if (!addrnode.bPrimary)
				strcpy_s(addrnode.sDevIdentity, addresses[i - 1].sDevIdentity);
			else
			{
				int nReadLen = MAX_DEV_IDN_LEN;
				CString strIDN;

				if (!Query("*IDN?", nReadLen, addrnode.sDevIdentity, 1000))
				{
					Log(CCommon::FormatString(_T("Failed to query identity of  device at GPIB::%d::%d::%d"), nBus, addrnode.nPrimAddr, addrnode.nSecAddr));

					Close();
					continue;
				}

				Close();
			}

			addresses.Add(addrnode);
		}
	}

	if (addresses.GetCount() == 0)
	{
		Log(_T("Found no GPIB device!"));
		return false;
	}

	return true;
}