int main(int argc, char *argv[]) { int loop; check_args(argc); for (loop=0;loop<=19-1;loop++) { inData[loop] = 0; } unsigned short addlist[2] = {atoi(argv[1]), NOADDR}; // list to enable inst //Reset Card 0 (i.e:gpib0) SendIFC(0); // ENABLE all on GPIB bus EnableRemote(0, addlist); // If error, Bye! if (ibsta & ERR) { printf("Instrument enable failed!\n"); exit(1); } // Send (BoardID, GPIBAddr, Command, LengthCommand, Endline) // typical command: // Send(0, 20, "*RST", 4l, NLend); Send(0, atoi(argv[1]), argv[2], strlen(argv[2]), NLend); Receive(0, atoi(argv[1]), inData, 19, STOPend); printf("%s",inData); }
void gpib_send(unsigned int gpib_board, unsigned int gpib_device, char *command_string ) { unsigned short addlist[2] = {gpib_device, NOADDR}; SendIFC(gpib_board); //Enable all on GPIB bus EnableRemote(gpib_board, addlist); if(ibsta & ERR) { printf("gpib_send: Instrument enable failed! \n"); } //Send Control Commandss Send(gpib_board, gpib_device, command_string, strlen(command_string), NLend); if(ibsta & ERR) { printf("gpib_send: Send failed! \n"); } printf("%s \n",command_string); }
int wxGPIB::FindListeners(int board) { int i; int listeners = 0; if((unsigned int)board > 1) { return -1; } // reset the GPIB, otherwise no connected device is found (linux) SendIFC(board); // list of primary addresses to searching for. Must be terminated // with NOADDR. Addr4882_t addrlist[31]; // The range of valid addresses is 1...30, 0 is reservated by the // controller, 31 is not valid for( i = 0;i < 30; i++) addrlist[i] = (Addr4882_t) i + 1; addrlist[30] = NOADDR; // place to store the results Addr4882_t results[31]; memset(results,0,sizeof(results)); FindLstn(board, addrlist, results, 31); if(ibsta & ERR) { return -1; } for( i=0;i<=30;i++) { if(results[i]) { listeners |= 1 << results[i]; } } return listeners; };
/** Find all listeners. @param boardId Id/number of board for listing @return Pointer to list of Addr4882_t containing numbers of all listening devices, this list should be free by delete[] */ Addr4882_t *GPIB::findLstn(int boardId) { /** valid GIPB addresses: 0 - master 1-30 - valid device addresses 31 - all devices? */ const Addr4882_t PIDsLstnTest[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, NOADDR }; Addr4882_t *PIDsLstn; SendIFC(boardId); if ((Ibsta() & ERR)) return NULL; PIDsLstn = new Addr4882_t[ARRAY_SIZE(PIDsLstnTest)]; ::FindLstn(boardId, PIDsLstnTest, PIDsLstn, ARRAY_SIZE(PIDsLstnTest) - 1); if (Ibsta() & ERR) { delete[] PIDsLstn; return NULL; } PIDsLstn[Ibcnt()] = NOADDR; return PIDsLstn; }
/** Open device connected to GPIB. @param boardNum Id/number of board to open. @param PAD Primary device address in range 1-30 @see PIDsLstnTest @param SAD Secondary device address. */ int GPIB::open(int boardNum, int PAD, int SAD) { SendIFC(boardNum); if ((Ibsta() & ERR) != 0) { return -1; } devId = ibdev(boardNum, PAD, SAD, T1s, 1, 0); if (devId >= 0) { ibclr(devId); ibrsp(devId, &poll); ibtmo(devId, T3s); SendLLO(boardNum); } return devId; }
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; }