📄 cashcodetestdlg.cpp
字号:
// CashCodeTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CashCodeTest.h"
#include "CashCodeTestDlg.h"
#include "CashDll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef struct
{
int TO;
CListBox *List;
}ThreadParam;
UINT StartCheckThrd(LPVOID lParam);
BOOL m_thrdFlag = true;
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CCashCodeTestDlg dialog
CCashCodeTestDlg::CCashCodeTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCashCodeTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCashCodeTestDlg)
m_check1 = FALSE;
m_check2 = FALSE;
m_check5 = FALSE;
m_TimeOut = 1000;
m_phone = _T("12345678901234567890123456789012");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCashCodeTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCashCodeTestDlg)
DDX_Control(pDX, IDC_LIST1, m_List);
DDX_Control(pDX, IDC_COMBO1, m_box);
DDX_Check(pDX, IDC_CHECK1, m_check1);
DDX_Check(pDX, IDC_CHECK10, m_check2);
DDX_Check(pDX, IDC_CHECK100, m_check5);
DDX_Text(pDX, IDC_EDIT1, m_TimeOut);
DDX_Text(pDX, IDC_Phone, m_phone);
DDV_MaxChars(pDX, m_phone, 32);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCashCodeTestDlg, CDialog)
//{{AFX_MSG_MAP(CCashCodeTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_INIT, OnButtonInit)
ON_BN_CLICKED(IDC_BUTTON_CHECK, OnButtonCheck)
ON_BN_CLICKED(IDC_BUTTON_SETV, OnButtonSetv)
ON_BN_CLICKED(IDC_BUTTON_GETSTA, OnButtonGetstate)
ON_BN_CLICKED(IDC_BUTTON_CLOSE, OnButtonClose)
ON_BN_CLICKED(IDC_BUTTON_CLOSE2, OnButtonClear)
ON_BN_CLICKED(IDC_SetPhone, OnSetPhone)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCashCodeTestDlg message handlers
BOOL CCashCodeTestDlg::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
GetDlgItem(IDC_BUTTON_SETV)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_CHECK)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_GETSTA)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCashCodeTestDlg::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 CCashCodeTestDlg::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 CCashCodeTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCashCodeTestDlg::OnButtonInit()
{
// TODO: Add your control notification handler code here
CString str;
m_box.GetWindowText(str);
if (str.GetLength()==0)
{
m_List.InsertString(-1,"请选择要使用的端口号!");
m_List.InsertString(-1,"==================================");
return;
}
if (!BV_Init(atoi(str),9600))
{
m_List.InsertString(-1,"初始化端口成功!");
m_List.InsertString(-1,"==================================");
// GetDlgItem(IDC_INITPORT)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_SETV)->EnableWindow(true);
// GetDlgItem(IDC_GETSTATUS)->EnableWindow(true);
}
else
{
m_List.InsertString(-1,"初始化端口失败!");
m_List.InsertString(-1,"==================================");
// GetDlgItem(IDC_BUTTON_SETV)->EnableWindow(TRUE);
}
}
void CCashCodeTestDlg::OnButtonCheck()
{
// TODO: Add your control notification handler code here
UpdateData();
GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(FALSE);
ThreadParam *thrd = new ThreadParam;
thrd->TO = m_TimeOut;
thrd->List = &m_List;
// AfxBeginThread(StartCheckThrd,thrd);
m_thrdFlag = true;
HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartCheckThrd,thrd,0,NULL);
if (hThread == NULL)
{
AfxMessageBox("Create Thread failed!");
return;
}
m_List.InsertString(-1,"开始验钞!");
m_List.InsertString(-1,"==================================");
GetDlgItem(IDC_BUTTON_SETV)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_CHECK)->EnableWindow(FALSE);
Sleep(4000);
GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(TRUE);
}
UINT StartCheckThrd(LPVOID lParam)
{
ThreadParam *pThrdParam = (ThreadParam *)lParam;
int timeOut = pThrdParam->TO;
int money = 0;
int ret = 1001;
char strPrint[100];
while (m_thrdFlag)
{
// Sleep(200);
// if (ret != 0)
// {
ret = BV_Identify(timeOut,&money);
Sleep(200);
// }
Sleep(400);
if (money>0 && money<=100)
{
sprintf(strPrint,"接收到%d元人民币!",money);
pThrdParam->List->InsertString(-1,strPrint);
pThrdParam->List->InsertString(-1,"==================================");
money = 0;
}
}
/* BYTE index = 24;
// BYTE z1,z2;
DWORD dwStart = GetTickCount();
DWORD dwEnd = dwStart;
dwEnd = GetTickCount()-dwStart;
while (dwEnd<(DWORD)timeout)
{
dwEnd = GetTickCount()-dwStart;
Sleep(100);
PollCMD(3,&z1,&z2);
if (z1 == 0x81)
{
index = z2;
}
if(index != 24 )
{
for(int i = 0;i<24;i++)
{
if(index == i)
break;
}
*value = tab[i].iCashValue;
// return 0;
// *money = &value;
}
}
*/
return 0;
}
void CCashCodeTestDlg::OnButtonSetv()
{
// TODO: Add your control notification handler code here
int flag;
char SetValues[50] = "";
char strVal[10];
CButton* pButton = (CButton*)GetDlgItem(IDC_CHECK1);
if (flag = pButton->GetCheck())
{
strcpy(strVal,"1,");
strcat(SetValues,strVal);
}
pButton = (CButton*)GetDlgItem(IDC_CHECK2);
if (flag = pButton->GetCheck())
{
strcpy(strVal,"2,");
strcat(SetValues,strVal);
}
pButton = (CButton*)GetDlgItem(IDC_CHECK5);
if (flag = pButton->GetCheck())
{
strcpy(strVal,"5,");
strcat(SetValues,strVal);
}
pButton = (CButton*)GetDlgItem(IDC_CHECK10);
if (flag = pButton->GetCheck())
{
strcpy(strVal,"10,");
strcat(SetValues,"10,");
}
pButton = (CButton*)GetDlgItem(IDC_CHECK20);
if (flag = pButton->GetCheck())
{
strcpy(strVal,"20,");
strcat(SetValues,"20,");
}
pButton = (CButton*)GetDlgItem(IDC_CHECK50);
if (flag = pButton->GetCheck())
{
strcpy(strVal,"50,");
strcat(SetValues,"50,");
}
pButton = (CButton*)GetDlgItem(IDC_CHECK100);
if (flag = pButton->GetCheck())
{
strcpy(strVal,"100,");
strcat(SetValues,"100");
}
if (strlen(SetValues) == 0)
{
strcat(SetValues,"1,2,5,10,20,50,100");
}
if (strlen(SetValues)<18)
{
SetValues[strlen(SetValues)-1] = '\0';
}
int a = BV_SetBillList(SetValues);
Sleep(500);
if (a != 0)
{
m_List.InsertString(-1,"币值设置失败!");
m_List.InsertString(-1,"==================================");
return;
}
char strPrint[100] = "当前可识别人民币币值为:";
strcat(strPrint,SetValues);
m_List.InsertString(-1,strPrint);
m_List.InsertString(-1,"==================================");
GetDlgItem(IDC_BUTTON_CHECK)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_GETSTA)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(TRUE);
}
void CCashCodeTestDlg::OnButtonGetstate()
{
// TODO: Add your control notification handler code here
int a = BV_GetStatus();
if (a == 1009)
{
m_List.InsertString(-1,"卡钞!");
m_List.InsertString(-1,"==================================");
}
if (a == 1008)
{
m_List.InsertString(-1,"钞箱满!");
m_List.InsertString(-1,"==================================");
}
if (a == 1004)
{
m_List.InsertString(-1,"假币!");
m_List.InsertString(-1,"==================================");
}
if (a == 1000)
{
m_List.InsertString(-1,"识币器故障!");
m_List.InsertString(-1,"==================================");
}
if (a == 0||a == 1)
{
m_List.InsertString(-1,"识币器正常!");
m_List.InsertString(-1,"==================================");
}
}
void CCashCodeTestDlg::OnButtonClose()
{
// TODO: Add your control notification handler code here
m_thrdFlag = false;
// Sleep(1000);
int ret = BV_Close();
if (ret != 0)
{
m_List.InsertString(-1,"识币器关闭失败!");
m_List.InsertString(-1,"==================================");
}
else
{
m_List.InsertString(-1,"识币器关闭成功!");
m_List.InsertString(-1,"==================================");
GetDlgItem(IDC_BUTTON_SETV)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_CHECK)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_GETSTA)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_CLOSE)->EnableWindow(FALSE);
}
// GetDlgItem(IDC_BUTTON_SETV)->EnableWindow(TRUE);
}
void CCashCodeTestDlg::OnButtonClear()
{
// TODO: Add your control notification handler code here
m_List.ResetContent();
}
void CCashCodeTestDlg::OnSetPhone()
{
// TODO: Add your control notification handler code here
UpdateData(1);
int ret;
//char tt[32] = "2345678123456781234567812345678";
char tt[50] = {0};
strcpy(tt,m_phone);
ret = BV_SetPhone(tt);
if(ret != 0) m_List.AddString("设置用户号出错");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -