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

📄 ezmr.cpp

📁 EZ _USB Control PANEL 源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CEzMrApp commands

BOOL CEzMrApp::OnIdle(LONG lCount)
{
	// CG: The following code inserted by 'Idle Time Processing' component.

	// Note: Do not perform lengthy tasks during OnIdle because your
	// application cannot process user input until OnIdle returns.

	// call the base class
	BOOL bBaseIdle = CWinApp::OnIdle(lCount);

	BOOL bMoreIdle = TRUE;
	if (lCount == 0)
	{
		// TODO: add code to perform important idle time processing
	}
	else if (lCount == 100)
	{
		// TODO: add code to perform less important tasks during idle
		if(m_nPollPorts)
		{
			MessageBeep(MB_OK);
			//OnFileUpdateAllDevs();
			OnFileOpenAllDevs();
		}
	}
	else if (lCount == 1000)
	{
		// TODO: add code to perform occasional tasks during idle
		bMoreIdle = bBaseIdle;
	}

	// return FALSE when there is no more idle processing to do
	return bMoreIdle;
}

void CEzMrApp::OnOptionsEdithexfile() 
{
	TRACE("TPM:CEzMrApp::OnOptionsEdithexfile()\n");
	//WinExec("..\\Tools\\hexwrk\\hworks32.exe", SW_SHOWNOACTIVATE);
	WinExec(m_strHexEdFileName, SW_SHOWNOACTIVATE);
}

void CEzMrApp::OnFileUpdateAllDevs() 
{
    HANDLE  hDevice = NULL;
    char    pcDriverName[MAX_DRIVER_NAME] = "";
	m_strUSBDevs = "";
	for(int i =0; i<MAX_USB_DEV_NUMBER; i++)
	{
		sprintf(pcDriverName, "Ezusb-%d", i);
		if (bOpenDriver (&hDevice, pcDriverName) == TRUE)
		{
			TRACE("TPM:CEzMrApp::OnFileUpdateAllDevs(): %s available\n", pcDriverName);
			m_strUSBDevs += pcDriverName;
			m_strUSBDevs += "\n";
            CloseHandle (hDevice);
		}
	}
/*
	POSITION dpos = m_pUSBDocTemplate->GetFirstDocPosition();
	while (dpos != 0)	
	{
		CDocument* pDoc = m_pUSBDocTemplate->GetNextDoc(dpos);
		ASSERT(pDoc != 0);
		POSITION vpos = pDoc->GetFirstViewPosition();
		CEzMrView* pView = (CEzMrView*)(pDoc->GetNextView(vpos));
		pView->UpdDrv();
	}
*/
}

void CEzMrApp::report_error(const char *fmt, ...)
{
	char buf[0x1000];
	va_list va;
	va_start( va, fmt );
	vsprintf( buf, fmt, va );
	va_end( va );
	TRACE(buf);
	if(!m_nQuietMode)
		AfxMessageBox(buf, MB_OK | MB_ICONEXCLAMATION);
}


void CEzMrApp::OnFileOpenAllDevs() 
{
    HANDLE  hDevice = NULL;
    char    pcDriverName[MAX_DRIVER_NAME] = "";
	int num_dev;
	int nIdxSubStr;
	CString strText;
	CString strItem;

	OnFileUpdateAllDevs();

	strText = theApp.m_strUSBDevs;

	if(strText == "")
	{
		theApp.report_error("No Cypress USB devices detected.\nYou may need to plug in (or install) USB devices.\nUse Open All Devices to refresh display.\n");
		return;
	}

	for(num_dev = 0; ((nIdxSubStr = strText.Find('\n')) != -1); num_dev++)
	{
		strItem = strText.Left(nIdxSubStr);
		strText = strText.Mid(nIdxSubStr+1);
		sprintf(pcDriverName, "%s", strItem);
		if (bOpenDriver (&hDevice, pcDriverName) == TRUE)
		{
			TRACE("TPM:CEzMrApp::OnFileOpenAllDevs(): %s available\n", pcDriverName);
            CloseHandle (hDevice);

			int nDocOpen = 0;
			POSITION dpos = m_pUSBDocTemplate->GetFirstDocPosition();
			while (dpos != 0)	
			{
				CDocument* pDoc = m_pUSBDocTemplate->GetNextDoc(dpos);
				ASSERT(pDoc != 0);
				CString strDocument = pDoc->GetTitle();
				POSITION vpos = pDoc->GetFirstViewPosition();
				CEzMrView* pView = (CEzMrView*)(pDoc->GetNextView(vpos));
				char* pcSelDriverName = pView->GetDrv();
				if(!strcmp(pcDriverName, pcSelDriverName))
				{
					nDocOpen = 1;
					TRACE("TPM:CEzMrApp::OnFileOpenAllDevs(): %s:%s is open\n", 
						strDocument, pcSelDriverName);
				}
			}

			if(!nDocOpen)
			{
				TRACE("TPM:CEzMrApp::OnFileOpenAllDevs(): %s opening...\n", pcDriverName);
				m_pUSBDoc[num_dev] = m_pUSBDocTemplate->OpenDocumentFile(NULL); // start up USB Device
				POSITION vpos = m_pUSBDoc[num_dev]->GetFirstViewPosition();
				CEzMrView* pView = (CEzMrView*)(m_pUSBDoc[num_dev]->GetNextView(vpos));

				CString str_pcDriverName = pcDriverName;
				CString strText = theApp.m_strUSBDevs;
				int nIdxSubStr;
				for(int i = 0; ((nIdxSubStr = strText.Find('\n')) != -1); i++)
				{ // Select correct driver
					CString strItem = strText.Left(nIdxSubStr);
					strText = strText.Mid(nIdxSubStr+1);
					if(strItem == str_pcDriverName)
					{
						pView->SetDrv(i);
						pView->SendOp(OP_GET_PIPINF); // "get pipes" at startup
						break;
					}
				}
			}
		}
	}
}

