⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isp1581_demodlg.cpp

📁 51单片机众多优秀的开发源程序:ZLG7290例程*ZLG7290汇编例程*蜂鸣器音乐例程*蜂鸣器响例程*读EEPROM并显示例程*16×2LCD模块例程*128×64点阵LCD模块例程*直连KEY和
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ISP1581_demoDlg.cpp : implementation file
//

#include "stdafx.h"
#include <mmsystem.h>
#include "ISP1581_demo.h"
#include "ISP1581_demoDlg.h"
#include "UsbDeviceCommand.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CISP1581_demoDlg dialog

CISP1581_demoDlg::CISP1581_demoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CISP1581_demoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CISP1581_demoDlg)
	m_nEditReadBufferSize = 0;
	m_nEditReadRepeatTimes = 0;
	m_nEditWriteBufferSize = 0;
	m_nEditWriteRepeatTimes = 0;
	m_sStaticAverReadSpeed = _T("");
	m_sStaticAverWriteSpeed = _T("");
	m_sStaticCurReadSpeed = _T("");
	m_sStaticMaxReadSpeed = _T("");
	m_sStaticMaxWriteSpeed = _T("");
	m_sStaticReadByteCount = _T("");
	m_sStaticReadTimeCount = _T("");
	m_sStaticWriteByteCount = _T("");
	m_sStaticWriteCurSpeed = _T("");
	m_sStaticWriteTimeCount = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CISP1581_demoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CISP1581_demoDlg)
	DDX_Control(pDX, IDC_COMBO_BULKWRITEPIPE, m_combo_bulkwritepipe);
	DDX_Control(pDX, IDC_COMBO_BULKREADPIPE, m_combo_bulkreadpipe);
	DDX_Text(pDX, IDC_EDIT_READBUFFERSIZE, m_nEditReadBufferSize);
	DDX_Text(pDX, IDC_EDIT_READREPEATTIMES, m_nEditReadRepeatTimes);
	DDX_Text(pDX, IDC_EDIT_WRITEBUFFERSIZE, m_nEditWriteBufferSize);
	DDX_Text(pDX, IDC_EDIT_WRITEREPEATTIMES, m_nEditWriteRepeatTimes);
	DDX_Text(pDX, IDC_STATIC_AVERREADSPEED, m_sStaticAverReadSpeed);
	DDX_Text(pDX, IDC_STATIC_AVERWRITESPEED, m_sStaticAverWriteSpeed);
	DDX_Text(pDX, IDC_STATIC_CURREADSPEED, m_sStaticCurReadSpeed);
	DDX_Text(pDX, IDC_STATIC_MAXREADSPEED, m_sStaticMaxReadSpeed);
	DDX_Text(pDX, IDC_STATIC_MAXWRITESPEED, m_sStaticMaxWriteSpeed);
	DDX_Text(pDX, IDC_STATIC_READBYTECOUNT, m_sStaticReadByteCount);
	DDX_Text(pDX, IDC_STATIC_READTIMECOUNT, m_sStaticReadTimeCount);
	DDX_Text(pDX, IDC_STATIC_WRITEBYTECOUNT, m_sStaticWriteByteCount);
	DDX_Text(pDX, IDC_STATIC_WRITECURSPEED, m_sStaticWriteCurSpeed);
	DDX_Text(pDX, IDC_STATIC_WRITETIMECOUNT, m_sStaticWriteTimeCount);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CISP1581_demoDlg, CDialog)
	//{{AFX_MSG_MAP(CISP1581_demoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_READSTART, OnButtonReadstart)
	ON_BN_CLICKED(IDC_BUTTON_READSTOP, OnButtonReadstop)
	ON_BN_CLICKED(IDC_BUTTON_WRITESTART, OnButtonWritestart)
	ON_BN_CLICKED(IDC_BUTTON_WRITESTOP, OnButtonWritestop)
	ON_WM_TIMER()
	ON_EN_CHANGE(IDC_EDIT_READBUFFERSIZE, OnChangeEditReadbuffersize)
	ON_EN_CHANGE(IDC_EDIT_WRITEBUFFERSIZE, OnChangeEditWritebuffersize)
	//}}AFX_MSG_MAP
	ON_WM_DEVICECHANGE()
	ON_MESSAGE(WM_CALTIMEMESSAGE, OnCalTimeMessage)	
	ON_MESSAGE(WM_UPDATEMESSAGE, OnUpdateMessage)	
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CISP1581_demoDlg message handlers

BOOL CISP1581_demoDlg::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
	OSVERSIONINFO osvi;
	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx (&osvi);
	if((osvi.dwMajorVersion == 5)&&(osvi.dwMinorVersion == 0))
	{
		m_osversion = OSTWOK;
	}
	else if((osvi.dwMajorVersion == 4)&&(osvi.dwMinorVersion == 90))
	{
		m_osversion = OSME;
	}
	else if((osvi.dwMajorVersion == 4)&&(osvi.dwMinorVersion == 10))
	{
		m_osversion = OSW98;
	}
	InitData();
	CheckBoard();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CISP1581_demoDlg::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 CISP1581_demoDlg::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 CISP1581_demoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CISP1581_demoDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
}

void CISP1581_demoDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	m_BulkRead.bInThread=FALSE;
	m_BulkWrite.bInThread=FALSE;
	KillTimer(1);
	KillTimer(2);
	m_calreadtime.bInThread=FALSE;
	m_calwritetime.bInThread=FALSE;
	Sleep(50);
	WaitForSingleObject(m_BulkRead.hThread,10);
	WaitForSingleObject(m_BulkWrite.hThread,10);
	EndDialog(0);
	//CDialog::OnCancel();
}

void CISP1581_demoDlg::InitData()
{
	UpdateData(true);
	m_nEditReadBufferSize=16000;
	m_nEditReadRepeatTimes=-1;
	m_nEditWriteBufferSize=16000;
	m_nEditWriteRepeatTimes=-1;
	m_sStaticAverReadSpeed="0.0";
	m_sStaticAverWriteSpeed="0.0";
	m_sStaticCurReadSpeed="0.0";
	m_sStaticMaxReadSpeed="0.0";
	m_sStaticMaxWriteSpeed="0.0";
	m_sStaticWriteCurSpeed="0.0";
	m_sStaticReadByteCount="0";
	m_sStaticReadTimeCount="00:00:00";
	m_sStaticWriteByteCount="0";
	m_sStaticWriteTimeCount="00:00:00";
	UpdateData(false);
	m_readtransfer_info.buffersize=16000;
	m_readtransfer_info.repeattimes=-1;
	m_readtransfer_info.averspeed=0;
	m_readtransfer_info.curspeed=0;
	m_readtransfer_info.maxspeed=0;
	m_readtransfer_info.bytecount=0;
	m_readtransfer_info.timecount.hour=0;
	m_readtransfer_info.timecount.minute=0;
	m_readtransfer_info.timecount.second=0;
	m_devchange=0;
	
}

