////////////////////////////////////////////////////////////////////////
// Start of Main
int main()
{
  int sg;
  char FreqCom[11], FreqC[7], Amplitude[10], AmpC[4], Modulation[4];
char rd[12];
 
  sg = ibdev (0, 0x15, 0x0, 0, 0, 0); //ADDR=21

  strcpy(FreqC, "127000");
  strcpy(FreqCom, "FR");
  strcat(FreqCom,FreqC);
  strcat(FreqCom,"KZ");
  ibwrt (sg, FreqCom, 10);

  strcpy(AmpC, "+10");
  strcpy(Amplitude, "AP");
  strcat(Amplitude,AmpC);
  strcat(Amplitude,"DM");
  ibwrt (sg, Amplitude, 7);

  strcpy(Modulation, "AM");
  strcat(Modulation,"S4");
  ibwrt (sg, Modulation, 4);

//ibwrt(sg,"IFR",3);
//ibrd(sg,rd,12);
//printf("%s\n",rd);
  return 0;
}
static int scpi_gpib_send(void *priv, const char *command)
{
	struct scpi_gpib *gscpi = priv;
	int len = strlen(command);

	ibwrt(gscpi->descriptor, command, len);

	if (ibsta & ERR)
	{
		sr_err("Error while sending SCPI command: '%s': iberr = %d.",
				command, iberr);
		return SR_ERR;
	}

	if (ibcnt < len)
	{
		sr_err("Failed to send all of SCPI command: '%s': "
				"len = %d, ibcnt = .", command, len, ibcnt);
		return SR_ERR;
	}

	sr_spew("Successfully sent SCPI command: '%s'.", command);

	return SR_OK;
}
Beispiel #3
0
int wxGPIB::Write(char* buf,size_t len)
{
    m_state = ibwrt(m_hd,buf,len);
    m_error = ThreadIberr();
    m_count = ThreadIbcnt();
    return m_count;
};
Beispiel #4
0
void SRS_onoff(void)
{
	static char write_buffer[100];
	ibsic(device1);

	if (SRS_flag==0)	 //SRS output set on 0.1V --> not triggering
	{
//			printf("SRS status: %d\n",SRS_flag);
		SRS_flag=1;
		strcpy (write_buffer, "OM 4,3");
		ibwrt (device1, write_buffer, strlen(write_buffer));

		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_LABEL_TEXT, "Enable");
		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_CMD_BUTTON_COLOR, VAL_GREEN);
		SetCtrlVal(ERG_panel, ERG_panel_LED_SRS, 0);
		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_DIMMED, 0);
	}

	else if (SRS_flag==1)   //SRS output set on TTL --> triggering!
	{

//			printf("SRS status: %d\n",SRS_flag);
		SRS_flag=0;
		strcpy (write_buffer, "OM 4,0");
		ibwrt (device1, write_buffer, strlen(write_buffer));

		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_LABEL_TEXT, "Disable");
		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_CMD_BUTTON_COLOR, VAL_RED);
		SetCtrlVal(ERG_panel, ERG_panel_LED_SRS, 1);
		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_DIMMED, 0);
	}

	else  if (SRS_flag==2)   //Scanning mode SRS output set on TTL --> triggering!
	{

//			printf("SRS status: %d\n",SRS_flag);
		SRS_flag=1;
		strcpy (write_buffer, "OM 4,0");
		ibwrt (device1, write_buffer, strlen(write_buffer));

		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_LABEL_TEXT, "Scanning");
		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_DIMMED, 1);
		SetCtrlAttribute (ERG_panel, ERG_panel_SRS, ATTR_CMD_BUTTON_COLOR, VAL_BLUE);
		SetCtrlVal(ERG_panel, ERG_panel_LED_SRS, 1);
	}
	return;
}
Beispiel #5
0
void setup_oscillo(void)
{
	static char write_buffer[100];
	//printf("test\n");
	// find hardware
	reset_connection_oscillo();
	// configure oscilloscope 
	strcpy (write_buffer, "DATA:ENCdg RIBinary");
	ibwrt (device, write_buffer, strlen(write_buffer));

// strcpy (write_buffer, "TRIGger:MAIn:MODe NORMal");
// ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "DATA:WIDTH 1");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "DATA:SOURCE CH1");
	ibwrt (device, write_buffer, strlen(write_buffer));
	SetCtrlVal(ERG_panel, ERG_panel_LED_chanel1, 1);
	SetCtrlVal(ERG_panel, ERG_panel_LED_chanel2, 0);
	
// to check the oscillo settings	
/*	strcpy (write_buffer, "DATA?");
	ibwrt (device, write_buffer, strlen(write_buffer));
	ibrd (device, read_buffer, numToRead);
	printf("%s", read_buffer);
*/

// to setup the oscillo scales from the start
	/*
	strcpy (write_buffer, "CH2:SCALE 2E-3");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "CH2:POSITION -2");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "HORIZONTAL:SECdiv 10E-3");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "HORIZONTAL:POSITION 40E-3");
	ibwrt (device, write_buffer, strlen(write_buffer));
	*/
	return;

}
Beispiel #6
0
/**
  Send command (text) to device.
  @param buf Buffer with text to send.
  @param len Number of bytes to send.
  @return On success returns 0, on error -1.
  */
