1758di_intdlg.cpp
来自「16 relay output channels and 16 isolated」· C++ 代码 · 共 655 行 · 第 1/2 页
CPP
655 行
// 1758DI_INTDlg.cpp : implementation file
//
#include "stdafx.h"
#include <process.h>
#include "1758DI_INT.h"
#include "1758DI_INTDlg.h"
#include "DISettingDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef struct _PT_ThreadArg
{
LONG m_lDriverHandle;
HWND m_hWnd;
// PT_CheckEvent ptCheckEvent;
} PT_ThreadArg, * LPT_ThreadArg;
static PT_ThreadArg ptThreadArg;
static USHORT usStartFlag;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// C1758DI_INTDlg dialog
C1758DI_INTDlg::C1758DI_INTDlg(CWnd* pParent /*=NULL*/)
: CDialog(C1758DI_INTDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(C1758DI_INTDlg)
m_dwScanTime = 200;
m_uChannel = 0;
m_FilterCounter = 0;
m_DriverHandle=0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_DriverHandle = (LONG)NULL; // driver handle
m_bContinue = FALSE;
m_bFlag = FALSE;
// m_StartFlag = 0;
}
void C1758DI_INTDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(C1758DI_INTDlg)
DDX_Control(pDX, IDC_StartScan, m_StartScan);
DDX_Control(pDX, IDC_StopScan, m_StopScan);
DDX_Control(pDX, IDC_STOPBTN, m_StopBtn);
DDX_Control(pDX, IDC_PortCOMBO, m_PortCom);
DDX_Control(pDX, IDC_InterruptList, m_InterruptList);
DDX_Control(pDX, IDC_SCANDATA, m_ScanData);
DDX_Control(pDX, IDC_DEVICENAME, m_DeviceName);
DDX_Control(pDX, IDC_SELECTDEVICE, m_SelectDevice);
DDX_Text(pDX, IDC_SCANTIME, m_dwScanTime);
DDX_Text(pDX, IDC_FilterCounter, m_FilterCounter);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(C1758DI_INTDlg, CDialog)
//{{AFX_MSG_MAP(C1758DI_INTDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SetRisingBtn, OnSetRisingBtn)
ON_BN_CLICKED(IDC_SetFallingBtn, OnSetFallingBtn)
ON_BN_CLICKED(IDC_SetFilterBtn, OnSetFilterBtn)
ON_BN_CLICKED(IDC_SELECTDEVICE, OnSelectdevice)
ON_BN_CLICKED(IDC_StartScan, OnStartScan)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_StopScan, OnStopScan)
ON_EN_CHANGE(IDC_FilterCounter, OnChangeFilterCounter)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_InterruptList, OnItemchangedInterruptList)
ON_BN_CLICKED(IDC_STOPBTN, OnStopbtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// C1758DI_INTDlg message handlers
BOOL C1758DI_INTDlg::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);
if (pSysMenu != NULL)
{
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
m_InterruptList.SetExtendedStyle( m_InterruptList.GetExtendedStyle()
| LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
m_InterruptList.InsertColumn(0, "Interrupt Channel", LVCFMT_CENTER, 90);
m_InterruptList.InsertColumn(1, "Trigger Mode", LVCFMT_CENTER, 140);
m_InterruptList.InsertColumn(2, "Filter", LVCFMT_CENTER, 60);
m_InterruptList.InsertColumn(3, "Event count", LVCFMT_CENTER, 80);
pThreadObject =NULL;
OnSelectdevice();
return TRUE; // return TRUE unless you set the focus to a control
}
void C1758DI_INTDlg::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 C1758DI_INTDlg::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 C1758DI_INTDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void C1758DI_INTDlg::OnSetRisingBtn()
{
// TODO: Add your control notification handler code here
CDISettingDlg dlg;
dlg.DIChanNum = m_DIChanNum;
dlg.DISetting = DIRisingTrigger;
dlg.DISettingFlag = RisingTrigger;
if ( IDOK==dlg.DoModal())
{
ULONG ulDataLength = sizeof(BYTE) *16 ;
DRV_DeviceSetProperty( m_DriverHandle, CFG_DiTriggerEnableRisingForAll, DIRisingTrigger , ulDataLength);
//or
/*
ulDataLength = sizeof(BYTE) ;
for(int i=0;i<16;i++)
DRV_DeviceSetProperty( m_DriverHandle, CFG_DiTriggerEnableRisingPort0+i,
&(DIRisingTrigger[i]) , ulDataLength);
*/
SetTrigerMode();
}
}
void C1758DI_INTDlg::SetFilter()
{
USHORT DIPort;
USHORT DIPortBit;
int nRow;
for( nRow = 0; nRow < m_DIChanNum; nRow++)
{
DIPort = nRow / 8;
DIPortBit = 1 << (nRow % 8);
if ( ( DIFilterEnable[DIPort] & DIPortBit ) )
{
m_InterruptList.SetItemText(nRow,2,"Yes");
}
else
{
m_InterruptList.SetItemText(nRow,2,"No");
}
}
}
void C1758DI_INTDlg::SetTrigerMode()
{
USHORT DIPort;
USHORT DIPortBit;
int nRow;
for( nRow = 0; nRow < m_DIChanNum; nRow++)
{
DIPort = nRow / 8;
DIPortBit = 1 << (nRow % 8);
if ( ( DIRisingTrigger[DIPort] & DIPortBit ) &&
( DIFallingTrigger[DIPort] & DIPortBit ) )
{
m_InterruptList.SetItemText(nRow,1,"Rising & Falling edge");
}
else if ( ( DIRisingTrigger[DIPort] & DIPortBit ) )
{
m_InterruptList.SetItemText(nRow,1,"Rising edge");
}
else if( ( DIFallingTrigger[DIPort] & DIPortBit ) )
{
m_InterruptList.SetItemText(nRow,1,"Falling edge");
}
else
{
m_InterruptList.SetItemText(nRow,1,"None");
}
}
}
void C1758DI_INTDlg::OnSetFallingBtn()
{
// TODO: Add your control notification handler code here
CDISettingDlg dlg;
dlg.DIChanNum = m_DIChanNum;
dlg.DISetting = DIFallingTrigger;
dlg.DISettingFlag = FallingTrigger;
if ( IDOK==dlg.DoModal())
{
ULONG ulDataLength = sizeof(BYTE) *16 ;
DRV_DeviceSetProperty( m_DriverHandle, CFG_DiTriggerEnableFallingForAll, DIFallingTrigger , ulDataLength);
//or
/*
ulDataLength = sizeof(BYTE) ;
for(int i=0;i<16;i++)
DRV_DeviceSetProperty( m_DriverHandle, CFG_DiTriggerEnableFallingPort0+i,
&(DIFallingTrigger[i]) , ulDataLength);
*/
SetTrigerMode();
}
}
void C1758DI_INTDlg::OnSetFilterBtn()
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?