void CISP1581_demoDlg::GetData(int nread)
{
	UpdateData(true);
	CString tmp;
	switch(nread)
	{
	case 0:
		m_readtransfer_info.buffersize=m_nEditReadBufferSize;
		m_readtransfer_info.repeattimes=m_nEditReadRepeatTimes;
		m_readtransfer_info.averspeed=atoi((LPCTSTR)m_sStaticAverReadSpeed);
		m_readtransfer_info.curspeed=atoi((LPCTSTR)m_sStaticCurReadSpeed);
		m_readtransfer_info.maxspeed=atoi((LPCTSTR)m_sStaticMaxReadSpeed);
		m_readtransfer_info.bytecount=atoi((LPCTSTR)m_sStaticReadByteCount);
		tmp=m_sStaticReadTimeCount;
		m_readtransfer_info.timecount.hour=atoi((LPCTSTR)tmp);
		tmp=tmp.Right(5);
		m_readtransfer_info.timecount.minute=atoi((LPCTSTR)tmp);
		tmp=tmp.Right(2);
		m_readtransfer_info.timecount.second=atoi((LPCTSTR)tmp);
		break;
	case 1:
		m_writetransfer_info.buffersize=m_nEditWriteBufferSize;
		m_writetransfer_info.repeattimes=m_nEditWriteRepeatTimes;
		m_writetransfer_info.averspeed=atoi((LPCTSTR)m_sStaticAverWriteSpeed);
		m_writetransfer_info.curspeed=atoi((LPCTSTR)m_sStaticWriteCurSpeed);
		m_writetransfer_info.maxspeed=atoi((LPCTSTR)m_sStaticMaxWriteSpeed);
		m_writetransfer_info.bytecount=atoi((LPCTSTR)m_sStaticWriteByteCount);
		tmp=m_sStaticWriteTimeCount;
		m_writetransfer_info.timecount.hour=atoi((LPCTSTR)tmp);
		tmp=tmp.Right(5);
		m_writetransfer_info.timecount.minute=atoi((LPCTSTR)tmp);
		tmp=tmp.Right(2);
		m_writetransfer_info.timecount.second=atoi((LPCTSTR)tmp);
		break;
	}
	UpdateData(false);
}

void CISP1581_demoDlg::OnButtonReadstart() 
{
	// TODO: Add your control notification handler code here
	CString pipename;
	
	if(m_combo_bulkreadpipe.GetCurSel()==CB_ERR)
	{
		MessageBox("请选择要操作的管道","警告");
		return;
	}
	UpdateData(true);
	m_BulkRead.bInThread=TRUE;
	m_BulkRead.testDlg=this;
//	if(m_nEditReadBufferSize%64!=0)
//		m_nEditReadBufferSize+=64-m_nEditReadBufferSize%64;
	m_BulkRead.buffersize=m_nEditReadBufferSize;
	m_BulkRead.repeattimes=m_nEditReadRepeatTimes;
	m_combo_bulkreadpipe.GetLBText(m_combo_bulkreadpipe.GetCurSel(),pipename);
	strcpy(m_BulkRead.pipe_name,(LPCTSTR)pipename);

	m_readtransfer_info.bytecount=0;
	m_readtransfer_info.buffersize=m_nEditReadBufferSize;
	m_readtransfer_info.curspeed=0;
	m_readtransfer_info.maxspeed=0;
	m_readtransfer_info.averspeed=0;
	m_readtransfer_info.repeattimes=m_nEditReadRepeatTimes;
	m_readtransfer_info.timecount.hour=0;
	m_readtransfer_info.timecount.minute=0;
	m_readtransfer_info.timecount.second=0;
	m_sStaticReadTimeCount="00:00:00";
	
	UpdateData(false);

	EnableButton(false,true,false,false);
	EnableEdit(false,false,false,false);
	m_starttime=timeGetTime();
	SetTimer(1,1000,NULL);
	CWinThread * wt = AfxBeginThread( 
		BulkReadPipe, // thread function 
		&m_BulkRead); // argument to thread function 	
	m_BulkRead.hThread=wt->m_hThread;
}

void CISP1581_demoDlg::OnButtonReadstop() 
{
	// TODO: Add your control notification handler code here
	m_BulkRead.bInThread=FALSE;
	EnableButton(true,false,true,false);
	EnableEdit(true,true,true,true);
	KillTimer(1);
	KillTimer(2);
	m_calreadtime.bInThread=FALSE;
	m_calwritetime.bInThread=FALSE;
	
}

void CISP1581_demoDlg::OnButtonWritestart() 
{
	// TODO: Add your control notification handler code here
	CString pipename;
	
	if(m_combo_bulkwritepipe.GetCurSel()==CB_ERR)
	{
		MessageBox("请选择要操作的管道","警告");
		return;
	}
	UpdateData(true);
	m_BulkWrite.bInThread=TRUE;
	m_BulkWrite.testDlg=this;
//	if(m_nEditWriteBufferSize%64!=0)
//		m_nEditWriteBufferSize+=64-m_nEditWriteBufferSize%64;
	m_BulkWrite.buffersize=m_nEditWriteBufferSize;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -