| |
// gpib.c : Sample project for the GPIB-1, PCIGPIB and USB GPIB // Modules under National Instrument Labwindows/CVI // // The complete project is available as download. // // Author: Michael Reimer, QUANCOM Informationssysteme GmbH, Germany // // Website: http://www.quancom.de // // Product: // GPIB PCI Controller http://www.quancom.de/qprod01/eng/pb/pcigpib_1.htm // GPIB ISA Controller http://www.quancom.de/qprod01/eng/pb/GPIB_1.htm // GPIB USB Controller http://www.quancom.de/qprod01/eng/pb/usb_gpib_1.htm // // To use the QLIB Commands in your source, do the following: // // (1) Add statement #include "qlib.h" to your source file. // (2) Add the qlib32.lib import library to your project.
/*---------------------------------------------------------------------------*/ /* Include files */ /*---------------------------------------------------------------------------*/ #include <cvirte.h> #include "qlib.h" /* Notice we need the QLIB API DLL function prototypes */ #include <userint.h> #include <utility.h> #include <ansi_c.h>
#include <panel_gpib.h>
/*---------------------------------------------------------------------------*/ /* This is the application's entry-point. */ /*---------------------------------------------------------------------------*/
int panel_handle, change, loop; unsigned long handle = 0;
int main (int argc, char *argv[]) { char message[50]; char text[50]; int j; if (InitCVIRTE (0, argv, 0) == 0) return -1; // The following sequence tries to find the // Bus Type ( PCI, ISA or USB ) of the // installed GPIB Controller handle = QAPIExtOpenCard(PCIGPIB,0);
if ( handle == NULL ) { handle = QAPIExtOpenCard(USBGPIB,0); if ( handle == NULL ) { handle = QAPIExtOpenCard(GPIB,0); } }
// The handle is != NULL if there is a GPIB Controller installed
if ( handle == NULL ) { MessagePopup("Error", "Can't open any GPIB Card!"); return FALSE; } else { panel_handle = LoadPanel (0, "panel_gpib.uir", PANEL); for (j=1;j<14;j++) { sprintf(text,"%i",j); InsertListItem(panel_handle, PANEL_LIST1, j-1, text, j); InsertListItem(panel_handle, PANEL_LIST2, j-1, text, j); InsertListItem(panel_handle, PANEL_LIST3, j-1, text, j); InsertListItem(panel_handle, PANEL_LIST4, j-1, text, j); } InsertListItem(panel_handle, PANEL_LIST5, 0,"GTL (Goto Local)",
0); InsertListItem(panel_handle, PANEL_LIST5, 1,"SDC (Selected Device
Clear)", 1); InsertListItem(panel_handle, PANEL_LIST5, 2,"GET (Group Execute
Trigger)", 2); InsertListItem(panel_handle, PANEL_LIST5, 3,"LLO (Local
Lockout)", 3); InsertListItem(panel_handle, PANEL_LIST5, 4,"DCL (Device Clear)",
4); DisplayPanel(panel_handle); RunUserInterface(); } CloseCVIRTE (); return 0; }
int CVICALLBACK TIMEREVENT(int panel, int control, int event, void *callbackData, int
eventData1, int eventData2) { if ( event == EVENT_TIMER_TICK ) { unsigned long result; if ( handle )
{
result = QAPIExtSpecial(handle,
JOB_READSRQ, 0, 0); if ( result == 0) { SetCtrlVal(panel_handle,
PANEL_TEXTSRQ, "No service requested"); } else { SetCtrlVal(panel_handle,
PANEL_TEXTSRQ, "Device has requested service ( SRQ )"); } }
return TRUE; } return 0; }
int CVICALLBACK SHUTDOWN(int panel, int control, int event, void *callbackData, int
eventData1, int eventData2) { if ( event == EVENT_COMMIT ) { QuitUserInterface (0); if ( handle != 0 ) { //QAPIExtCloseCard(handle); handle = 0; } return TRUE; } return 0; }
int CVICALLBACK POLL(int panel, int control, int event, void *callbackData, int
eventData1, int eventData2) { if ( event == EVENT_COMMIT ) { unsigned long list; char text[100]; unsigned long result; unsigned long pollbyte; GetCtrlVal(panel_handle, PANEL_LIST3, &list); // if ( handle ) { result = QAPIExtSpecial(handle, JOB_SERIALPOLL, list,
(unsigned long)&pollbyte); if (result) { // data successfully read from gpib device sprintf(text,"%x", pollbyte & 0xFFL); SetCtrlVal(panel_handle, PANEL_TEXT3, (char*)text); } else { // failure device not present SetCtrlVal(panel_handle, PANEL_TEXT3, "<No answer>"); } } return TRUE; } return 0;
}
int CVICALLBACK RECEIVE(int panel, int control, int event, void *callbackData, int
eventData1, int eventData2) { if ( event == EVENT_COMMIT ) { unsigned long list; char text[100]; unsigned long result; GetCtrlVal(panel_handle, PANEL_LIST2, &list); // if ( handle ) { result = QAPIExtReadString(handle, list, text,
sizeof(text)-1, 0); if (result) { // data successfully read from gpib device SetCtrlVal(panel_handle, PANEL_TEXT2, (char*)&text); } else { // failure MessagePopup("Error","Failure sending data!"); } } return TRUE; } return 0;
}
int CVICALLBACK SEND(int panel, int control, int event, void *callbackData, int
eventData1, int eventData2) { if ( event == EVENT_COMMIT ) { unsigned long list; char text[100]; unsigned long result; GetCtrlVal(panel_handle, PANEL_LIST1, &list); GetCtrlVal(panel_handle, PANEL_TEXT1, (char*)&text); if ( handle ) { result = QAPIExtWriteString(handle, list, text,
strlen(text), 0); if (result) { // data send to gpib device } else { // failure MessagePopup("Error","Failure sending data!"); } } return TRUE; } return 0;
}
int CVICALLBACK SENDCOMMAND(int panel, int control, int event, void *callbackData, int
eventData1, int eventData2) { if ( event == EVENT_COMMIT ) { unsigned long list1; unsigned long list2; char text[100]; unsigned long result; unsigned long nCmd; GetCtrlVal(panel_handle, PANEL_LIST4, &list1); GetCtrlVal(panel_handle, PANEL_LIST5, &list2); if ( handle ) { switch (list2) { case 0: nCmd = JOB_GTL; break; case 1: nCmd = JOB_SDC; break; case 2: nCmd = JOB_GET; break; case 3: nCmd = JOB_LLO; break; case 4: nCmd = JOB_DCL; break; default: nCmd = JOB_GTL;
} result = QAPIExtSpecial(handle, nCmd, list1, 0); if (result) { // data send to gpib device } else { // failure MessagePopup("Error","Failure sending data!"); } } return TRUE; } return 0;
}
int CVICALLBACK REN(int panel, int control, int event, void *callbackData, int
eventData1, int eventData2) { if ( event == EVENT_COMMIT ) { BOOL bREN; unsigned long result; if ( handle ) { GetCtrlVal(panel_handle, PANEL_REN, &bREN); result = QAPIExtSpecial(handle, JOB_REN, bREN,
0); } } return 0; }
|
|