📄 if101drivertestdlg.cpp
字号:
// IF101DriverTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "IF101DriverTest.h"
#include "IF101DriverTestDlg.h"
#include "IF101Ctrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
TCHAR tLGC1Buffer[0x20000];
TCHAR tLGC2Buffer[0x20000];
TCHAR tLGC3Buffer[0x20000];
/////////////////////////////////////////////////////////////////////////////
// CIF101DriverTestDlg dialog
CIF101DriverTestDlg::CIF101DriverTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CIF101DriverTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CIF101DriverTestDlg)
m_lgc1_intr = 0;
m_lgc2_intr = 0;
m_Lgc1_len = 0;
m_Lgc2_len = 0;
m_lgc3_intr = 0;
m_Lgc3_len = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CIF101DriverTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CIF101DriverTestDlg)
DDX_Control(pDX, IDC_LGC3_ST, m_lgc3_st);
DDX_Control(pDX, IDC_LGC3_SP, m_lgc3_sp);
DDX_Control(pDX, IDC_LGC2_SP, m_lgc2_sp);
DDX_Control(pDX, IDC_LGC2_ST, m_lgc2_st);
DDX_Control(pDX, IDC_LGC1_SP, m_lgc1_sp);
DDX_Control(pDX, IDC_LGC1_ST, m_lgc1_st);
DDX_Text(pDX, IDC_LGC1_INTR, m_lgc1_intr);
DDX_Text(pDX, IDC_LGC2_INTR, m_lgc2_intr);
DDX_Text(pDX, IDC_LGC1_INTR_LEN, m_Lgc1_len);
DDX_Text(pDX, IDC_LGC2_INTR_LEN, m_Lgc2_len);
DDX_Text(pDX, IDC_LGC3_INTR, m_lgc3_intr);
DDX_Text(pDX, IDC_LGC3_INTR_LEN, m_Lgc3_len);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CIF101DriverTestDlg, CDialog)
//{{AFX_MSG_MAP(CIF101DriverTestDlg)
ON_BN_CLICKED(IDC_LGC1_ST, OnLgc1St)
ON_BN_CLICKED(IDC_LGC1_SP, OnLgc1Sp)
ON_BN_CLICKED(IDC_LGC2_ST, OnLgc2St)
ON_BN_CLICKED(IDC_LGC2_SP, OnLgc2Sp)
ON_BN_CLICKED(IDC_IF101_INTR_EMULATOR, OnIf101IntrEmulator)
ON_BN_CLICKED(IDC_IF101_SETTING, OnIf101Setting)
ON_BN_CLICKED(IDC_IF101_INTR_ENABLE, OnIf101IntrEnable)
ON_BN_CLICKED(IDC_IF101_INTR_DISABLE, OnIf101IntrDisable)
ON_BN_CLICKED(IDC_LGC3_ST, OnLgc3St)
ON_BN_CLICKED(IDC_LGC3_SP, OnLgc3Sp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIF101DriverTestDlg message handlers
BOOL CIF101DriverTestDlg::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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
hLGC1 = NULL;
hLGC2 = NULL;
m_lgc1_sp.EnableWindow(FALSE);
m_lgc2_sp.EnableWindow(FALSE);
// TODO: Add extra initialization here
m_hIF101InterruptEvent = CreateEvent( NULL, FALSE, FALSE, TEXT("IF101INTERRUPT_RUNNING"));
return TRUE; // return TRUE unless you set the focus to a control
}
DWORD LGC1ThreadProc(
LPVOID lpParameter
)
{
CIF101DriverTestDlg *pobj = (CIF101DriverTestDlg*)lpParameter;
DWORD dwCount,BytesWriten;;
DWORD nBytestoread = 0x20000;
//TCHAR szMsg[100];
DWORD i = 0;
while(!pobj->bLGC1ThreadExit)
{
//RETAILMSG(1,(TEXT("hNNO = 0x%x\r\n"),pobj->hLGC1));
if(ReadFile(pobj->hLGC1,
(LPVOID)tLGC1Buffer,
nBytestoread,
&dwCount,
NULL))
{
pobj->m_lgc1_intr = i;
i = i++%100;
pobj->m_Lgc1_len = dwCount;
pobj->UpdateData(FALSE);
WriteFile(pobj->hLGC1_record,
tLGC1Buffer,
dwCount,
&BytesWriten,
NULL);
}
}
RETAILMSG(1,(TEXT("READ THREAD EXIT!\r\n\r\n")));
return 1;
}
DWORD LGC2ThreadProc(
LPVOID lpParameter
)
{
CIF101DriverTestDlg *pobj = (CIF101DriverTestDlg*)lpParameter;
DWORD dwCount,BytesWriten;
DWORD nBytestoread = 0x20000;
//TCHAR szMsg[100];
DWORD i = 0;
while(!pobj->bLGC2ThreadExit)
{
//RETAILMSG(1,(TEXT("hNNO = 0x%x\r\n"),pobj->hLGC2));
if(ReadFile(pobj->hLGC2,
(LPVOID)(tLGC2Buffer),
nBytestoread,
&dwCount,
NULL))
{
pobj->m_lgc2_intr = i;
i = i++%100;
pobj->m_Lgc2_len = dwCount;
pobj->UpdateData(FALSE);
WriteFile(pobj->hLGC1_record,
tLGC2Buffer,
dwCount,
&BytesWriten,
NULL);
}
}
RETAILMSG(1,(TEXT("READ THREAD EXIT!\r\n\r\n")));
return 1;
}
void CIF101DriverTestDlg::OnLgc1St()
{
// TODO: Add your control notification handler code here
TCHAR szMsg[1000];
// Open the existing file.
RETAILMSG(1,(TEXT("open\r\n")));
if(hLGC1) return;
hLGC1 = CreateFile (TEXT("LGC1:"), // Open One.txt
GENERIC_WRITE|GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
OPEN_EXISTING, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hLGC1 == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
wsprintf (szMsg, TEXT("Could not open file hLGC1:\r\n"));
RETAILMSG(1,(szMsg));
return;
}
hLGC1_record = CreateFile (TEXT("LGC1_record"), // Open One.txt
GENERIC_WRITE|GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
CREATE_ALWAYS, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hLGC1_record == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
wsprintf (szMsg, TEXT("Could not open file hLGC1_record:\r\n"));
RETAILMSG(1,(szMsg));
return;
}
bLGC1ThreadExit = FALSE;
CreateThread(NULL,0,LGC1ThreadProc,this,0,0);
m_lgc1_sp.EnableWindow(TRUE);
m_lgc1_st.EnableWindow(FALSE);
}
void CIF101DriverTestDlg::OnLgc1Sp()
{
// TODO: Add your control notification handler code here
bLGC1ThreadExit = TRUE;
if(hLGC1)
{
CloseHandle(hLGC1);
hLGC1 = NULL;
}
if(hLGC1_record)
{
CloseHandle(hLGC1_record);
hLGC1_record = NULL;
}
m_lgc1_sp.EnableWindow(FALSE);
m_lgc1_st.EnableWindow(TRUE);
}
void CIF101DriverTestDlg::OnLgc2St()
{
// TODO: Add your control notification handler code here
TCHAR szMsg[1000];
// Open the existing file.
RETAILMSG(1,(TEXT("open\r\n")));
if(hLGC2) return;
hLGC2 = CreateFile (TEXT("LGC2:"), // Open One.txt
GENERIC_WRITE|GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
OPEN_EXISTING, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hLGC2 == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
wsprintf (szMsg, TEXT("Could not open file hLGC1:\r\n"));
RETAILMSG(1,(szMsg));
return;
}
hLGC2_record = CreateFile (TEXT("LGC2_record"), // Open One.txt
GENERIC_WRITE|GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
CREATE_ALWAYS, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hLGC2_record == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
wsprintf (szMsg, TEXT("Could not open file hLGC2_record:\r\n"));
RETAILMSG(1,(szMsg));
return;
}
bLGC2ThreadExit = FALSE;
CreateThread(NULL,0,LGC2ThreadProc,this,0,0);
m_lgc2_sp.EnableWindow(TRUE);
m_lgc2_st.EnableWindow(FALSE);
}
void CIF101DriverTestDlg::OnLgc2Sp()
{
// TODO: Add your control notification handler code here
bLGC2ThreadExit = TRUE;
if(hLGC2)
{
CloseHandle(hLGC2);
hLGC2 = NULL;
}
if(hLGC2_record)
{
CloseHandle(hLGC2_record);
hLGC2_record = NULL;
}
m_lgc2_sp.EnableWindow(FALSE);
m_lgc2_st.EnableWindow(TRUE);
}
void CIF101DriverTestDlg::OnIf101IntrEmulator()
{
// TODO: Add your control notification handler code here
SetEvent(m_hIF101InterruptEvent);
}
void CIF101DriverTestDlg::OnIf101Setting()
{
// TODO: Add your control notification handler code here
CIF101Ctrl obj;
obj.DoModal();
}
void CIF101DriverTestDlg::OnOK()
{
// TODO: Add extra validation here
OnLgc2Sp();
OnLgc1Sp();
CDialog::OnOK();
}
void CIF101DriverTestDlg::OnCancel()
{
// TODO: Add extra cleanup here
OnLgc2Sp();
OnLgc1Sp();
CDialog::OnCancel();
}
#define INNO_INTR_ENABLE 0x84
#define INNO_INTR_DISABLE 0x85
void CIF101DriverTestDlg::OnIf101IntrEnable()
{
// TODO: Add your control notification handler code here
HANDLE hINNO = NULL;
TCHAR szMsg[1000];
UINT16 dwInBuffer[2] = {0};
UINT16 dwOutBuffer[2] = {0};
DWORD dwReturn = 0;
hINNO = CreateFile (L"INO1:", // Open One.txt
GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
OPEN_EXISTING, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hINNO == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
MessageBox(TEXT("INO1: Open Failed!!!"));
return ;
}
if(!DeviceIoControl(hINNO,INNO_INTR_ENABLE,dwInBuffer,1,dwOutBuffer,1,&dwReturn,NULL))
{
wsprintf (szMsg, TEXT("Could not write file INO1:"));
CloseHandle(hINNO);
return;
}
CloseHandle(hINNO);
}
void CIF101DriverTestDlg::OnIf101IntrDisable()
{
// TODO: Add your control notification handler code here
HANDLE hINNO = NULL;
TCHAR szMsg[1000];
UINT16 dwInBuffer[2] = {0};
UINT16 dwOutBuffer[2] = {0};
DWORD dwReturn = 0;
hINNO = CreateFile (L"INO1:", // Open One.txt
GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
OPEN_EXISTING, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hINNO == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
MessageBox(TEXT("INO1: Open Failed!!!"));
return ;
}
if(!DeviceIoControl(hINNO,INNO_INTR_DISABLE,dwInBuffer,1,dwOutBuffer,1,&dwReturn,NULL))
{
wsprintf (szMsg, TEXT("Could not write file INO1:"));
CloseHandle(hINNO);
return;
}
CloseHandle(hINNO);
}
DWORD LGC3ThreadProc(
LPVOID lpParameter
)
{
CIF101DriverTestDlg *pobj = (CIF101DriverTestDlg*)lpParameter;
DWORD dwCount,BytesWriten;
DWORD nBytestoread = 0x20000;
//TCHAR szMsg[100];
DWORD i = 0;
while(!pobj->bLGC3ThreadExit)
{
//RETAILMSG(1,(TEXT("hNNO = 0x%x\r\n"),pobj->hLGC2));
if(ReadFile(pobj->hLGC3,
(LPVOID)(tLGC3Buffer),
nBytestoread,
&dwCount,
NULL))
{
pobj->m_lgc3_intr = i;
i = i++%100;
pobj->m_Lgc3_len = dwCount;
pobj->UpdateData(FALSE);
WriteFile(pobj->hLGC3_record,
tLGC3Buffer,
dwCount,
&BytesWriten,
NULL);
}
}
RETAILMSG(1,(TEXT("READ THREAD EXIT!\r\n\r\n")));
return 1;
}
void CIF101DriverTestDlg::OnLgc3St()
{
// TODO: Add your control notification handler code here
TCHAR szMsg[1000];
// Open the existing file.
RETAILMSG(1,(TEXT("open\r\n")));
if(hLGC3) return;
hLGC3 = CreateFile (TEXT("LGC3:"), // Open One.txt
GENERIC_WRITE|GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
OPEN_EXISTING, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hLGC3 == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
wsprintf (szMsg, TEXT("Could not open file hLGC3:\r\n"));
RETAILMSG(1,(szMsg));
return;
}
hLGC3_record = CreateFile (TEXT("LGC3_record"), // Open One.txt
GENERIC_WRITE|GENERIC_READ, // Open for reading
0, // Do not share
NULL, // No security
CREATE_ALWAYS, // Existing file only
FILE_ATTRIBUTE_NORMAL, // Normal file
NULL); // No template file
if (hLGC3_record == INVALID_HANDLE_VALUE)
{
// Your error-handling code goes here.
wsprintf (szMsg, TEXT("Could not open file hLGC3_record:\r\n"));
RETAILMSG(1,(szMsg));
return;
}
bLGC3ThreadExit = FALSE;
CreateThread(NULL,0,LGC3ThreadProc,this,0,0);
m_lgc3_sp.EnableWindow(TRUE);
m_lgc3_st.EnableWindow(FALSE);
}
void CIF101DriverTestDlg::OnLgc3Sp()
{
// TODO: Add your control notification handler code here
bLGC3ThreadExit = TRUE;
if(hLGC3)
{
CloseHandle(hLGC3);
hLGC3 = NULL;
}
if(hLGC3_record)
{
CloseHandle(hLGC3_record);
hLGC3_record = NULL;
}
m_lgc3_sp.EnableWindow(FALSE);
m_lgc3_st.EnableWindow(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -