📄 pci_testdlg.cpp
字号:
// pci_testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "pci_test.h"
#include "pci_testDlg.h"
#include <windows.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef void VOIDFUNC();
/////////////////////////////////////////////////////////////////////////////
// CPci_testDlg dialog
CPci_testDlg::CPci_testDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPci_testDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPci_testDlg)
m_intChange = 0;
m_initial = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPci_testDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPci_testDlg)
DDX_Text(pDX, IDC_EDIT2, m_intChange);
DDX_Text(pDX, IDC_EDIT1, m_initial);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPci_testDlg, CDialog)
//{{AFX_MSG_MAP(CPci_testDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, change)
ON_BN_CLICKED(IDC_BUTTON3, ampon)
ON_BN_CLICKED(IDC_BUTTON4, ampoff)
ON_BN_CLICKED(IDC_BUTTON5, lowcorrect)
ON_BN_CLICKED(IDC_BUTTON6, lowcorrect_off)
ON_BN_CLICKED(IDC_BUTTON7, highcorrect_on)
ON_BN_CLICKED(IDC_BUTTON8, highcorrect_off)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPci_testDlg message handlers
BOOL CPci_testDlg::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
hDevice = INVALID_HANDLE_VALUE;
// Name used to open device
sLinkName = "\\\\.\\PciforappDevice0";
hDevice = OpenByName();
if (hDevice == INVALID_HANDLE_VALUE)
{
AfxMessageBox("ERROR opening device");
return TRUE;
}
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 CPci_testDlg::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 CPci_testDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
HANDLE CPci_testDlg::OpenByName(void)
{
// Create a handle to the driver
return CreateFile(sLinkName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);
}
void CPci_testDlg::Exit(int res)
{
CloseIfOpen();
exit(res);
}
void CPci_testDlg::CloseIfOpen(void)
{
if (hDevice != INVALID_HANDLE_VALUE)
{
// Close the handle to the driver
if (!CloseHandle(hDevice))
{
AfxMessageBox("ERROR: CloseHandle");
}
hDevice = INVALID_HANDLE_VALUE;
}
}
int CPci_testDlg::doWrite(int input)
{
ULONG nWritten;
//buf = (int *) malloc( sizeof(int) );
/*if (buf == NULL)
{
AfxMessageBox("Failed to allocate buffer for write");
return;
}*/
// load buffer with dummy data (abcdefg...)
int buf = input;
// Write data to driver+
WriteFile(hDevice, &buf, 4, &nWritten, NULL);
return buf;
//free(buf);
}
void CPci_testDlg::OnButton1()
{
AfxMessageBox("接收机初始化开始,请等待6秒左右");
int buf;
CString m_strBuf;
buf = doWrite(0x000); //12'b000000 000 000
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
//m_intChange = m_strBuf;
UpdateData( FALSE );
Sleep(6000);
buf = doWrite(0x880); //12'b1000 1000 0000
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
//m_intChange = m_strBuf;
UpdateData( FALSE );
Sleep(2000);
buf = doWrite(0x912); //12'b100100 010 010
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
//m_intChange = m_strBuf;
UpdateData( FALSE );
AfxMessageBox("接收机初始化完成");
}
void CPci_testDlg::change()
{
int buf;
CString m_strBuf;
UpdateData( TRUE );
buf = doWrite(m_intChange); //
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
AfxMessageBox("接收机增益更改完成");
}
void CPci_testDlg::ampon()
{
int buf;
CString m_strBuf;
buf = doWrite(0x912); //12'b1001 0001 0010
m_strBuf.Format( "%x", buf );
AfxMessageBox("完成");
//m_intChange = m_strBuf;
}
void CPci_testDlg::ampoff()
{
int buf;
CString m_strBuf;
buf = doWrite(0x992); //12'b1001 1001 0010
m_strBuf.Format( "%x", buf );
AfxMessageBox("完成");
//m_intChange = m_strBuf;
}
void CPci_testDlg::lowcorrect()
{
int buf;
CString m_strBuf;
buf = doWrite(0xd12); //12'b1101 0001 0010
m_strBuf.Format( "%x", buf );
AfxMessageBox("完成");
//m_intChange = m_strBuf;
}
void CPci_testDlg::lowcorrect_off()
{
int buf;
CString m_strBuf;
buf = doWrite(0x912); //12'b1001 0001 0010
m_strBuf.Format( "%x", buf );
AfxMessageBox("完成");
//m_intChange = m_strBuf;
}
void CPci_testDlg::highcorrect_on()
{
int buf;
CString m_strBuf;
buf = doWrite(0xd12); //12'b1111 0001 0010
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
//m_intChange = m_strBuf;
buf = doWrite(0xd92); //12'b1101 1001 0010
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
//m_intChange = m_strBuf;
buf = doWrite(0xf92); //12'b1111 1001 0010
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
AfxMessageBox("完成");
}
void CPci_testDlg::highcorrect_off()
{
int buf;
CString m_strBuf;
buf = doWrite(0x992); //12'b1001 1001 0010
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
Sleep(1000);
buf = doWrite(0x912); //12'b1001 0001 0010
m_strBuf.Format( "%x", buf );
//AfxMessageBox( m_strBuf );
AfxMessageBox("完成");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -