示例#1
0
int gpibPort::portRead(char *buffer, int len)
{
    ibrd( handle, buffer , len );
    // printf("GPIB: read 0x%04x\n", ibsta);
    if ( ibsta & ERR )
    {
        buffer[0] = '\0';

        return -1;
    }
    else if ( ibsta & TIMO )
    {
        buffer[0] = '\0';

        return -1;
    }

    /* Assume that the returned string contains ASCII data. NULL terminate
     * the string using the value in ibcntl which is the number of bytes
     * read in.
     */

    buffer[ibcntl] = '\0';

    return ibcntl;
}
示例#2
0
int waveform (int color, int data_file)
{
	static char write_buffer[100],  read_buffer[10000]  ;
	int numToRead=10000;
	int written_bytes;
	
	////////////////////////////////////////////////
	memset(read_buffer, 0, 10000);
	ibsic(device);

	strcpy (write_buffer, "DATA:STARt 1");
	ibwrt (device, write_buffer, strlen(write_buffer));
	sprintf (write_buffer, "DATA:STOP 10000");
	ibwrt (device, write_buffer, strlen(write_buffer));
	strcpy (write_buffer, "ACQUIRE:MODE SAMPLE");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "ACQUIRE:STOPAFTER SEQUENCE");
	ibwrt (device, write_buffer, strlen(write_buffer));
	
	//read pump intensity, mask type and scan ref
	get_intensity();
//	Delay(0.5);
	
	strcpy (write_buffer, "ACQUIRE:STATE ON");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "*WAI");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "CURVe?");
	ibwrt (device, write_buffer, strlen(write_buffer));
	Delay(0.3); 

	ibrd (device, read_buffer, numToRead);

//Delay(1);	 
	ConvertArrayType (read_buffer, VAL_CHAR, data2fit, VAL_DOUBLE, 10000);
	written_bytes=WriteFile (data_file,read_buffer ,10000 );
	CloseFile (data_file);
	
	
	
	if (written_bytes!=10000)
	{
		printf("Error writing file!!\n");
	}

	plot_data(color);                   
	
	GetCtrlVal (ERG_panel, ERG_panel_fit_live, &j);
//	printf ("%d", j);
	if (j==1)
	{
	fit_data ();
	}
	
	return 1;
}
示例#3
0
int cleanbuffer (void)
{
	static char read_buffer[2500];
	int numToRead=2500;
	memset(read_buffer, 0, 2500);
	ibrd (device, read_buffer, numToRead);
	fprintf ( IO_output, "%s\n", read_buffer);

	return 1;
}
示例#4
0
int wxGPIB::Read(char* buf,size_t len)
{
    // if something is in the fifo, first read that
    if(m_fifo->items() > 0) {
	   return m_fifo->read(buf,len);
    }
    m_state = ibrd(m_hd,buf,len);
    m_error = ThreadIberr();
    m_count = ThreadIbcnt();
    return m_count;
};
示例#5
0
int wavex0 (void)
{
	static char write_buffer[100],  read_buffer[2500];
	int numToRead=2500;
	memset(read_buffer, 0, 2500);
	strcpy (write_buffer, "WFMPre:XZEro?");
	ibwrt (device, write_buffer, strlen(write_buffer));
	ibrd (device, read_buffer, numToRead);
	fprintf ( IO_output, "%s\n", read_buffer);

	return 1;
}
示例#6
0
/***************************************************************************
 *
 * Name:      ReadValue
 * Arguments: device - handle to the opened device
 *            buffer - buffer to read into
 *            bufsize - size of buffer (in bytes)
 * Returns:   FALSE if succesful, TRUE if error
 *
 * Reads a string from a GPIB device and checks for errors.  If no
 * errors it terminates the string.
 *
 ***************************************************************************/
int ReadValue(int device, char *buffer, size_t bufsize) {
   int rtrnval;
   /**/
   ibrd (device,buffer,bufsize);
   if (Ibcnt()==bufsize || Ibcnt()==0 || Ibsta()&ERR)
      rtrnval = TRUE;
   else
   {
      buffer[Ibcnt()-1] = '\0';    /* Terminate string */
      rtrnval = FALSE;
   }
   return (rtrnval);
}
示例#7
0
int waveform (int color, int data_file)
{
	static char write_buffer[100];
	int numToRead=10000;
	char * read_buffer;
	read_buffer = malloc (numToRead);
	
	
	memset(read_buffer, 0, 10000);
	ibsic(device);

	strcpy (write_buffer, "DATA:STARt 1");
	ibwrt (device, write_buffer, strlen(write_buffer));
	sprintf (write_buffer, "DATA:STOP 10000");
	ibwrt (device, write_buffer, strlen(write_buffer));
	strcpy (write_buffer, "ACQUIRE:MODE SAMPLE");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "ACQUIRE:STOPAFTER SEQUENCE");
	ibwrt (device, write_buffer, strlen(write_buffer));
	
	strcpy (write_buffer, "ACQUIRE:STATE ON");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "*WAI");				// wait for trigger to continue
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "CURVe?");
	ibwrt (device, write_buffer, strlen(write_buffer));
	Delay(0.3); 

	ibrd (device, read_buffer, numToRead);

	ConvertArrayType (read_buffer, VAL_CHAR, data2fit, VAL_DOUBLE, 10000);
	free (read_buffer)  ;
	
	
	
	
	plot_data(color);                   
	
	// check if live-fitting is enabled
	GetCtrlVal (Fit_pnl_handle, Fit_panel_fit_live, &fit_status);
	if (fit_status==1)
	{
		fit_data ();
	}
	
	return 1;
}
示例#8
0
static int scpi_gpib_read_data(void *priv, char *buf, int maxlen)
{
	struct scpi_gpib *gscpi = priv;

	ibrd(gscpi->descriptor, buf, maxlen);

	if (ibsta & ERR)
	{
		sr_err("Error while reading SCPI response: iberr = %d.", iberr);
		return SR_ERR;
	}

	gscpi->read_started = 1;

	return ibcnt;
}
示例#9
0
文件: gpib.cpp 项目: pinkavaj/seebrez
/**
  Read response from device.
  @param buf Pointer to char array to store text data.
  @param bufLen Lenght of buffer.
  @return Return number of bytes read, or -1 on error.
  */
int GPIB::readValue(char *buf, int bufLen)
{
    int len;

    ibrd(devId, buf, bufLen);
    len = Ibcnt();
    if (len == bufLen || len == 0 || Ibsta() & ERR)
       return -1;

    // strip end of string from whitespaces
    while (isspace(buf[--len])) {
        if (!len)
            return -1;
    }

    buf[++len] = 0;

    return len;
}
示例#10
0
文件: GPIB.c 项目: imr/Electric8
JNIEXPORT jint JNICALL Java_com_sun_electric_tool_simulation_test_GPIB_ibrd
  (JNIEnv *penv, jclass cls, jint ud, jbyteArray data, jint length, jintArray err)
{
  unsigned int ret;
   
  //variable preparation phase
  jbyte *dataP = (*penv)->GetByteArrayElements(penv, data, 0);
  jint *perr = (*penv)->GetIntArrayElements(penv, err, 0);


  //excution phase
  ret = ibrd(ud, dataP, length);
  *perr = iberr;

  //release  phase
  (*penv)->ReleaseByteArrayElements(penv, data, dataP, 0);
  (*penv)->ReleaseIntArrayElements(penv, err, perr, 0);

  return ret; 
}
示例#11
0
bool CGPIBDevice::Read(char *strRead, int &nLen, int nTimeout)
{
	if (strRead == NULL || nLen <= 0)
	{
		Log(_T("Invalid GPIB read input parameter"));
		return false;
	}

	memset(strRead, 0, nLen);

	ibrd(m_nDev, strRead, nLen - 1);

	if (ibsta & ERR)
	{
		Log(_T("GPIB read error: ") + GetGPIBError(iberr));
		return false;
	}

	Log(m_strLogHeader + _T("[PC<-TS] ") + CCommon::ToWideChar(strRead));
	return true;
}
示例#12
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;
}
示例#13
0
int headerfile (void)
{
	static char write_buffer[100],  read_buffer[2500];
	int numToRead=2500;
	
// Sequence number
	sprintf (msg,"Sequence= %d", i);
	WriteLine (data_file, msg, -1);
	
// mask number and name
	sprintf (msg, "Mask ID= %d\nMask name=%s", h, mask_filename);
	WriteLine (data_file, msg, -1);

// Pulse intensity	
	sprintf (msg,"Pulse intensity= %f", channel_data[0]);
	WriteLine (data_file, msg, -1);

// Fit type 
	if (fit_status==1){
		if (fit_type==0){
			sprintf (msg,"Fit type= linear (slope)");
		}
		if (fit_type==1){
			sprintf (msg,"Fit type= Gaussian (tau)");
		}
		if (fit_type==2){
			sprintf (msg,"Fit type= wave A-B (amplitude)");
		}
	}
	else {
		sprintf (msg,"Fit type= no fit");
	}
	WriteLine (data_file, msg, -1);

//Optimization value	
	sprintf (msg,"Optimization value=%f", value);	
	WriteLine (data_file, msg, -1);
	
//  wave x interval
	memset(read_buffer, 0, 2500);
	strcpy (write_buffer, "WFMPre:XINcr?");
	ibwrt (device, write_buffer, strlen(write_buffer));
	ibrd (device, read_buffer, numToRead);
	sprintf (msg, "X interval= %s", read_buffer);
	WriteLine (data_file, msg, -1);

//  Y scaling factor
	memset(read_buffer, 0, 2500);
	strcpy (write_buffer, "WFMPre:YMUlt?");
	ibwrt (device, write_buffer, strlen(write_buffer));
	ibrd (device, read_buffer, numToRead);
	sprintf (msg, "Y scaling factor= %s", read_buffer);
	WriteLine (data_file, msg, -1);
	
// First x data point
	memset(read_buffer, 0, 2500);
	strcpy (write_buffer, "WFMPre:XZEro?");
	ibwrt (device, write_buffer, strlen(write_buffer));
	ibrd (device, read_buffer, numToRead);
	sprintf (msg, "X0= %s", read_buffer);
	WriteLine (data_file, msg, -1);
	
	return 1;
}
示例#14
0
// This is only for internal usage
    int GpibDevice::Ibrd(char* buf,size_t len)
    {
	   return ibrd(m_hd,buf,len);
    };
示例#15
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            */

}
示例#16
0
// This is only for internal usage
int wxGPIB_x::Ibrd(char* buf,size_t len)
{
    return ibrd(m_hd,buf,len);
};
示例#17
0
// read a string from the counter
void gpibread( int identifier, char *response) {
 memset(response,0,strsize);
 ibrd(identifier, response, strsize-1);
 //printf("%s\n",response);
}