📄 camtestdlg.cpp
字号:
// camtestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "camtest.h"
#include "camtestDlg.h"
#include "ppcam32.h"
#include <mmsystem.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCamtestDlg dialog
CCamtestDlg::CCamtestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCamtestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCamtestDlg)
m_sValue = _T("");
m_sNTR = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_nC = 0;
m_nN = 0;
m_nA = 0;
m_nF = 0;
m_nValue = 0;
m_nNOB = 0;
m_nNTR = 0;
}
void CCamtestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCamtestDlg)
DDX_Control(pDX, IDC_COMBO5, m_cNOB);
DDX_Control(pDX, IDC_COMBO4, m_cFunction);
DDX_Control(pDX, IDC_COMBO3, m_cAddress);
DDX_Control(pDX, IDC_COMBO2, m_cStation);
DDX_Control(pDX, IDC_COMBO1, m_cCrate);
DDX_Control(pDX, IDC_LIST1, m_cDataLB);
DDX_Control(pDX, IDC_RADIO2, m_cXBit);
DDX_Control(pDX, IDC_RADIO1, m_cQBit);
DDX_Text(pDX, IDC_EDIT1, m_sValue);
DDX_Text(pDX, IDC_EDIT2, m_sNTR);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCamtestDlg, CDialog)
//{{AFX_MSG_MAP(CCamtestDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnExecute)
ON_BN_CLICKED(IDC_BUTTON2, OnDMARead)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCamtestDlg message handlers
BOOL CCamtestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
m_cCrate.SetCurSel(0);
m_cStation.SetCurSel(0);
m_cAddress.SetCurSel(0);
m_cFunction.SetCurSel(3);
m_cNOB.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CCamtestDlg::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 CCamtestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCamtestDlg::Read_Controls()
{
UpdateData();
CString sMesg;
m_cCrate.GetWindowText(sMesg);
m_nC = atoi(sMesg);
m_cStation.GetWindowText(sMesg);
m_nN = atoi(sMesg);
m_cAddress.GetWindowText(sMesg);
m_nA = atoi(sMesg);
m_cFunction.GetWindowText(sMesg);
m_nF = atoi(sMesg);
m_cNOB.GetWindowText(sMesg);
m_nNOB = atoi(sMesg);
m_nValue = atoi(m_sValue);
m_nNTR = atoi(m_sNTR);
}
void CCamtestDlg::Update_GUI()
{
CString sMesg;
sMesg.Format("%i",m_nC);
m_cCrate.SetWindowText(sMesg);
sMesg.Format("%i",m_nN);
m_cStation.SetWindowText(sMesg);
sMesg.Format("%i",m_nA);
m_cAddress.SetWindowText(sMesg);
sMesg.Format("%i",m_nF);
m_cFunction.SetWindowText(sMesg);
sMesg.Format("%i",m_nNOB);
m_cNOB.SetWindowText(sMesg);
m_sValue.Format("%i",m_nValue);
m_sNTR.Format("%i",m_nNTR);
UpdateData(FALSE);
}
void CCamtestDlg::OnExecute()
{
int dwValue, nQ, nX;
// TODO: Add your control notification handler code here
Read_Controls();
Update_GUI();
Crate_set(&m_nC);
if (m_nF < 8) {
// Input function
dwValue = 0;
cami(&m_nN, &m_nF, &m_nA, &dwValue, &nQ, &nX);
// Show results
m_sValue.Format("%i",dwValue);
UpdateData(FALSE);
m_cXBit.SetCheck((nX == 1) ? 1 : 0);
m_cQBit.SetCheck((nQ == 1) ? 1 : 0);
}
else {
// Output function
camo(&m_nN, &m_nF, &m_nA, &m_nValue, &nQ, &nX);
m_cXBit.SetCheck((nX == 1) ? 1 : 0);
m_cQBit.SetCheck((nQ == 1) ? 1 : 0);
}
}
void CCamtestDlg::OnDMARead()
{
int QBL, i, E, ByteLen;
unsigned int data;
unsigned char* pData;
CString sMesg;
DWORD dwStart, dwEnd;
double dRate;
Read_Controls();
Update_GUI();
m_cDataLB.ResetContent();
// Decode "number of bytes" to determine data alignment
switch (m_nNOB) {
case 1:
ByteLen = sizeof(char);
break;
case 2:
ByteLen = sizeof(short);
break;
case 3:
ByteLen = sizeof(DWORD);
break;
default:
data = 0;
} //end switch
pData = new unsigned char[m_nNTR * ByteLen];
dmaset(&m_nC, &m_nNOB, &QBL, (unsigned int*) &m_nNTR);
CWaitCursor oWC;
dwStart = timeGetTime();
dmai(&m_nN, &m_nF, &m_nA, pData, &E);
dwEnd = timeGetTime();
dRate = ((1000.0 * m_nNTR * ByteLen) / (dwEnd - dwStart)) / 1024.0;
// Compute transfer rate
sMesg.Format("Rate=%1.0f KBPS",dRate);
m_cDataLB.AddString(sMesg);
// Return results in list box
for (i=0; i<m_nNTR; i++) {
switch (m_nNOB) {
case 1:
data = (unsigned int) *((unsigned char*) (pData) + i);
break;
case 2:
data = (unsigned int) *((unsigned short*) (pData) + i);
break;
case 3:
data = (unsigned int) *((DWORD*) (pData) + i);
break;
default:
data = 0;
} //end switch
sMesg.Format("%i: %u",i+1,data);
m_cDataLB.AddString(sMesg);
} //end for
delete pData;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -