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

📄 4882mfcdlg.cpp

📁 488.2规范的MFC库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 4882MFCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "4882MFC.h"
#include "4882MFCDlg.h"
#include "decl-32.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

void gpiberr(char *);            // ADDED- function prototype for gpiberr.

// ADDED- For writing strings to the List Box (Fluke 45 Readings).
void DDX_ListText(CDataExchange *pDX, UINT nID, CStringList *pCStringList);

#define  MAVbit   0x10           // ADDED- Position of the Message Available bit.

int ReadingsTaken;               // ADDED- counter for readings taken.

char          buffer[101];       // ADDED- Data received from the Fluke 45
int           loop,              // ADDED- FOR loop counter and array index
              num_listeners,     // ADDED- Number of listeners on GPIB
              pad;               // ADDED- Primary address of listener on GPIB
short         SRQasserted,       // ADDED- Set to indicate if SRQ is asserted
              statusByte;        // ADDED- Serial Poll Response Byte
double        sum;               // ADDED- Accumulator of measurements
Addr4882_t    fluke,             // ADDED- Primary address of the Fluke 45
              instruments[32],   // ADDED- Array of primary addresses
              result[31];        // ADDED- Array of listen addresses

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
   CAboutDlg();

// Dialog Data
   //{{AFX_DATA(CAboutDlg)
   enum { IDD = IDD_ABOUTBOX };
   //}}AFX_DATA

   // ClassWizard generated virtual function overrides
   //{{AFX_VIRTUAL(CAboutDlg)
   protected:
   virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
   //}}AFX_VIRTUAL

// Implementation
protected:
   //{{AFX_MSG(CAboutDlg)
   //}}AFX_MSG
   DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
   //{{AFX_DATA_INIT(CAboutDlg)
   //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(CAboutDlg)
   //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
   //{{AFX_MSG_MAP(CAboutDlg)
      // No message handlers
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy4882MFCDlg dialog

CMy4882MFCDlg::CMy4882MFCDlg(CWnd* pParent /*=NULL*/)
   : CDialog(CMy4882MFCDlg::IDD, pParent)
{
   //{{AFX_DATA_INIT(CMy4882MFCDlg)
      // NOTE: the ClassWizard will add member initialization here
   //}}AFX_DATA_INIT
   // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
   m_hIcon = AfxGetApp()->LoadIcon(IDI_ELITEK);
}

void CMy4882MFCDlg::DoDataExchange(CDataExchange* pDX)
{
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(CMy4882MFCDlg)
      // NOTE: the ClassWizard will add DDX and DDV calls here
   //}}AFX_DATA_MAP

    // ADDED- function used to display the Fluke 45 multimeter
    //        readings to the List Box control.
   DDX_ListText(pDX, IDC_LIST1, &m_ListReadings);
}

BEGIN_MESSAGE_MAP(CMy4882MFCDlg, CDialog)
   //{{AFX_MSG_MAP(CMy4882MFCDlg)
   ON_WM_SYSCOMMAND()
   ON_WM_PAINT()
   ON_WM_QUERYDRAGICON()
   ON_BN_CLICKED(IDOK, OnRun)
   ON_BN_CLICKED(ID_APP_ABOUT, OnAppAbout)
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy4882MFCDlg message handlers

BOOL CMy4882MFCDlg::OnInitDialog()
{
   CDialog::OnInitDialog();

   // Add "About..." menu item to system menu.

   // IDM_ABOUTBOX must be in the system command range.
   ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
   ASSERT(IDM_ABOUTBOX < 0xF000);

   CMenu* pSysMenu = GetSystemMenu(FALSE);
   CString strAboutMenu;
   strAboutMenu.LoadString(IDS_ABOUTBOX);
   if (!strAboutMenu.IsEmpty())
   {
      pSysMenu->AppendMenu(MF_SEPARATOR);
      pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
   }

   // Set the icon for this dialog.  The framework does this automatically
   //  when the application's main window is not a dialog
   SetIcon(m_hIcon, TRUE);       // Set big icon
   SetIcon(m_hIcon, FALSE);      // Set small icon

   // TODO: Add extra initialization here

   return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy4882MFCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
   if ((nID & 0xFFF0) == IDM_ABOUTBOX)
   {
      CAboutDlg dlgAbout;
      dlgAbout.DoModal();
   }
   else
   {
      CDialog::OnSysCommand(nID, lParam);
   }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMy4882MFCDlg::OnPaint()
{
   if (IsIconic())
   {
      CPaintDC dc(this); // device context for painting

      SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

      // Center icon in client rectangle
      int cxIcon = GetSystemMetrics(SM_CXICON);
      int cyIcon = GetSystemMetrics(SM_CYICON);
      CRect rect;
      GetClientRect(&rect);
      int x = (rect.Width() - cxIcon + 1) / 2;
      int y = (rect.Height() - cyIcon + 1) / 2;

      // Draw the icon
      dc.DrawIcon(x, y, m_hIcon);
   }
   else
   {
      CDialog::OnPaint();
   }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMy4882MFCDlg::OnQueryDragIcon()
{
   return (HCURSOR) m_hIcon;
}

void CMy4882MFCDlg::OnCancel()
{
   // TODO: Add extra cleanup here

   CDialog::OnCancel();
}

// ADDED- In this sample program, when the Run button is clicked, it
//        will execute the code contained in this function. For the
//        purposes of this example, it will initialize the Fluke 45
//        Digital Multimeter and get 10 measurements from the Fluke.
void CMy4882MFCDlg::OnRun()
{
   char str[100];

   // If not already cleared, clear the List Box of all the
   // Fluke 45 measurements that are currently displayed.
   if (!m_ListReadings.IsEmpty())
      m_ListReadings.RemoveAll();

   //  Your board needs to be the Controller-In-Charge in order to find all
   //  listeners on the GPIB.  To accomplish this, the function SendIFC is
   //  called.  If the error bit ERR is set in IBSTA, call GPIBERR with
   //  an error message.
   SendIFC(0);
   if (ibsta & ERR)
   {
      gpiberr ("SendIFC Error");
      return;
   }

   //  Create an array containing all valid GPIB primary addresses.  Your GPIB
   //  interface board is at address 0 by default.  This  array (INSTRUMENTS)
   //  will be given to the function FindLstn to find all listeners.  The
   //  constant NOADDR, defined in DECL-32.H, signifies the end of the array.
   for (loop = 0; loop <= 30; loop++)
   {
      instruments[loop] = (Addr4882_t)loop;
   }
   instruments[31] = NOADDR;

   //  Print message to tell user that the program is searching for all active
   //  listeners.  Find all of the listeners on the bus.   Store the listen
   //  addresses in the array RESULT.  If the error bit ERR is set in IBSTA,
   //  call GPIBERR with an error message.
   sprintf(str, "Finding all listeners on the bus...");
   m_ListReadings.AddTail(str);

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

   FindLstn(0, &instruments[1], (Addr4882_t *)result, 31);
   if (ibsta & ERR)
   {
      gpiberr("FindLstn Error");
      return;
   }

   //  Assign the value of IBCNT to the variable NUM_LISTENERS.
   //  Print the number of listeners found.
   num_listeners = ibcnt;

   sprintf(str, "Number of instruments found = %d", num_listeners);
   m_ListReadings.AddTail(str);

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

   //  Send the *IDN? command to each device that was found.
   //
   //  Establish a FOR loop to determine if the Fluke 45 is a listener on the
   //  GPIB.  The variable LOOP will serve as a counter for the FOR loop and
   //  as the index to the array RESULT.
   for (loop = 0; loop <= num_listeners; loop++)
   {
      //  Send the identification query to each listen address in the
      //  array RESULT.  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, result[loop], "*IDN?", 5L, NLend);
      if (ibsta & ERR)
      {
         gpiberr("Send Error");
         return;
      }

      //  Read the name identification response returned from each device.
      //  Store the response in the array 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, result[loop], buffer, 10L, STOPend);
      if (ibsta & ERR)

⌨️ 快捷键说明

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