// 8048Dlg.cpp : implementation file // #include "stdafx.h" #include "8048.h" #include "8048Dlg.h" #include "XPacSDK_CE.h" #include "pac_i8048W.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CMy8048Dlg dialog CMy8048Dlg::CMy8048Dlg(CWnd* pParent /*=NULL*/) : CDialog(CMy8048Dlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMy8048Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CMy8048Dlg, CDialog) #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) ON_WM_SIZE() #endif //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON1, &CMy8048Dlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CMy8048Dlg::OnBnClickedButton2) ON_WM_TIMER() END_MESSAGE_MAP() // CMy8048Dlg message handlers int previousSlot; BOOL CMy8048Dlg::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 previousSlot=-1; // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP) void CMy8048Dlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/) { if (AfxIsDRAEnabled()) { DRA::RelayoutDialog( AfxGetResourceHandle(), this->m_hWnd, DRA::GetDisplayMode() != DRA::Portrait ? MAKEINTRESOURCE(IDD_MY8048_DIALOG_WIDE) : MAKEINTRESOURCE(IDD_MY8048_DIALOG)); } } #endif int channelNumber =0; int slotNumber =0; int Amount=0; int rec[8],fec[8]; int tSecond =0; unsigned int SlotAddr[]={ 0x2000, 0x2800, 0x3000, 0x3800, 0x4000, 0x4800, 0x5000, 0x5800 }; int CALLBACK BackData(){ int temp = 0; if(pac_i8048W_Read_RisingReg(slotNumber,channelNumber)){ rec[channelNumber]++; } if(pac_i8048W_Read_FallingReg(slotNumber,channelNumber)){ fec[channelNumber]++; } Amount++; //pac_i8048W_UnFreezeINT(slotNumber,channelNumber); _pac_outp(SlotAddr[slotNumber] + channelNumber*1, 0); return 1; } void CMy8048Dlg::OnBnClickedButton1() { // TODO: Add your control notification handler code here TCHAR strTemp[100]={0}; int typeNumber =0; int ret =0; int i; GetDlgItemText(IDC_COMBO1,strTemp,100); slotNumber = _wtoi(strTemp); GetDlgItemText(IDC_COMBO2,strTemp,100); channelNumber = _wtoi(strTemp); GetDlgItemText(IDC_COMBO3,strTemp,100); typeNumber = _wtoi(strTemp); //printf("slot:%d, Ch:%d, type:%d\r\n",slotNumber,channelNumber,typeNumber); if(previousSlot>0) pac_UnregisterSlotInterrupt(previousSlot); PAC_OUTP(0x7006,1); //retrigger unit 50us ret = pac_i8048W_Init(slotNumber); //printf("ret = %d\n",ret); if(!ret){ if(typeNumber==0){ pac_i8048W_Set_RisingReg(slotNumber,channelNumber,1); pac_i8048W_Set_FallingReg(slotNumber,channelNumber,0); }else{ pac_i8048W_Set_FallingReg(slotNumber,channelNumber,1); pac_i8048W_Set_RisingReg(slotNumber,channelNumber,0); } Sleep(10); pac_i8048W_InstallISR(slotNumber,BackData,80); previousSlot=slotNumber; } Sleep(10); SetTimer(1,200,NULL); OnBnClickedButton2(); } void CMy8048Dlg::OnBnClickedButton2() { // TODO: Add your control notification handler code here tSecond=0; Amount =0; rec[channelNumber]=0; fec[channelNumber]=0; } void CMy8048Dlg::OnTimer(UINT_PTR nIDEvent) { // TODO: Add your message handler code here and/or call default WCHAR BUF[100]; BYTE byteData = 0; tSecond++; byteData = pac_i8048W_DI_ALL(slotNumber); swprintf(BUF,L"ch%d = %d",channelNumber,rec[channelNumber]); SetDlgItemText(IDC_EDIT2,BUF); swprintf(BUF,L"ch%d = %d",channelNumber,fec[channelNumber]); SetDlgItemText(IDC_EDIT3,BUF); //printf("Second: %d\n",tSecond); CDialog::OnTimer(nIDEvent); }