int GPIB::sendCmd(const char *buf, size_t len)
{
    ibwrt(devId, buf, len);
    if (Ibsta() & ERR ||
            Ibcnt() != len)
       return -1;

    return 0;
}
Beispiel #7
0
void setup_SRS(void)
{
	static char write_buffer[100];
	reset_connection_SRS();
	strcpy (write_buffer, "OM 4,3");
	ibwrt (device1, write_buffer, strlen(write_buffer));
	SRS_flag=0;
	SRS_onoff();
}
Beispiel #8
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;
}
Beispiel #9
0
void setup_oscillo(void)
{
	static char write_buffer[100];
	// find hardware
	reset_connection_oscillo();
	// configure oscilloscope 
	strcpy (write_buffer, "DATA:ENCdg RIBinary");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "DATA:WIDTH 1");
	ibwrt (device, write_buffer, strlen(write_buffer));

	strcpy (write_buffer, "DATA:SOURCE CH1");
	ibwrt (device, write_buffer, strlen(write_buffer));
	SetCtrlVal(Main_pnl_handle, ERG_panel_LED_chanel1, 1);
	SetCtrlVal(Main_pnl_handle, ERG_panel_LED_chanel2, 0);
	return;

}
Beispiel #10
0
/***************************************************************************
 *
 * Name:      WriteCommand
 * Arguments: device - handle to the opened device
 *            cmd - command string to be written
 * Returns:   FALSE if succesful, else TRUE
 *
 * Send a command to a GPIB device and checks for error.
 *
 ***************************************************************************/
int WriteCommand (int device, const char *cmd) {
   size_t cmdlength;
   int    ReturnVal;
   /**/
   cmdlength = strlen (cmd);
   ibwrt  (device, cmd, cmdlength);
   if (Ibcnt()!=cmdlength || Ibsta()&ERR)
      ReturnVal = TRUE;
   else
      ReturnVal = FALSE;
   return (ReturnVal);
}
Beispiel #11
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;
}
Beispiel #12
0
int CVICALLBACK chanel2 (int panel, int control, int event,
						 void *callbackData, int eventData1, int eventData2)
{
	static char write_buffer[100];
	switch (event)
	{
		case EVENT_COMMIT:
			strcpy (write_buffer, "DATA:SOURCE CH2");
			ibwrt (device, write_buffer, strlen(write_buffer));
			SetCtrlVal(ERG_panel, ERG_panel_LED_chanel2, 1);
			SetCtrlVal(ERG_panel, ERG_panel_LED_chanel1, 0);
			break;
	}
	return 0;
}
Beispiel #13
0
int gpibPort::portWrite(char *buffer, int len)
{
    int ret;

    // printf("GPIB: write\n");
    ret = ibwrt( handle, buffer, len );

    if ( ibsta & ERR )
    {
        GPIBCleanup( (char*)"Unable to write to device" );
        return -1;
    }

    return ret;
}
Beispiel #14
0
int ibfind( const char *dev )
{
	int index;
	int retval;
	int ud;
	ibConf_t *conf;
	int status;

	retval = ibParseConfigFile();
	if(retval < 0)
	{
		setIberr( EDVR );
		setIbsta( ERR );
		return -1;
	}

	if( ( index = ibFindDevIndex( dev ) ) < 0 )
	{ /* find desired entry */
		setIberr( EDVR );
		setIbsta( ERR );
		return -1;
	}

	conf = &ibFindConfigs[ index ];

	ud = my_ibdev( *conf );
	if(ud < 0)
	{
		fprintf(stderr, "libgpib: ibfind failed to get descriptor\n");
		return -1;
	}
	conf = general_enter_library( ud, 1, 0 );

	if(conf->flags & CN_SDCL)
	{
		status = ibclr(ud);
		if( status & ERR ) return -1;
	}

	if(strcmp(conf->init_string, ""))
	{
		status = ibwrt(ud, conf->init_string, strlen(conf->init_string));
		if( status & ERR )
			return -1;
	}

	return ud;
}
Beispiel #15
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;
}
Beispiel #16
0
int CVICALLBACK secbwtrigg (int panel, int control, int event,
							void *callbackData, int eventData1, int eventData2)
{
	static char write_buffer[100];
	int  Nsec;
	switch (event)
	{
		case EVENT_COMMIT:
			reset_connection_SRS();
			//get and set the waiting time bewteen to trigger pulses sent to the sutter, in sec.
			GetCtrlVal(Main_pnl_handle, ERG_panel_nsec, &Nsec);
			sprintf(write_buffer,"DT 5,1,%d", Nsec);
			ibwrt (device1, write_buffer, strlen(write_buffer));
			break;
	}
	return 0;
}
Beispiel #17
0
int CVICALLBACK pulsespertrigg (int panel, int control, int event,
								void *callbackData, int eventData1, int eventData2)
{
	static char write_buffer[100];
	int  Npulses;
	switch (event)
	{
		case EVENT_COMMIT:
			reset_connection_SRS();
			//get and set the opening time of the sutter in ms,
			//which corresponds to the number of pulses at 1kHz.
			GetCtrlVal(Main_pnl_handle, ERG_panel_npulses, &Npulses);
			sprintf(write_buffer,"DT 3,2,%d.03E-3", Npulses);
			ibwrt (device1, write_buffer, strlen(write_buffer));
			break;
	}
	return 0;
}
Beispiel #18
0
/*
   There is no equivalent Java primitive for unsigned variable such as unsigned int.
   Care must be taken if signed Java variable and unsigned C variable are used simultaneously.
*/
JNIEXPORT jint JNICALL Java_com_sun_electric_tool_simulation_test_GPIB_ibwrt
  (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 = ibwrt(ud, dataP, length);
  *perr = iberr;

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

  return ret; 
}
Beispiel #19
0
bool CGPIBDevice::Write(const char *strWrite)
{
	if (strWrite == NULL)
	{
		Log(_T("Invalid GPIB write input parameter"));
		return false;
	}

	if (strlen(strWrite) == 0) return true;

	ibwrt(m_nDev, (char*)strWrite, strlen(strWrite));

	Log(m_strLogHeader + _T(" [PC->TS] ") + CCommon::ToWideChar(strWrite));

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

	return true;
}
Beispiel #20
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;
}
Beispiel #21
0
// This is only for internal usage
    int GpibDevice::Ibwrt(char* buf,size_t len)
    {
	   return ibwrt(m_hd,buf,len);
    };