void CEzMrApp::OnFileGpifTool() 
{
	CFileStatus status;
	if( CFile::GetStatus( m_strPathUSBRoot + "\\Bin\\GPIF.exe", status ) )
	{ // if program exists
		WinExec(m_strPathUSBRoot + "\\Bin\\GPIF.exe", SW_SHOWNOACTIVATE);
	}
	else
	{
		theApp.report_error("Error running GPIFTool; Not available.\n");
		return;
	}	
}

int CEzMrApp::ExitInstance() 
{
	return CWinApp::ExitInstance();
}

void CEzMrApp::OnOptionsRunCableTest() 
{
	TRACE("TPM:CEzMrApp::OnOptionsRunCableTest()\n");
	CDlgTest dlg;
	m_nQuietMode = 1; //supress popups
	dlg.DoModal();
	m_nQuietMode = 0;
}



void CEzMrApp::OnHelpGotoupdateonweb() 
{
    // For URL, open it in the browser
    HINSTANCE h = ShellExecute(NULL, "open", "http://www.cypress.com/usb/index.html", NULL, NULL, SW_SHOWNORMAL);
    if(!((UINT)h > 32)) 
	{
		AfxMessageBox("Sorry: cannot access web location", MB_OK | MB_ICONEXCLAMATION);
	}
}

void CEzMrApp::OnHelpContactanchorchips() 
{
    HINSTANCE h = ShellExecute(NULL, "open", "mailto:USB Applications <usbapps@cypress.com>", NULL, NULL, SW_SHOWNORMAL);
    if(!((UINT)h > 32)) 
	{
		AfxMessageBox("Sorry: cannot access email", MB_OK | MB_ICONEXCLAMATION);
	}
}

void CEzMrApp::OnHelpContentsandtutorial() 
{
    // For URL, open it in the browser
    HINSTANCE h = ShellExecute(NULL, "open", m_strPathUSBRoot + "\\Doc\\EZ-USB General\\EZ-USB Contents and Tutorial.pdf", NULL, NULL, SW_SHOWNORMAL);
    if(!((UINT)h > 32)) 
	{
		AfxMessageBox("Sorry: cannot access document. You may need Acrobat Reader", MB_OK | MB_ICONEXCLAMATION);
	}
}

void CEzMrApp::OnHelpControlpaneluserguide() 
{
    // For URL, open it in the browser
    HINSTANCE h = ShellExecute(NULL, "open", m_strPathUSBRoot + "\\Doc\\EZ-USB General\\EzMrUser.pdf", NULL, NULL, SW_SHOWNORMAL);
    if(!((UINT)h > 32)) 
	{
		AfxMessageBox("Sorry: cannot access document. You may need Acrobat Reader", MB_OK | MB_ICONEXCLAMATION);
	}
}

void CEzMrApp::OnUpdateFileGpiftool(CCmdUI* pCmdUI) 
{
	CFileStatus status;
	if( CFile::GetStatus( m_strPathUSBRoot + "\\Bin\\GPIF.exe", status )
		&& (theApp.m_nTarg != 2))
		pCmdUI->Enable(TRUE);
	else
		pCmdUI->Enable(FALSE);
}

void CEzMrApp::OnOptionsFx2() 
{
	if(m_nTarg==2)
	{
		m_nTarg = 2; // set default target to Sx2
		theApp.m_strTargetName = "Sx2";
		theApp.m_strMonFileName = theApp.GetProfileString("Settings", "m_strMonFileName", 
		theApp.m_strPathUSBRoot + "\\Target\\Monitor\\mon-ext-sio1-c0.hex");
	}
	else if(m_nTarg==1)
	{
		m_nTarg = 1; // set default target to Fx2
		theApp.m_strTargetName = "Fx2";
		theApp.m_strMonFileName = theApp.GetProfileString("Settings", "m_strMonFileName", 
		theApp.m_strPathUSBRoot + "\\Target\\Monitor\\mon-ext-sio1-c0.hex");
	}
	else
	{
		m_nTarg = 0; // set default target to Fx
		theApp.m_strTargetName = "EZ-USB";
		theApp.m_strMonFileName = theApp.GetProfileString("Settings", "m_strMonFileName", 
		theApp.m_strPathUSBRoot + "\\Target\\Monitor\\mon-ext-sio1-e0.hex");
	}
	theApp.WriteProfileString("Settings", "m_strTargetName", theApp.m_strTargetName);
}



⌨️ 快捷键说明

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