?? usbiicrwdlg.cpp
字號:
/*
//*************************************************************************
//
// P H I L I P S P R O P R I E T A R Y
//
// COPYRIGHT (c) 1998 BY PHILIPS SINGAPORE.
// -- ALL RIGHTS RESERVED --
//
// File Name: UsbIICRWDlg.CPP
// Author: Wenkai Du
// Created: 14 Jan 98
// Modified:
// Revision: 1.4
//
//*************************************************************************
//
//*************************************************************************
*/
// UsbIICRWDlg.cpp : implementation file
//
#include "stdafx.h"
#include <mmsystem.h>
#include "UsbIICRW.h"
#include "UsbIICRWDlg.h"
#include <devioctl.h>
#include "process.h"
#include "EasyD12.H"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
UINT KillDialog(void * pParam)
{
struct CKillDialogParam * killParam;
struct CThreadParam * threadParam;
CUsbIICRWDlg* testDlg;
int i;
killParam = (struct CKillDialogParam *)pParam;
for(i = 0; i < 3; i ++)
{
threadParam=(struct CThreadParam *)(killParam->tp[i]);
if(threadParam->bInThread != FALSE)
{
threadParam->bInThread = FALSE;
WaitForSingleObject(threadParam->hThread, INFINITE);
}
}
testDlg = killParam->testDlg;
testDlg -> EndDialog(0);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CUsbIICRWDlg dialog
CUsbIICRWDlg::CUsbIICRWDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUsbIICRWDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUsbIICRWDlg)
m_strDown = _T("");
m_strUp = _T("");
m_strSendAdr = _T("");
m_strSendLen = _T("");
m_strRevLen = _T("");
m_strRevAdr = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
// m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
}
CUsbIICRWDlg::~CUsbIICRWDlg()
{
}
void CUsbIICRWDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUsbIICRWDlg)
DDX_Control(pDX, IDC_CBO_ATMEL, m_CboATMEL);
DDX_Text(pDX, IDC_EDITDOWN, m_strDown);
DDX_Text(pDX, IDC_EDITUP, m_strUp);
DDX_Text(pDX, IDC_EDIT_SENDADR, m_strSendAdr);
DDX_Text(pDX, IDC_EDIT_SENDLEN, m_strSendLen);
DDX_Text(pDX, IDC_EDIT_REVLEN, m_strRevLen);
DDX_Text(pDX, IDC_EDIT_REVADR, m_strRevAdr);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUsbIICRWDlg, CDialog)
//{{AFX_MSG_MAP(CUsbIICRWDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTONDOWN, OnButtondown)
ON_BN_CLICKED(IDC_BUTTONUP, OnButtonup)
ON_CBN_SELCHANGE(IDC_CBO_ATMEL, OnSelchangeCboAtmel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUsbIICRWDlg message handlers
BOOL CUsbIICRWDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
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_CboATMEL.SetCurSel(0);
m_CurrentCardName="AT24C01A";
m_CurrentCardType=CARD_AT24C01A;
SetTimer(1, 500, 0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CUsbIICRWDlg::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 CUsbIICRWDlg::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 CUsbIICRWDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CUsbIICRWDlg::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
KillTimer(1);
return CDialog::DestroyWindow();
}
/*
void CUsbIICRWDlg::OnCancel()
{
/* if(m_ReadWrite.bInThread == FALSE &&
m_MainWrite.bInThread == FALSE &&
m_MainRead.bInThread == FALSE)
EndDialog(0);
else
{
m_KillDialog.tp[0] = &m_ReadWrite;
m_KillDialog.tp[1] = &m_MainWrite;
m_KillDialog.tp[2] = &m_MainRead;
m_KillDialog.testDlg = this;
AfxBeginThread(
KillDialog, // thread function
&m_KillDialog);
}*/
//}
void CUsbIICRWDlg::OnButtondown()
{
unsigned char buf[16],buf1[16];
unsigned char OutBuf[1000];
// HANDLE hFile, hDevice=0;
ULONG nBytes = 0;
// BOOL bResult;
UpdateData(TRUE);
///////////////////////////////////////////////
out.data=atol((LPCSTR)m_strSendAdr);
type.data=m_CurrentCardType;
buf1[0]='W';
buf1[1]=type.byte[0];
buf1[2]=type.byte[1];
buf1[3]=out.byte[0];
buf1[4]=out.byte[1];
out.data=atol((LPCSTR)m_strSendLen);
buf1[5]=out.byte[0];;
buf1[6]=out.byte[1];;
buf1[7]=buf1[0]^buf1[1]^buf1[2]^buf1[3]^buf1[4]^buf1[5]^buf1[6];
if(WritePort1(buf1,8)!=0)
{
MessageBox((LPCSTR)"寫命令失敗!", "提示", MB_ICONSTOP);
return;
}
// if(WritePort1(buf1+4,4)!=0)
// {
// MessageBox((LPCSTR)"寫命令失敗!", "提示", MB_ICONSTOP);
// return;
// }
if(ReadPort1(buf,2)!=0)
{
MessageBox((LPCSTR)"讀端口1失敗!", "提示", MB_ICONSTOP);
return;
}
if(buf[0]!=0x55 && buf[1]!=0xaa)
{
MessageBox((LPCSTR)"應答錯誤!", "提示", MB_ICONSTOP);
return;
}
/* char cc[40],t[1];
int i;
itoa((int)nBytes,cc,10);
m_strDown=cc;
m_strDown+=' ';
memset(cc,0,40);
for( i=0;i<4;i++)
{
sprintf(t, "%02X", buf1[i]);
strcat(cc,t);
}
m_strDown+=cc;
memset(cc,0,40);
for( i=0;i<4;i++)
{
sprintf(t, "%02X", buf[i]);
strcat(cc,t);
}
m_strUp=cc;
UpdateData(FALSE);//更新顯示
*/
// if(_mbscmp(buf,buf1)!=0)
// {
// MessageBox((LPCSTR)"接收響應數據出錯", "提示", MB_ICONSTOP);
// return;
// }
/////////////////////////////////////////////
UpdateData(TRUE);//獲得數據
memset(OutBuf,0,out.data);
strcpy((char *)OutBuf,(LPCSTR)m_strDown);
WritePort2(OutBuf,out.data);
/*
hFile = open_file("PIPE03");
if(hFile == INVALID_HANDLE_VALUE)
{
return;
MessageBox((LPCSTR)"端口打開失敗!", "提示", MB_ICONSTOP);
}
hDevice = open_dev();
UpdateData(TRUE);//獲得數據
memset(OutBuf,0,16);
strcpy((char *)OutBuf,(LPCSTR)m_strDown);
bResult = WriteFile(hFile,
OutBuf,
8,
&nBytes,
NULL);
if(bResult==FALSE)
{
DeviceIoControl(hFile,
IOCTL_D12_RESET_PIPE,
0,
0,
0,
0,
&nBytes,
NULL);
MessageBox((LPCSTR)"寫入數據失敗", "提示", MB_ICONSTOP);
}
CloseHandle(hFile);
CloseHandle(hDevice);
*/
}
void CUsbIICRWDlg::OnButtonup()
{
unsigned char buf[1000],buf1[16];
// HANDLE hFile, hDevice=0;
// ULONG nBytes = 0;
UpdateData(TRUE);
///////////////////////////////////////////////
out.data=atol((LPCSTR)m_strRevAdr);
type.data=m_CurrentCardType;
buf1[0]='R';
buf1[1]=type.byte[0];
buf1[2]=type.byte[1];
buf1[3]=out.byte[0];
buf1[4]=out.byte[1];
out.data=atol((LPCSTR)m_strRevLen);
buf1[5]=out.byte[0];;
buf1[6]=out.byte[1];;
buf1[7]=buf1[0]^buf1[1]^buf1[2]^buf1[3]^buf1[4]^buf1[5]^buf1[6];
if(WritePort1(buf1,4)!=0)
{
MessageBox((LPCSTR)"寫命令失敗!", "提示", MB_ICONSTOP);
return;
}
if(WritePort1(buf1+4,4)!=0)
{
MessageBox((LPCSTR)"寫命令失敗!", "提示", MB_ICONSTOP);
return;
}
if(ReadPort1(buf,2)!=0)
{
MessageBox((LPCSTR)"讀端口1失敗!", "提示", MB_ICONSTOP);
return;
}
if(buf[0]!=0x55 && buf[1]!=0xaa)
{
MessageBox((LPCSTR)"應答錯誤!", "提示", MB_ICONSTOP);
return;
}
memset(buf, 0, out.data);
if(ReadPort2(buf,out.data)!=0)
{
MessageBox((LPCSTR)"讀端口2失敗!", "提示", MB_ICONSTOP);
return;
}
char cc[2000],t[1];
UINT i;
memset(cc,0,out.data*2+1);
for( i=0;i<out.data;i++)
{
sprintf(t, "%02X", buf[i]);
strcat(cc,t);
}
m_strUp=cc;
UpdateData(FALSE);
}
void CUsbIICRWDlg::OnSelchangeCboAtmel()
{
int CurrentSelect=m_CboATMEL.GetCurSel(); //從當前狀態得到序號
if (CurrentSelect!=CB_ERR) { //如果這個式子成立,表明選擇了某個項.
m_CboATMEL.GetLBText(CurrentSelect,m_CurrentCardName); //將IC卡的名稱保存下來.
m_CurrentCardType=CardTypeAT[CurrentSelect];//將序號換算成IC卡代碼
// m_CboCPU.SetCurSel(-1); //清楚其他列表框中的卡號.
// m_CboSIEMENS.SetCurSel(-1);
}//如果if條件通不過,則說明沒有選擇任何項目,不用做任何事.
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -