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

📄 4882mfcdlg.cpp

📁 488.2规范的MFC库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      {
         gpiberr("Receive Error");
         return;
      }

      //  The low byte of the listen address is the primary address.
      //  Assign the variable PAD the primary address of the device.
      //  The macro GetPAD, defined in DECL-32.H, returns the low byte
      //  of the listen address.
      pad = GetPAD(result[loop]);

      //  The string returned by Receive is a binary string whose length is
      //  specified by the byte count in IBCNTL. However, the Fluke 45
      //  sends measurements in the form of ASCII strings. Because of
      //  this, it is possible to add a NULL character to the end of the
      //  data received and use the PRINTF function to display the ASCII
      //  Fluke 45 response. The following code illustrates that.
      buffer[ibcnt] = '\0';
      printf("The instrument at address %d is a %s\n", pad, buffer);

      //  Determine if the name identification is the Fluke 45.  If it is
      //  the Fluke 45, assign PAD to FLUKE,  print message that the
      //  Fluke 45 has been found, call the function FOUND, and terminate
      //  FOR loop.
      if (strncmp(buffer, "FLUKE, 45", 9) == 0)
      {
         fluke = (Addr4882_t)pad;
         sprintf(str, "**** We found the Fluke ****");
         m_ListReadings.AddTail(str);

         // Update the List Box containing the measurements.
         UpdateData(FALSE);
         UpdateWindow();

         break;
      }

    }      /*  End of FOR loop */

    if (loop > num_listeners)
    {
       sprintf(str, "Did not find the Fluke!");
       m_ListReadings.AddTail(str);

       // Update the List Box containing the measurements.
       UpdateData(FALSE);
       UpdateWindow();
   }
   else
   {
       //  Reset the Fluke 45 using the functions DevClear and Send.
       //
       //  DevClear will send the GPIB Selected Device Clear (SDC) command message
       //  to the Fluke 45.  If the error bit ERR is set in IBSTA, call GPIBERR with
       //  an error message.
       DevClear(0, (Addr4882_t)fluke);
       if (ibsta & ERR)
       {
          gpiberr("DevClear Error");
          return;
       }

       //  Use the function Send to send the IEEE-488.2 reset command (*RST)
       //  to the Fluke 45.  The constant NLend, defined in DECL-32.H, instructs
       //  the function Send to append a linefeed character with EOI asserted
       //  to the end of the message.  If the error bit ERR is set in IBSTA,
       //  call GPIBERR with an error message.
       Send(0, (Addr4882_t)fluke, "*RST", 4L, NLend);
       if (ibsta & ERR)
       {
          gpiberr("Send *RST Error");
          return;
       }

       //  Use the function Send to send device configuration commands to the
       //  Fluke 45.  Instruct the Fluke 45 to measure 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).  If the error bit ERR is set in
       //  IBSTA, call GPIBERR with an error message.
       Send(0, (Addr4882_t)fluke, "VAC; AUTO; TRIGGER 2; *SRE 16", 29L, NLend);
       if (ibsta & ERR)
       {
          gpiberr("Send Setup Error");
          return;
       }

       //  Initialized the accumulator of the 10 measurements to zero.
       sum = 0.0;

       //  Establish FOR loop to read the 10 measurements.  The variable ReadingsTaken
       //  will serve as the counter of the FOR loop.
       for (ReadingsTaken=0; ReadingsTaken < 10 ; ReadingsTaken++)
       {
          //  Trigger the Fluke 45 by sending the trigger command (*TRG) and
          //  request a measurement by sending the command "VAL1?".  If the
          //  error bit ERR is set in IBSTA, call GPIBERR with an error message.
          Send(0, (Addr4882_t)fluke, "*TRG; VAL1?", 11L, NLend);
          if (ibsta & ERR)
          {
             gpiberr("Send Trigger Error");
             return;
          }

          //  Wait for the Fluke 45 to assert SRQ, meaning it is ready to send
          //  a measurement.  If SRQ is not asserted within the timeout period,
          //  call GPIBERR with an error message.  The timeout period by default
          //  is 10 seconds.
          WaitSRQ(0, &SRQasserted);
          if (!SRQasserted)
          {
             sprintf(str, "SRQ is not asserted.  The Fluke is not ready.");
             m_ListReadings.AddTail(str);

             // Update the List Box containing the measurements.
             UpdateData(FALSE);
             UpdateWindow();

             return;
          }

          //  Read the serial poll status byte of the Fluke 45.  If the error
          //  bit ERR is set in IBSTA, call GPIBERR with an error message.
          ReadStatusByte(0, (Addr4882_t)fluke, &statusByte);
          if (ibsta & ERR)
          {
             gpiberr("ReadStatusByte Error");
             return;
          }

          //  Check if the Message Available Bit (bit 4) of the return status
          //  byte is set.  If this bit is not set, print the status byte and
          //  call GPIBERR with an error message.
          if (!(statusByte & MAVbit))
          {
             gpiberr("Improper Status Byte");
             return;
          }

          //  Read the Fluke 45 measurement.  Store the measurement in the
          //  variable BUFFER.  The constant STOPend, defined in DECL-32.H,
          //  instructs the function Receive to terminate the read when END
          //  is detected.  If the error bit ERR is set in IBSTA, call
          //  GPIBERR with an error message.
          Receive(0, (Addr4882_t)fluke, buffer, 10L, STOPend);
          if (ibsta & ERR)
          {
             gpiberr("Receive Error");
             return;
          }

          //  The string returned by Receive is a binary string whose length is
          //  specified by the byte count in IBCNTL. However, the Fluke 45
          //  sends measurements in the form of ASCII strings. Because of
          //  this, it is possible to add a NULL character to the end of the
          //  data received and use the PRINTF function to display the ASCII
          //  Fluke 45 response. The following code illustrates that.
          buffer[ibcntl - 1] = '\0';
          sprintf(str, "Measurement #%2d ===> %s", ReadingsTaken + 1, buffer);
          m_ListReadings.AddTail(str);

          // Update the List Box containing the measurements.
          UpdateData(FALSE);
          UpdateWindow();


          //  Convert the variable BUFFER to its numeric value and add to the
          //  accumulator.
          sum = sum + atof(buffer);

       }  //  Continue FOR loop until 10 measurements are read.

       //  Print the average of the 10 measurements.
       sprintf(str, "   The average of the 10 measurements is : %f", sum/10);
       m_ListReadings.AddTail(str);

       // Update the List Box containing the measurements.
       UpdateData(FALSE);
       UpdateWindow();

   }

   //  Call the ibonl function to disable the hardware and software.
   ibonl (0,0);
}



// ADDED- This function will alert you that a NI-488 function failed
//        by printing an error message.  The status variable IBSTA
//        will also be printed in hexadecimal along with the
//        mnemonic meaning of the bit position. The status variable
//        IBERR will be printed in decimal along with the mnemonic
//        meaning of the decimal value. The status variable IBCNTL
//        will be printed in decimal.
//
//        The NI-488 function IBONL is called to disable the
//        hardware and software.
void gpiberr(char *msg)
{
   char str[100];
   char tempbuf[20];

   // Start the Message with the failing GPIB call.
   sprintf(str, msg);

   // Add ibsta information to the Message String.
   strcat(str, "  ibsta = &H");
   itoa(ibsta, tempbuf, 16);
   strcat(str, tempbuf);
   strcat(str, " <");
   if (ibsta & ERR )  strcat(str, " ERR");
   if (ibsta & TIMO)  strcat(str, " TIMO");
   if (ibsta & END )  strcat(str, " END");
   if (ibsta & SRQI)  strcat(str, " SRQI");
   if (ibsta & RQS )  strcat(str, " RQS");
   if (ibsta & CMPL)  strcat(str, " CMPL");
   if (ibsta & LOK )  strcat(str, " LOK");
   if (ibsta & REM )  strcat(str, " REM");
   if (ibsta & CIC )  strcat(str, " CIC");
   if (ibsta & ATN )  strcat(str, " ATN");
   if (ibsta & TACS)  strcat(str, " TACS");
   if (ibsta & LACS)  strcat(str, " LACS");
   if (ibsta & DTAS)  strcat(str, " DTAS");
   if (ibsta & DCAS)  strcat(str, " DCAS");
   strcat(str, " >");

   // Add iberr information to the Message String.
   strcat(str, "\niberr = ");
   itoa(iberr, tempbuf, 10);
   strcat(str, tempbuf);
   if (iberr == EDVR) strcat(str, " EDVR <DOS Error>");
   if (iberr == ECIC) strcat(str, " ECIC <Not CIC>");
   if (iberr == ENOL) strcat(str, " ENOL <No Listener>");
   if (iberr == EADR) strcat(str, " EADR <Address error>");
   if (iberr == EARG) strcat(str, " EARG <Invalid argument>");
   if (iberr == ESAC) strcat(str, " ESAC <Not Sys Ctrlr>");
   if (iberr == EABO) strcat(str, " EABO <Op. aborted>");
   if (iberr == ENEB) strcat(str, " ENEB <No GPIB board>");
   if (iberr == EOIP) strcat(str, " EOIP <Async I/O in prg>");
   if (iberr == ECAP) strcat(str, " ECAP <No capability>");
   if (iberr == EFSO) strcat(str, " EFSO <File sys. error>");
   if (iberr == EBUS) strcat(str, " EBUS <Command error>");
   if (iberr == ESTB) strcat(str, " ESTB <Status byte lost>");
   if (iberr == ESRQ) strcat(str, " ESRQ <SRQ stuck on>");
   if (iberr == ETAB) strcat(str, " ETAB <Table Overflow>");

   // Add ibcntl information to the Message String.
   strcat(str, "\nibcntl = ");
   ultoa(ibcntl, tempbuf, 16);
   strcat(str, tempbuf);
   AfxMessageBox(str, MB_ICONSTOP, 0);

   //  Call the ibonl function to disable the hardware and software.
   ibonl(0, 0);
}


// ADDED- this function is used to display the Fluke 45 readings in
//        the List Box control.


void DDX_ListText(CDataExchange *pDX, UINT nID, CStringList *pCStringList)
{
   if (!pDX->m_bSaveAndValidate)
   {
      int i;
      POSITION pos;

      pDX->PrepareCtrl(nID);

      if (pCStringList != NULL)
      {
         CListBox *pListBox = (CListBox *)pDX->m_pDlgWnd->GetDlgItem(nID);
         pListBox->ResetContent();

         for (i = 0, pos = pCStringList->GetHeadPosition(); pos != NULL; i++)
         {
            pListBox->InsertString(i, pCStringList->GetNext(pos));
         }
      }
   }
}

void CMy4882MFCDlg::OnAppAbout()
{
   // ADDED- Invoke the About Box when Help Button is pressed.
   CAboutDlg dlgAbout;
   dlgAbout.DoModal();
}

⌨️ 快捷键说明

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