Beispiel #22
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            */

}
Beispiel #23
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;
}
int main( int argc, char *argv[] )
{
	int board = 0;
	int eos_mode = 0;
	char *file_path;
	int status;
	int retval;
	FILE *filep;
	struct stat file_stats;
	uint8_t *buffer;
	unsigned long buffer_length;

	if( argc < 2 )
	{
		fprintf( stderr, "Must provide file path as arguement\n" );
		return -1;
	}

	file_path = argv[ 1 ];
	filep = fopen( file_path, "r" );
	if( filep == NULL )
	{
		perror( "fopen()");
		return -1;
	}

	retval = fstat( fileno( filep ), &file_stats );
	if( retval < 0 )
	{
		perror( "fstat()");
		return -1;
	}
	buffer_length = file_stats.st_size;

	buffer = malloc( buffer_length );
	if( buffer == NULL )
	{
		perror( "malloc()");
		return -1;
	}

	if( fread( buffer, 1, buffer_length, filep ) != buffer_length )
	{
		perror( "fread()" );
		return -1;
	}

	fclose( filep );

	status = ibeos( board, eos_mode );
	if( status & ERR )
	{
		fprintf( stderr, "ibeos() failed\n" );
		fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) );
		return -1;
	}

	status = ibtmo( board, TNONE );
	if( status & ERR )
	{
		fprintf( stderr, "ibtmo() failed\n" );
		fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) );
		return -1;
	}

	status = ibconfig( board, IbcTIMING, T1_DELAY_350ns );
	if( status & ERR )
	{
		fprintf( stderr, "ibconfig() failed\n" );
		fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) );
		return -1;
	}

	status = ibwait( board, TACS );
	if( ( status & TACS ) == 0 )
	{
		fprintf( stderr, "ibwait() for TACS failed\n" );
		fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) );
		return -1;
	}

	status = ibwrt( board, buffer, buffer_length );
	if( status & ERR )
	{
		fprintf( stderr, "ibwrt() failed\n" );
		fprintf( stderr, "%s\n", gpib_error_string( ThreadIberr() ) );
		return -1;
	}

	free( buffer );

	return 0;
}
Beispiel #25
0
// write a string to the counter
void gpibwrite(int identifier, char command[strsize]) {
 char response[strsize];
 ibwrt(identifier,command,strlen(command));
 gpibread(identifier, response);
}
Beispiel #26
0
// This is only for internal usage
int wxGPIB_x::Ibwrt(char* buf,size_t len)
{
    return ibwrt(m_hd,buf,len);
};