⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sample5_3.c

📁 CVI例程
💻 C
字号:
#include <formatio.h>#include <ansi_c.h>#include <gpib.h>#include <cvirte.h>		/* Needed if linking in external compiler; harmless otherwise */#include <userint.h>#include "sample5_3.h"static int panelHandle;int func,addr,board;int OpenedBoard=0,OpenedDevice=0;int main (int argc, char *argv[]){	if (InitCVIRTE (0, argv, 0) == 0)	/* Needed if linking in external compiler; harmless otherwise */		return -1;	/* out of memory */	if ((panelHandle = LoadPanel (0, "sample5_3.uir", SAMPLE5_3)) < 0)		return -1;	DisplayPanel (panelHandle);	RunUserInterface ();	return 0;}int CVICALLBACK Continue (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	if(event==EVENT_COMMIT) {		GetCtrlVal (panelHandle, SAMPLE5_3_SELECTADDRESS, &addr);		GetCtrlVal (panelHandle, SAMPLE5_3_SELECTBOARD, &board);		DiscardPanel(panelHandle);   		if(func==1)			panelHandle=LoadPanel (0, "sample5_3.uir",DEVICE );		else{			panelHandle=LoadPanel (0, "sample5_3.uir",BOARD);            OpenedDevice = ibdev (board, addr, NO_SAD, T10s, 1, 0);    		}        SetCtrlAttribute (panelHandle, DEVICE_STATUS_MSG, ATTR_VISIBLE, 0);		DisplayPanel(panelHandle);	}	return 0;}int CVICALLBACK Quit (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	if(event==EVENT_COMMIT){		if(OpenedBoard)			ibonl (OpenedBoard, 0); 		QuitUserInterface (0);	}	return 0;}int CVICALLBACK OpenBoard (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	char command[256],buf[256];	if(event==EVENT_COMMIT){		if(board==0) strcpy(command,"gpib0");		if(board==1) strcpy(command,"gpib1"); 		if(board==2) strcpy(command,"gpib2"); 		if(board==3) strcpy(command,"gpib3"); 		sprintf(buf,"ibfind (\"%s\")",command);  		ResetTextBox (panelHandle, BOARD_COMMAND, "");        SetCtrlVal (panelHandle, BOARD_COMMAND, buf);        OpenedBoard = ibfind (command);        if (ibsta & 0x8000){            SetCtrlVal (panelHandle, BOARD_STATUS, 1);            SetCtrlVal (panelHandle, BOARD_ERROR, iberr);            SetCtrlVal (panelHandle, BOARD_COUNT, 0);         }        else{            SetCtrlVal (panelHandle, BOARD_STATUS, 0);            SetCtrlVal (panelHandle, BOARD_ERROR, 0);            SetCtrlVal (panelHandle, BOARD_COUNT, ibcnt);             SetCtrlAttribute (panelHandle, BOARD_CLEARBOARD, ATTR_DIMMED, 0);          } 	}	return 0;}int CVICALLBACK ClearBoard (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	char buf[256];	if(event==EVENT_COMMIT){		sprintf(buf,"ibsic (%d)",OpenedBoard);		ResetTextBox (panelHandle, BOARD_COMMAND, "");        SetCtrlVal (panelHandle, BOARD_COMMAND, buf);		ibsic(OpenedBoard);          if (ibsta & 0x8000){            SetCtrlVal (panelHandle, BOARD_STATUS, 1);            SetCtrlVal (panelHandle, BOARD_ERROR, iberr);            SetCtrlVal (panelHandle, BOARD_COUNT, 0);         }        else{            SetCtrlVal (panelHandle, BOARD_STATUS, 0);            SetCtrlVal (panelHandle, BOARD_ERROR, 0);            SetCtrlVal (panelHandle, BOARD_COUNT, ibcnt);             SetCtrlAttribute (panelHandle, BOARD_CLEARBOARD, ATTR_DIMMED, 0);          }  	}	return 0;}int CVICALLBACK DeviceQuit (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	if(event==EVENT_COMMIT){		ibonl (OpenedDevice, 0);		QuitUserInterface (0);	}	return 0;}int CVICALLBACK WriteRead (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	char buf[10000];	int bytes;	if(event==EVENT_COMMIT){		GetCtrlVal (panelHandle, DEVICE_SELECTFUNC, &func);		if(func==0){//write			GetCtrlVal (panelHandle, DEVICE_COMMAND, buf);			SetCtrlAttribute (panelHandle, DEVICE_STATUS_MSG, ATTR_VISIBLE, 1);            ProcessDrawEvents();            ibwrt (OpenedDevice, buf, strlen(buf));            SetCtrlAttribute (panelHandle, DEVICE_STATUS_MSG, ATTR_VISIBLE, 0);            ProcessDrawEvents();        }        else{        	GetCtrlVal (panelHandle, DEVICE_BYTESTOREAD, &bytes);        	SetCtrlAttribute (panelHandle, DEVICE_STATUS_MSG, ATTR_VISIBLE, 1);            ProcessDrawEvents();            ibrd (OpenedDevice,buf, bytes);            SetCtrlAttribute (panelHandle, DEVICE_STATUS_MSG, ATTR_VISIBLE, 0);            ProcessDrawEvents();			if (!(ibsta & 0x8000)){ 				ResetTextBox (panelHandle, DEVICE_DATARECEIVED, "");                InsertTextBoxLine (panelHandle, DEVICE_DATARECEIVED, 0, buf);                FillBytes (buf, 0, bytes, 0x0);			}		}        if (ibsta & 0x8000){           	SetCtrlVal (panelHandle, DEVICE_STATUS, 1);            SetCtrlVal (panelHandle, DEVICE_ERROR, iberr);            SetCtrlVal (panelHandle, DEVICE_COUNT, 0);         }	    else{	        SetCtrlVal (panelHandle, DEVICE_STATUS, 0);	        SetCtrlVal (panelHandle, DEVICE_ERROR, 0);	        SetCtrlVal (panelHandle, DEVICE_COUNT, ibcnt); 	    }	}	return 0;}int CVICALLBACK SelectFunc (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	if(event==EVENT_COMMIT)	{		GetCtrlVal (panelHandle, SAMPLE5_3_SELECTFUNC, &func);		if(func==1)			SetCtrlAttribute (panelHandle, SAMPLE5_3_SELECTADDRESS, ATTR_DIMMED,0);		else			SetCtrlAttribute (panelHandle, SAMPLE5_3_SELECTADDRESS, ATTR_DIMMED,1);	}	return 0;}int CVICALLBACK Func (int panel, int control, int event,		void *callbackData, int eventData1, int eventData2){	if(event==EVENT_COMMIT){		GetCtrlVal (panelHandle, DEVICE_SELECTFUNC, &func);		if(func==1) {			 SetCtrlAttribute (panelHandle, DEVICE_STATUS_MSG, ATTR_CTRL_VAL, "正在读取数据...");			 SetCtrlAttribute (panelHandle, DEVICE_WRITEREAD, ATTR_LABEL_TEXT,"读数据");		}		else	{			 SetCtrlAttribute (panelHandle, DEVICE_WRITEREAD, ATTR_LABEL_TEXT,"发命令");			 SetCtrlAttribute (panelHandle, DEVICE_STATUS_MSG, ATTR_CTRL_VAL, "正在发送数据...");		}	}	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -