Beispiel #1
0
void reset_connection_oscillo(void)
{
	address=1; //GPIB address of oscilloscope
	device = ibdev (0, address, NO_SAD, T30s, 1, 0);
	ibsic(device);
	
}
Beispiel #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;
}
Beispiel #3
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 #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 reset_connection_SRS(void)
{
	address=2; //GPIB address of SRS DG 535
	device1 = ibdev (0, address, NO_SAD, T10s, 1, 00001000);
	ibsic(device1);
}
Beispiel #6
0
static int configure_board( int fileno, const parsed_options_t *options )
{
	board_type_ioctl_t boardtype;
	select_pci_ioctl_t pci_selection;
	pad_ioctl_t pad_cmd;
	sad_ioctl_t sad_cmd;
	online_ioctl_t online_cmd;
	int retval;

	online_cmd.online = 0;
	online_cmd.init_data_ptr = 0;
	online_cmd.init_data_length = 0;
	retval = ioctl( fileno, IBONL, &online_cmd );
	if( retval < 0 )
	{
		fprintf( stderr, "failed to bring board offline\n" );
		return retval;
	}
	if( options->offline != 0 )
		return 0;
	strncpy( boardtype.name, options->board_type, sizeof( boardtype.name ) );
	retval = ioctl( fileno, CFCBOARDTYPE, &boardtype );
	if( retval < 0 )
	{
		fprintf(stderr, "failed to configure boardtype: %s\n", boardtype.name);
		return retval;
	}
	retval = ioctl( fileno, CFCBASE, &options->iobase );
	if( retval < 0 )
	{
		fprintf(stderr, "failed to configure base address\n");
		return retval;
	}
	retval = ioctl( fileno, CFCIRQ, &options->irq );
	if( retval < 0 )
	{
		fprintf(stderr, "failed to configure irq\n");
		return retval;
	}
	retval = ioctl( fileno, CFCDMA, &options->dma );
	if( retval < 0 )
	{
		fprintf(stderr, "failed to configure dma channel\n");
		return retval;
	}
	pad_cmd.handle = 0;
	pad_cmd.pad = options->pad;
	retval = ioctl( fileno, IBPAD, &pad_cmd );
	if( retval < 0 )
	{
		fprintf(stderr, "failed to configure pad\n");
		return retval;
	}
	sad_cmd.handle = 0;
	sad_cmd.sad = options->sad;
	retval = ioctl( fileno, IBSAD, &sad_cmd );
	if( retval < 0 )
	{
		fprintf(stderr, "failed to configure sad\n");
		return retval;
	}
	pci_selection.pci_bus = options->pci_bus;
	pci_selection.pci_slot = options->pci_slot;
	retval = ioctl( fileno, IBSELECT_PCI, &pci_selection );
	if( retval < 0 )
	{
		fprintf(stderr, "failed to configure pci bus\n");
		return retval;
	}
	online_cmd.online = 1;
	assert(sizeof(options->init_data) <= sizeof(online_cmd.init_data_ptr));
	online_cmd.init_data_ptr = (uintptr_t)options->init_data;
	online_cmd.init_data_length = options->init_data_length;
	retval = ioctl( fileno, IBONL, &online_cmd );
	if( retval < 0 )
	{
		fprintf( stderr, "failed to bring board online\n" );
		return retval;
	}

	retval = ibrsc( options->minor, options->is_system_controller );
	if( retval & ERR )
	{
		fprintf( stderr, "failed to request/release system control\n" );
		return -1;
	}
	if( options->is_system_controller )
	{
		if( options->assert_ifc )
		{
			retval = ibsic( options->minor );
			if( retval & ERR )
			{
				fprintf( stderr, "failed to assert interface clear\n" );
				return -1;
			}
		}
		if( options->assert_remote_enable )
		{
			retval = ibsre( options->minor, 1 );
			if( retval & ERR )
			{
				fprintf( stderr, "failed to assert remote enable\n" );
				return -1;
			}
		}
	}

	return 0;
}
Beispiel #7
0
int wxGPIB_x::Ioctl(int cmd,void* args)
{
    switch(cmd) {
    case CTB_RESET:
	   if(m_hd >= 0) {
		  if(m_asyncio) {
			 ibstop(m_hd);
			 m_asyncio = 0;
		  }
		  ibclr(m_hd);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_GETRSP: {
	   char spr = 0;
	   if(m_hd >= 0) {
		  ibrsp(m_hd,&spr);
		  *(int*)args = (int)spr;
		  return 0;
	   }
	   return 1; }
    case CTB_GPIB_GETSTA:
	   *(int*)args = m_state;
	   return 0;
    case CTB_GPIB_GETERR:
	   *(int*)args = m_error;
	   return 0;
    case CTB_GPIB_GETLINES: {
	   short state = 0;
	   if(m_hd >= 0) {
		  iblines(m_board,&state);
		  *(int*)args = (int)state;
		  return 0;
	   }
	   return -1; }
    case CTB_GPIB_SETTIMEOUT: {
	   if(m_hd >= 0) {
		  wxGPIB_Timeout timeout;
		  unsigned long to = *(unsigned long*)args;
		  // convert the timeout in ms (given by args) into the
		  // traditional NI-488.2 timeout period 
		  if(to > 1000000) timeout = wxGPIB_TO_1000s;
		  else if(to > 300000) timeout = wxGPIB_TO_300s;
		  else if(to > 100000) timeout = wxGPIB_TO_100s;
		  else if(to > 30000) timeout = wxGPIB_TO_30s;
		  else if(to > 10000) timeout = wxGPIB_TO_10s;
		  else if(to > 3000) timeout = wxGPIB_TO_3s;
		  else if(to > 1000) timeout = wxGPIB_TO_1s;
		  else if(to > 300) timeout = wxGPIB_TO_300ms;
		  else if(to > 100) timeout = wxGPIB_TO_100ms;
		  else if(to > 30) timeout = wxGPIB_TO_30ms;
		  else if(to > 10) timeout = wxGPIB_TO_10ms;
		  else if(to > 3) timeout = wxGPIB_TO_3ms;
		  else if(to > 1) timeout = wxGPIB_TO_1ms;
		  else timeout = wxGPIB_TO_NONE;
		  ibtmo(m_hd,timeout);
		  return 0; 
	   }
	   return -1; }
    case CTB_GPIB_GTL:
	   // Forces the specified device to go to local program mode
	   if(m_hd >= 0) {
		  ibloc(m_hd);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_REN:
	   // This routine can only be used if the specified GPIB 
	   // Interface Board is the System Controller.
	   // Remember that even though the REN line is asserted, 
	   // the device(s) will not be put into remote state until is
	   // addressed to listen by the Active Controller
	   if(m_hd) {
		  char adr = (char)m_dcs.m_address1;
		  ibsre(m_board,1);
		  ibcmd(m_board,&adr,1);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_RESET_BUS:
	   ibsic(m_board);
	   return 0;
    }
    // error or unknown command
    return -1;
};
Beispiel #8
0
int wxGPIB::Ioctl(int cmd,void* args)
{
    switch(cmd) {
    case CTB_RESET:
	   if(m_hd >= 0) {
		  ibclr(m_hd);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_GETRSP: {
	   char spr = 0;
	   if(m_hd >= 0) {
		  ibrsp(m_hd,&spr);
		  *(int*)args = (int)spr;
		  return 0;
	   }
	   return 1; }
    case CTB_GPIB_GETSTA:
	   *(int*)args = m_state;
	   return 0;
    case CTB_GPIB_GETERR:
	   *(int*)args = m_error;
	   return 0;
    case CTB_GPIB_GETLINES: {
	   short state = 0;
	   if(m_hd >= 0) {
		  iblines(m_board,&state);
		  *(int*)args = (int)state;
		  return 0;
	   }
	   return -1; }
    case CTB_GPIB_SETTIMEOUT: {
	   if(m_hd >= 0) {
		  wxGPIB_Timeout timeout;
		  unsigned long to = *(unsigned long*)args;
		  // convert the timeout in ms (given by args) into the
		  // traditional NI-488.2 timeout period 
		  if(to > 1000000) timeout = wxGPIB_TO_1000s;
		  else if(to >= 300000) timeout = wxGPIB_TO_300s;
		  else if(to >= 100000) timeout = wxGPIB_TO_100s;
		  else if(to >= 30000) timeout = wxGPIB_TO_30s;
		  else if(to >= 10000) timeout = wxGPIB_TO_10s;
		  else if(to >= 3000) timeout = wxGPIB_TO_3s;
		  else if(to >= 1000) timeout = wxGPIB_TO_1s;
		  else if(to >= 300) timeout = wxGPIB_TO_300ms;
		  else if(to >= 100) timeout = wxGPIB_TO_100ms;
		  else if(to >= 30) timeout = wxGPIB_TO_30ms;
		  else if(to >= 10) timeout = wxGPIB_TO_10ms;
		  else if(to >= 3) timeout = wxGPIB_TO_3ms;
		  else if(to >= 1) timeout = wxGPIB_TO_1ms;
		  else timeout = wxGPIB_TO_NONE;
		  ibtmo(m_hd,timeout);
		  return 0; 
	   }
	   return -1; }
    case CTB_GPIB_GTL:
	   // Forces the specified device to go to local program mode
	   if(m_hd >= 0) {
		  ibloc(m_hd);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_REN:
	   // This routine can only be used if the specified GPIB 
	   // Interface Board is the System Controller.
	   // Remember that even though the REN line is asserted, 
	   // the device(s) will not be put into remote state until is
	   // addressed to listen by the Active Controller
	   if(m_hd) {
		  char adr = (char)m_dcs.m_address1;
		  ibsre(m_board,1);
		  ibcmd(m_board,&adr,1);
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_RESET_BUS:
	   ibsic(m_board);
	   return 0;
    case CTB_GPIB_GET_EOS_CHAR:
	   if( m_hd ) {
		  *(int*)args = (int)m_dcs.m_eosChar;
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_SET_EOS_CHAR:
#ifdef __GNUG__
	   // FIXME!
	   // Doesn't work with linux-gpib-3.2.08. All EOS beside 0x00
	   // are blocking during sending data to the device. (Look at 
	   // function my_ibwrt in linux-gpib-3.2.08/lib/ibWrt.c
	   if( m_hd ) {
		  m_dcs.m_eosChar = (char)*(int*)args;
		  ibeos(m_hd,(m_dcs.m_eosMode << 8) | m_dcs.m_eosChar);
		  return 0;
	   }
#endif
	   return -1;
    case CTB_GPIB_GET_EOS_MODE:
	   if( m_hd ) {
		  *(int*)args = (int)m_dcs.m_eosMode;
		  return 0;
	   }
	   return -1;
    case CTB_GPIB_SET_EOS_MODE:
	   if( m_hd ) {
		  m_dcs.m_eosMode = (char)*(int*)args;
		  ibeos(m_hd,(m_dcs.m_eosMode << 8) | m_dcs.m_eosChar);
		  return 0;
	   }
	   return -1;
    }
    // error or unknown command
    return -1;
};
Beispiel #9
0
void acquire_scans (void)
{
	int color;
	int Nleft=0;
	char file [ FILENAME_MAX ];

	SetCtrlAttribute (Main_pnl_handle, ERG_panel_acquire, ATTR_DIMMED, 1);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_abortscan, ATTR_DIMMED, 1);
	if (experiment==1){
		GetCtrlVal (Sequence_pnl_handle, Seq_panel_seq_number, &seq_num);
		Nscans=	seq_num*m;
	}
	else {
		GetCtrlVal (Main_pnl_handle, ERG_panel_nscans, &Nscans);
	}

	DirSelectPopup ("d:\\data\\test", "Select Directory", 1, 1, pathname);

	i=0;
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_pause, ATTR_DIMMED, 0);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_abortscan, ATTR_DIMMED, 0);
	
// start trigger 
	SRS_flag=2;
	SRS_onoff();
	DeleteGraphPlot (Main_pnl_handle, ERG_panel_mask_display, -1, VAL_IMMEDIATE_DRAW);
	
	if (experiment==1){			 // mode sequence
		for (i=0;i<seq_num;i++) {
			for (h=0;h<m;h++){
				SetCtrlIndex (Sequence_pnl_handle, Seq_panel_mask_list, h);
				for (k=0;k<Npixel;k++){
					drive_level[k]=mask[h].voltages[k];
				}				
				display_masks();
				
				ProcessSystemEvents();
				GetLabelFromIndex (Sequence_pnl_handle, Seq_panel_mask_list, h, &mask_filename);
				strcpy(filename, pathname);
				
				//prepare file to write
				sprintf(file, "\\sequence%d_%s.txt", i, mask_filename);
				strcat(filename, file);
				data_file = OpenFile (filename, VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_ASCII);
				
				//enable oscillo then wait for trigger and get ERG trace
				color=floor(256/Nscans)*(i*m+h);
				waveform(color, data_file);	
				get_intensity();
				
				//write header file
				headerfile();
				
				//write ERG trace 
				ArrayToFile (filename, data2fit, VAL_DOUBLE, 10000, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_SEP_BY_TAB, 100, VAL_ASCII, VAL_APPEND);
				nmeasure[0]=i*m+h+1;
				displaychannel();
				
				Nleft=Nscans-(i*m+h);
				SetCtrlVal (Main_pnl_handle, ERG_panel_nremain, Nleft);
				ProcessSystemEvents();
				if (pause_flag)
				{
					while (pause_flag)
						ProcessSystemEvents();
				}
			}
		}
	}
	
	else{				  // mode normal
	//prepare file name for acquiring data
		while ( i < Nscans )
		{
			strcpy(filename, pathname);
			sprintf(file, "\\scope_data%d.txt", i);
			strcat(filename, file);
			data_file = OpenFile (filename, VAL_WRITE_ONLY, VAL_TRUNCATE, VAL_ASCII);
			color=floor(256/Nscans)*i;
			waveform(color, data_file);
			get_intensity();
			
			headerfile();
			ArrayToFile (filename, data2fit, VAL_DOUBLE, 10000, 1, VAL_GROUPS_TOGETHER, VAL_GROUPS_AS_ROWS, VAL_SEP_BY_TAB, 100, VAL_ASCII, VAL_APPEND);
			
			i++;
			Nleft=Nscans-i+1;
			SetCtrlVal (Main_pnl_handle, ERG_panel_nremain, Nleft);
			ProcessSystemEvents();
			if (pause_flag)
			{
				while (pause_flag)
					ProcessSystemEvents();
			}
			CloseFile (data_file);
		}
	}
	
	SetCtrlVal (Main_pnl_handle, ERG_panel_nremain, 0);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_pause, ATTR_DIMMED, 1);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_abortscan, ATTR_DIMMED, 1);
	SetCtrlAttribute (Main_pnl_handle, ERG_panel_acquire, ATTR_DIMMED, 0);
	
// stop trigger 	
	SRS_flag=0;
	SRS_onoff();
	
	ibsic(device); 
	return;
}
Beispiel #10
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;
}