
// CounterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CounterCallback.h"
#include "CounterDlg.h"
#include "EventDlg.h"
#include "ModeDlg.h"
#include "NotifyDlg.h"
#include "afxdialogex.h"

// Counter header
#include "CCnt.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

//---------------------------------------------------------
// Global variable
//---------------------------------------------------------
short				ChannelNum;					// Total number of channels
short int			Id;							// Device ID
DWORD				CountMatch[CHANNEL_NUM];	// Count match times
HWND				hMainWnd;
static CCounterDlg	*DlgPtr;

// CCounterDlg dialog



CCounterDlg::CCounterDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CCounterDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCounterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_COUNT_STATUS_3, m_CountStatus3);
	DDX_Control(pDX, IDC_EDIT_COUNT_STATUS_2, m_CountStatus2);
	DDX_Control(pDX, IDC_EDIT_COUNT_STATUS_1, m_CountStatus1);
	DDX_Control(pDX, IDC_EDIT_COUNT_STATUS_0, m_CountStatus0);
	DDX_Control(pDX, IDC_EDIT_COUNT_VALUE_3, m_CountValue3);
	DDX_Control(pDX, IDC_EDIT_COUNT_VALUE_2, m_CountValue2);
	DDX_Control(pDX, IDC_EDIT_COUNT_VALUE_1, m_CountValue1);
	DDX_Control(pDX, IDC_EDIT_COUNT_VALUE_0, m_CountValue0);
	DDX_Control(pDX, IDC_EDIT_DEV_NAME, m_DeviceName);
	DDX_Control(pDX, IDC_STATIC_NOTIFY, m_Notify);
	DDX_Control(pDX, IDC_EDIT_RET, m_Ret);
}

BEGIN_MESSAGE_MAP(CCounterDlg, CDialogEx)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_CNTINIT, &CCounterDlg::OnBnClickedButtonCntinit)
	ON_BN_CLICKED(IDC_BUTTON_CNTMODE, &CCounterDlg::OnBnClickedButtonCntmode)
	ON_BN_CLICKED(IDC_BUTTON_CNTNOTIFY, &CCounterDlg::OnBnClickedButtonCntnotify)
	ON_BN_CLICKED(IDC_BUTTON_CNTEVENT, &CCounterDlg::OnBnClickedButtonCntevent)
	ON_BN_CLICKED(IDC_BUTTON_CNTSTART, &CCounterDlg::OnBnClickedButtonCntstart)
	ON_BN_CLICKED(IDC_BUTTON_CNTPRESET, &CCounterDlg::OnBnClickedButtonCntpreset)
	ON_BN_CLICKED(IDC_BUTTON_CNTRESET, &CCounterDlg::OnBnClickedButtonCntreset)
	ON_BN_CLICKED(IDC_BUTTON_CNTSTOP, &CCounterDlg::OnBnClickedButtonCntstop)
	ON_BN_CLICKED(IDC_BUTTON_CNTEXIT, &CCounterDlg::OnBnClickedButtonCntexit)
	ON_BN_CLICKED(IDC_BUTTON_EXIT, &CCounterDlg::OnBnClickedButtonExit)
END_MESSAGE_MAP()


// CCounterDlg message handlers

//===================================================
// Dialog initialization
//===================================================
BOOL CCounterDlg::OnInitDialog()
{
	CDialogEx::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

	short	i;
	//-----------------------------------
	// Control array settings
	//-----------------------------------
	//------------------
	// Count value control
	//------------------
	m_Count[0]	= &m_CountValue0;
	m_Count[1]	= &m_CountValue1;
	m_Count[2]	= &m_CountValue2;
	m_Count[3]	= &m_CountValue3;
	//------------------
	// Count status control
	//------------------
	m_Status[0]	= &m_CountStatus0;
	m_Status[1]	= &m_CountStatus1;
	m_Status[2]	= &m_CountStatus2;
	m_Status[3]	= &m_CountStatus3;
	//-----------------------------------
	// Initialize dialog display
	//-----------------------------------
	m_DeviceName.SetWindowText(_T("CNT000"));
	//-----------------------------------
	// For each channel
	//-----------------------------------
	for(i = 0; i < CHANNEL_NUM; i++){
		//------------------
		// Count value control
		//------------------
		m_Count[i]->SetWindowText(_T(""));
		//------------------
		// Count status control
		//------------------
		m_Status[i]->SetWindowText(_T(""));
	}
	//-----------------------------------
	// Initializing Parameters
	//-----------------------------------
	ChannelNum	= CHANNEL_NUM;
	//-----------------------------------
	// Copy window's handle
	//-----------------------------------
	hMainWnd = m_hWnd;

	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 CCounterDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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
	{
		CDialogEx::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CCounterDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


//---------------------------------------------
// CntInit()
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntinit()
{
	CString	str;
	char	buf[100], error_string[256];
	TCHAR	szbuf[100], szError_string[256];
	long	ret;
	short	i;

	//-----------------------------------
	// Get device name
	//-----------------------------------
	m_DeviceName.GetWindowText(szbuf, sizeof(szbuf));
	sprintf_s(buf, "%S", szbuf);

	//------------------------------
	// Initialization
	//------------------------------
	ret = CntInit(buf, &Id);
	CntGetErrorString(ret, error_string);
	wsprintf(szError_string, _T("%S"), error_string);
	str.Format(_T("CntInit ret = %d: %s"), ret, szError_string);
	m_Ret.SetWindowText(str);
	
	if(ret != CNT_ERR_SUCCESS){
		return;
	}
	//-----------------------------
	// Get number of channels
	//-----------------------------
	CntGetMaxChannels(Id, &ChannelNum);
	//-----------------------------
	// If the sample control count is exceeded, 
	// the total channel count is corrected to the control count.
	//-----------------------------
	if(ChannelNum > CHANNEL_NUM){
		ChannelNum	= CHANNEL_NUM;
	}
	//-----------------------------
	// Toggles the count value and status display according to the total number of channels.
	//-----------------------------
	for(i = 0; i < CHANNEL_NUM; i++){
		//-----------------------------
		// Disables the display when the number of loops exceeds the total number of channels.
		//-----------------------------
		if(i >= ChannelNum){
			m_Count[i]->EnableWindow(FALSE);
			m_Status[i]->EnableWindow(FALSE);
		//-----------------------------
		// Enables the display when the number of loops is less than or equal to the total number of channels.
		//-----------------------------
		}else{
			m_Count[i]->EnableWindow(TRUE);
			m_Status[i]->EnableWindow(TRUE);
		}
	}
}

//---------------------------------------------
// Display "Counter Mode Setting" dialog
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntmode()
{
	//------------------------------
	// Display "Counter Mode Setting" dialog
	//------------------------------
	CModeDlg	dlg;
	dlg.DoModal();
}

//---------------------------------------------
// Display "Notification Setting" dialog
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntnotify()
{
	//------------------------------
	// Display "Notification Setting" dialog
	//------------------------------
	CNotifyDlg	dlg;
	dlg.DoModal();
}

//---------------------------------------------
// Display "Event Setting" dialog
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntevent()
{
	//------------------------------
	// Display "Event Setting" dialog
	//------------------------------
	CEventDlg	dlg;
	dlg.DoModal();
}

//---------------------------------------------
// Start count
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntstart()
{
	CString		str;
	char		error_string[256];
	TCHAR		szError_string[256];
	long		ret;
	short		ChNo[CHANNEL_NUM];
	short		i;

	//-----------------------------
	// Callback rountine
	//-----------------------------
	// Count match
	ret = CntCountUpCallbackProc(Id, SetCountUpCallBackProc, this);
	/*
	//-----------------------------
	// The error check is commented out for devices that do not have the event notification function
	// If you need the error check, uncomment it
	//-----------------------------
	if (ret != 0){
		CntGetErrorString(ret, error_string);
		wsprintf(szError_string, _T("%S"), error_string);
		str.Format(_T("CntSetCountUpCallbackProc ret = %d: %s"), ret, szError_string);
		m_Ret.SetWindowText(str);
		return;
	}
	*/
	// Counter error
	ret = CntCounterErrorCallbackProc(Id, CounterErrorCallBackProc, this);
	/*
	//-----------------------------
	// The error check is commented out for devices that do not have the event notification function
	// If you need the error check, uncomment it
	//-----------------------------
	if (ret != 0){
		CntGetErrorString(ret, error_string);
		wsprintf(szError_string, _T("%S"), error_string);
		str.Format(_T("CntSetCounterErrorCallbackProc ret = %d: %s"), ret, szError_string);
		m_Ret.SetWindowText(str);
		return;
	}
	*/
	// Carry/Borrow error
	ret = CntCarryBorrowCallbackProc(Id, CarryBorrowCallBackProc, this);
	/*
	//-----------------------------
	// The error check is commented out for devices that do not have the event notification function
	// If you need the error check, uncomment it
	//-----------------------------
	if (ret != 0){
		CntGetErrorString(ret, error_string);
		wsprintf(szError_string, _T("%S"), error_string);
		str.Format(_T("CntCarryBorrowCallbackProc ret = %d: %s"), ret, szError_string);
		m_Ret.SetWindowText(str);
		return;
	}
	*/
	/*
	//---------------------------------------------------------
	//  When using the timer notification event of device,
	//  please use the following function.
	//---------------------------------------------------------
	// Timer notification
	ret = CntTimerCallbackProc(Id, TimerCallBackProc, this);
	if (ret != 0){
		CntGetErrorString(ret, error_string);
		wsprintf(szError_string, _T("%S"), error_string);
		str.Format(_T("CntTimerCallbackProc ret = %d: %s"), ret, szError_string);
		m_Ret.SetWindowText(str);
		return;
	}
	*/

	//------------------------------
	// Set parameter
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		ChNo[i] = i;
	}

	//------------------------------
	// Start count
	//------------------------------
	ret = CntStartCount(Id, &ChNo[0], ChannelNum);
	CntGetErrorString(ret, error_string);
	wsprintf(szError_string, _T("%S"), error_string);
	str.Format(_T("CntStartCount ret = %d: %s"), ret, szError_string);
	m_Ret.SetWindowText(str);
	if (ret == 0) {
		//------------------------------
		// Consider a device that does not have a timer notification function,
		// we use the window timer.
		// Please switch and use, according to the use.
		//------------------------------
		//------------------------------
		// Start timer
		//------------------------------
		DlgPtr = this;
		DlgPtr->SetTimer((UINT_PTR)this, 100, TimerCallBackProc);
		//------------------------------
		// When using the timer notification event of device,
		// please use the following function.
		//------------------------------
		//CntNotifyTimer(Id, 100, m_hWnd);
	}
}

//---------------------------------------------
// Preset counter
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntpreset()
{
	CString			str;
	char			error_string[256];
	TCHAR			szError_string[256];
	long			ret;
	short			ChNo[CHANNEL_NUM];
	unsigned long	PresetData[CHANNEL_NUM];
	short			i;

	//------------------------------
	// Set preset value
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		ChNo[i] = i;
		PresetData[i] = i * 100;
	}
	//------------------------------
	// Preset setting processing
	//------------------------------
	ret = CntPreset(Id, &ChNo[0], ChannelNum, &PresetData[0]);
	CntGetErrorString(ret, error_string);
	wsprintf(szError_string, _T("%S"), error_string);
	str.Format(_T("CntPreset ret = %d: %s"), ret, szError_string);
	m_Ret.SetWindowText(str);
}

//---------------------------------------------
// Reset counter
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntreset()
{
	CString		str;
	char		error_string[256];
	TCHAR		szError_string[256];
	long		ret;
	short		ChNo[CHANNEL_NUM];
	short		i;

	//------------------------------
	// Set parameter
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		ChNo[i] = i;
	}

	//------------------------------
	// Reset counter
	//------------------------------
	ret = CntZeroClearCount(Id, &ChNo[0], ChannelNum);
	CntGetErrorString(ret, error_string);
	wsprintf(szError_string, _T("%S"), error_string);
	str.Format(_T("CntZeroClearCount ret = %d: %s"), ret, szError_string);
	m_Ret.SetWindowText(str);
}

//---------------------------------------------
// Stop count
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntstop()
{
	CString		str;
	char		error_string[256];
	TCHAR		szError_string[256];
	long		ret;
	short		ChNo[CHANNEL_NUM];
	short		i;

	//------------------------------
	// Set parameter
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		ChNo[i] = i;
	}

	//------------------------------
	// Stop count
	//------------------------------
	ret = CntStopCount(Id, &ChNo[0], ChannelNum);
	CntGetErrorString(ret, error_string);
	wsprintf(szError_string, _T("%S"), error_string);
	str.Format(_T("CntStopCount ret = %d: %s"), ret, szError_string);
	m_Ret.SetWindowText(str);

	//------------------------------
	// Consider a device that does not have a timer notification function,
	// we use the window timer.
	// Please switch and use, according to the use.
	//------------------------------
	//------------------------------
	// Stop timer
	//------------------------------
	KillTimer((UINT_PTR)this);
	//------------------------------
	// When using the timer notification event of device,
	// please use the following function.
	//------------------------------
	//CntStopNotifyTimer(Id);
}

//---------------------------------------------
// CntExit()
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonCntexit()
{
	CString		str;
	char		error_string[256];
	TCHAR		szError_string[256];
	long		ret;

	//------------------------------
	// Consider a device that does not have a timer notification function,
	// we use the window timer.
	// Please switch and use, according to the use.
	//------------------------------
	//------------------------------
	// Stop timer
	//------------------------------
	KillTimer((UINT_PTR)this);
	//------------------------------
	// When using the timer notification event of device,
	// please use the following function.
	//------------------------------
	//CntStopNotifyTimer(Id);
	
	//------------------------------
	// Counter termination processing
	//------------------------------
	ret = CntExit(Id);
	CntGetErrorString(ret, error_string);
	wsprintf(szError_string, _T("%S"), error_string);
	str.Format(_T("CntExit ret = %d: %s"), ret, szError_string);
	m_Ret.SetWindowText(str);
}

//---------------------------------------------
// Exit sample program
//---------------------------------------------
void CCounterDlg::OnBnClickedButtonExit()
{
	long		ret;

	//------------------------------
	// Consider a device that does not have a timer notification function,
	// we use the window timer.
	// Please switch and use, according to the use.
	//------------------------------
	//------------------------------
	// Stop timer
	//------------------------------
	KillTimer((UINT_PTR)this);
	//------------------------------
	// When using the timer notification event of device,
	// please use the following function.
	//------------------------------
	//CntStopNotifyTimer(Id);

	//------------------------------
	// Counter termination processing
	//------------------------------
	ret = CntExit(Id);
	CDialogEx::OnOK();
}

//---------------------------------------------------------
// Callback routine
//---------------------------------------------------------
void CCounterDlg::SetCountUpCallBackProc(short Id, WPARAM wParam, LPARAM lParam, void *Param)
{
	// Calss object
	CCounterDlg		*dlg;
	CString			str;

	dlg = (CCounterDlg *)Param;

	switch (LOWORD(wParam)){
	case 0:	// Count match: 0CH
		CountMatch[0]++;
		if (HIWORD(wParam) == 1){
			str.Format(_T("Count Match! Channel No.: 0, UP, \nCount: %08X(Hex) Matched: %lu times"), lParam, CountMatch[0]);
		}
		else{
			str.Format(_T("Count Match! Channel No.: 0, DOWN, \nCount: %08X(Hex) Matched: %lu times"), lParam, CountMatch[0]);
		}
		dlg->m_Notify.SetWindowText(str);
		break;
	case 1:	// Count match: 1CH
		CountMatch[1]++;
		if (HIWORD(wParam) == 1){
			str.Format(_T("Count Match! Channel No.: 1, UP, \nCount: %08X(Hex) Matched: %lu times"), lParam, CountMatch[1]);
		}
		else{
			str.Format(_T("Count Match! Channel No.: 1, DOWN, \nCount: %08X(Hex) Matched: %lu times"), lParam, CountMatch[1]);
		}
		dlg->m_Notify.SetWindowText(str);
		break;
	case 2:	// Count match: 2CH
		CountMatch[2]++;
		if (HIWORD(wParam) == 1){
			str.Format(_T("Count Match! Channel No.: 2, UP, \nCount: %08X(Hex) Matched: %lu times"), lParam, CountMatch[2]);
		}
		else{
			str.Format(_T("Count Match! Channel No.: 2, DOWN, \nCount: %08X(Hex) Matched: %lu times"), lParam, CountMatch[2]);
		}
		dlg->m_Notify.SetWindowText(str);
		break;
	case 3:	// Count match: 3CH
		CountMatch[3]++;
		if (HIWORD(wParam) == 1){
			str.Format(_T("Count Match! Channel No.: 3, UP, \nCount: %08X(Hex) Matched: %lu times"), lParam, CountMatch[3]);
		}
		else{
			str.Format(_T("Count Match! Channel No.: 3, DOWN, \nCount: %08X(Hex) Matched: %lu times"), lParam, CountMatch[3]);
		}
		dlg->m_Notify.SetWindowText(str);
		break;
	}
}

void CCounterDlg::CounterErrorCallBackProc(short Id, WPARAM wParam, LPARAM lParam, void *Param)
{
	// Calss object
	CCounterDlg		*dlg;
	CString			str;

	dlg = (CCounterDlg *)Param;

	switch (LOWORD(lParam)){
	case CNT_AI_ERROR:		// Abnormal input
		str.Format(_T("Abnormal input error! Channel No.: %d"), LOWORD(wParam));
		dlg->m_Notify.SetWindowText(str);
		break;
	case CNT_FLT_ERROR:		// Filter
		str.Format(_T("Filter error! Channel No.: %d"), LOWORD(wParam));
		dlg->m_Notify.SetWindowText(str);
		break;
	case CNT_ALM_ERROR:		// Alarm
		str.Format(_T("Alarm error! Channel No.: %d"), LOWORD(wParam));
		dlg->m_Notify.SetWindowText(str);
		break;
	}
}

void CCounterDlg::CarryBorrowCallBackProc(short Id, WPARAM wParam, LPARAM lParam, void *Param)
{
	// Calss object
	CCounterDlg		*dlg;
	CString			str;

	dlg = (CCounterDlg *)Param;

	switch (LOWORD(lParam)){
	case CNT_CB_CARRY:		// Carry
		str.Format(_T("Carry! Channel No.: %d"), LOWORD(wParam));
		dlg->m_Notify.SetWindowText(str);
		break;
	case CNT_CB_BORROW:		// Borrow
		str.Format(_T("Borrow! Channel No.: %d"), LOWORD(wParam));
		dlg->m_Notify.SetWindowText(str);
		break;
	}
}

//---------------------------------------------------------
// Consider a device that does not have a timer notification function,
// we use the window timer.
// Please switch and use, according to the use.
//---------------------------------------------------------
//---------------------------------------------------------
// Callback routine for window timer
//---------------------------------------------------------
void CALLBACK CCounterDlg::TimerCallBackProc(HWND TIMERhnd, UINT wParam, UINT_PTR nIDEvent, DWORD dwTime)
{
	short			ChNo[CHANNEL_NUM];
	unsigned long	CntData[CHANNEL_NUM];
	unsigned long	StatusData[CHANNEL_NUM];
	short			i;
	long			ret;
	CString			str;
	char			error_string[256];
	TCHAR			szError_string[256];

	//------------------------------
	// Set parameter
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		ChNo[i]			= i;
		CntData[i]		= 0;
		StatusData[i]	= 0;
	}
	//------------------------------
	// Get count value
	//------------------------------
	ret = CntReadCount(Id, &ChNo[0], ChannelNum, &CntData[0]);
	if (ret != 0) {
		CntGetErrorString(ret, error_string);
		wsprintf(szError_string, _T("%S"), error_string);
		str.Format(_T("CntReadCnt ret = %d: %s"), ret, szError_string);
		DlgPtr->m_Ret.SetWindowText(str);
		DlgPtr->KillTimer((UINT_PTR)DlgPtr);
	}
	//------------------------------
	// Get count status
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		ret = CntReadStatusEx(Id, i, &StatusData[i]);
		if (ret != 0) {
			CntGetErrorString(ret, error_string);
			wsprintf(szError_string, _T("%S"), error_string);
			str.Format(_T("CntReadStatus ret = %d: %s"), ret, szError_string);
			DlgPtr->m_Ret.SetWindowText(str);
			DlgPtr->KillTimer((UINT_PTR)DlgPtr);
		}
	}
	//------------------------------
	// Display data
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		str.Format(_T("%lu\n"), CntData[i]);
		DlgPtr->m_Count[i]->SetWindowText(str);
		str.Format(_T("%08XH\n"), StatusData[i]);
		DlgPtr->m_Status[i]->SetWindowText(str);
	}
}

/*
//---------------------------------------------------------
// When using the timer notification event of device,
// please use the following callback routine.
//---------------------------------------------------------
//---------------------------------------------------------
// Callback routine for timer notification
//---------------------------------------------------------
void CCounterDlg::TimerCallBackProc(short Id, WPARAM wParam, LPARAM lParam, void *Param)
{
	short			ChNo[CHANNEL_NUM];
	unsigned long	CntData[CHANNEL_NUM];
	unsigned long	StatusData[CHANNEL_NUM];
	short			i;
	long			ret;
	CString			str;
	char			error_string[256];
	TCHAR			szError_string[256];
	// Class object
	CCounterDlg		*dlg;

	dlg = (CCounterDlg *)Param;

	//------------------------------
	// Set parameter
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		ChNo[i]			= i;
		CntData[i]		= 0;
		StatusData[i]	= 0;
	}
	//------------------------------
	// Get count value
	//------------------------------
	ret = CntReadCount(Id, &ChNo[0], ChannelNum, &CntData[0]);
	if (ret != 0) {
		CntGetErrorString(ret, error_string);
		wsprintf(szError_string, _T("%S"), error_string);
		str.Format(_T("CntReadCnt ret = %d: %s"), ret, szError_string);
		dlg->m_Ret.SetWindowText(str);
		CntStopNotifyTimer(Id);
	}
	//------------------------------
	// Get count status
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		ret = CntReadStatusEx(Id, i, &StatusData[i]);
		if (ret != 0) {
			CntGetErrorString(ret, error_string);
			wsprintf(szError_string, _T("%S"), error_string);
			str.Format(_T("CntReadStatus ret = %d: %s"), ret, szError_string);
			dlg->m_Ret.SetWindowText(str);
			CntStopNotifyTimer(Id);
		}
	}
	//------------------------------
	// Display data
	//------------------------------
	for (i = 0; i<ChannelNum; i++) {
		str.Format(_T("%lu\n"), CntData[i]);
		m_Count[i]->SetWindowText(str);
		str.Format(_T("%08XH\n"), StatusData[i]);
		m_Status[i]->SetWindowText(str);
	}
}
*/
