📄 usbdlg.cpp
字号:
}
/*
else{
::SetWindowLong(GetDlgItem(IDC_VIEWIMAGE)->m_hWnd, GWL_STYLE, BS_PUSHBUTTON);
//GetDlgItem(IDC_VIEWIMAGE)->SetWindowText("Viewer");
}
*/
}
void CUsbtestDlg::OnOpenDevButton()
{
// TODO: Add your control notification handler code here
CStatic* p = (CStatic*)GetDlgItem(IDC_OPEN_DEV);
if(FindUsbDev(UsbDevID)) {
SaveFile=FALSE; // disable save bmp file
p->SetWindowText("Ready");
EnableAllControl(TRUE);
GetDlgItem(IDC_VIEWIMAGE)->EnableWindow(FALSE);
}
else {
p->SetWindowText("N/A");
EnableAllControl(FALSE);
}
}
#define EP0_MAX_READ_SIZE 64*4
void CUsbtestDlg::OnEppAddrReadButton()
{
// TODO: Add your control notification handler code here
WORD wSize=EP0_MAX_READ_SIZE, i;
BYTE buf[EP0_MAX_READ_SIZE];
CString ss, sn;
CEdit* pa = (CEdit*)GetDlgItem(IDC_EPP_ADDR_READ);
pa->GetWindowText(ss);
sscanf(ss,"%x",&wSize);
if (wSize > EP0_MAX_READ_SIZE)
wSize = EP0_MAX_READ_SIZE;
ss.Format("0x%04x: ",wSize);
if (UsbVendorCmdRead(V_EPP_ADDR_READ, 0, 0, wSize, buf))
{
for (i=0; i<wSize; i++)
{ sn.Format("%02X ", buf[i]);
ss += sn;
}
pa->SetWindowText(ss);
}
else
pa->SetWindowText("N/A");
}
void CUsbtestDlg::OnEppDataReadButton()
{
// TODO: Add your control notification handler code here
WORD wSize=EP0_MAX_READ_SIZE, i;
BYTE buf[EP0_MAX_READ_SIZE];
CString ss, sn;
CEdit* pa = (CEdit*)GetDlgItem(IDC_EPP_DATA_READ);
pa->GetWindowText(ss);
sscanf(ss,"%x",&wSize);
if (wSize > EP0_MAX_READ_SIZE)
wSize = EP0_MAX_READ_SIZE;
ss.Format("0x%04x: ",wSize);
if (UsbVendorCmdRead(V_EPP_DATA_READ, 0x2040, 0, wSize, buf))
{
for (i=0; i<wSize; i++)
{ sn.Format("%02X ", buf[i]);
ss += sn;
}
pa->SetWindowText(ss);
}
else
pa->SetWindowText("N/A");
}
void CUsbtestDlg::OnEppAddrWriteButton()
{
// TODO: Add your control notification handler code here
WORD wData=0;
CString ss;
CEdit* pa = (CEdit*)GetDlgItem(IDC_EPP_ADDR_WRITE);
pa->GetWindowText(ss);
sscanf(ss,"%x",&wData);
if (UsbVendorCmdWrite(V_EPP_ADDR_WRITE, 0, wData, 0, 0))
{ ss.Format("0x%04x",wData);
pa->SetWindowText(ss);
}
else
pa->SetWindowText("N/A");
}
void CUsbtestDlg::OnEppDataWriteButton()
{
// TODO: Add your control notification handler code here
WORD wData=0;
CString ss;
CEdit* pa = (CEdit*)GetDlgItem(IDC_EPP_DATA_WRITE);
pa->GetWindowText(ss);
sscanf(ss,"%x",&wData);
if (UsbVendorCmdWrite(V_EPP_DATA_WRITE, 0, wData, 0, 0))
{ ss.Format("0x%04x",wData);
pa->SetWindowText(ss);
}
else
pa->SetWindowText("N/A");
}
#define cSL11R_SRAM_ADDR 0xc00
#define cSL11R_SRAM_SIZE (0x8000-0xc00)/2
void CUsbtestDlg::OnSramTestButton()
{
// TODO: Add your control notification handler code here
WORD wRetVal;
CEdit* p = (CEdit*)GetDlgItem(IDC_SRAM_TEST);
if (UsbVendorCmdRead(V_RAM_TEST, cSL11R_SRAM_ADDR, cSL11R_SRAM_SIZE, 2, &wRetVal))
{ if (wRetVal)
p->SetWindowText("Fail");
else
p->SetWindowText("OK");
}
else
p->SetWindowText("N/A");
}
#define cSL11R_DRAM_ADDR 0x8000
#define cSL11R_DRAM_SIZE 4096*2 // page size: = Page1(8K) + Page2(8K) = 16K
void CUsbtestDlg::OnSl11rDmemTestButton()
{
// TODO: Add your control notification handler code here
WORD wRetVal;
CEdit* p = (CEdit*)GetDlgItem(IDC_DRAM_TEST);
// setup SL11R Extend DRAM page 1 map from 0x8000 to 0xa000
if (!UsbVendorCmdWrite(V_CPU_POKE, 0xc018, 0x100, 0, 0))
{ p->SetWindowText("N/A");
return;
}
// setup SL11R Extend DRAM page 2 map from 0xa000 to 0xc000
if (!UsbVendorCmdWrite(V_CPU_POKE, 0xc01a, 0x101, 0, 0))
{ p->SetWindowText("N/A");
return;
}
// setup DRAM turbo, PageMode, Enable refresh
if (!UsbVendorCmdWrite(V_CPU_POKE, 0xc038, 0x7, 0, 0))
{ p->SetWindowText("N/A");
return;
}
if (UsbVendorCmdRead(V_RAM_TEST, cSL11R_DRAM_ADDR, cSL11R_DRAM_SIZE, 2, &wRetVal))
{ if (wRetVal)
p->SetWindowText("Fail");
else
p->SetWindowText("OK");
}
else
p->SetWindowText("N/A");
}
#define EP0_MAX_PEEK_SIZE 16*1024
void CUsbtestDlg::OnPeekButton()
{
// TODO: Add your control notification handler code here
WORD wAddr, wSize=EP0_MAX_PEEK_SIZE, i;
CString ss, sn;
CEdit* pa = (CEdit*)GetDlgItem(IDC_SL11R_ADDR);
pa->GetWindowText(ss);
sscanf(ss,"%x",&wAddr);
pa = (CEdit*)GetDlgItem(IDC_SL11R_SIZE);
pa->GetWindowText(ss);
sscanf(ss,"%x",&wSize);
if (wSize > EP0_MAX_PEEK_SIZE)
wSize = EP0_MAX_PEEK_SIZE;
ss.Format("0x%04x: ",wSize);
HGLOBAL hImageBuf = ::GlobalAlloc(GHND, (DWORD)wSize);
if(hImageBuf == NULL)
{
AfxMessageBox("Insufficient memory for GlobalAlloc!");
return;
}
WORD *wBuf = (WORD*)::GlobalLock(hImageBuf);
if(wBuf == NULL)
{
AfxMessageBox("Insufficient memory!");
GlobalFree(hImageBuf);
return;
}
pa = (CEdit*)GetDlgItem(IDC_SL11R_DATA);
if (UsbVendorCmdRead(V_CPU_PEEK, wAddr, 0, wSize, wBuf))
{
for (i=0; i<(wSize/2); i++)
{ sn.Format("%04X ", wBuf[i]);
ss += sn;
}
pa->SetWindowText(ss);
}
else
pa->SetWindowText("N/A");
GlobalFree(hImageBuf);
}
void CUsbtestDlg::OnPokeButton()
{
// TODO: Add your control notification handler code here
CString ss;
CEdit* pa = (CEdit*)GetDlgItem(IDC_SL11R_ADDR);
pa->GetWindowText(ss);
WORD wAddr=0, wData=0;
sscanf(ss,"%x",&wAddr);
CEdit* ps = (CEdit*)GetDlgItem(IDC_SL11R_DATA);
ps->GetWindowText(ss);
sscanf(ss,"%x",&wData);
if (UsbVendorCmdWrite(V_CPU_POKE, wAddr, wData, 0, 0))
{ ss.Format("0x%04x",wAddr);
pa->SetWindowText(ss);
}
else
pa->SetWindowText("N/A");
}
void CUsbtestDlg::WriteBlock(BYTE Cmd)
{
CString ss;
CEdit* pLineNumber= (CEdit*)GetDlgItem(IDC_LINENUMBER);
CEdit* pImageSize = (CEdit*)GetDlgItem(IDC_IMAGESIZE);
BYTE *bBuf;
pLineNumber->GetWindowText(ss);
WORD i, linecnt = (WORD)atoi(ss);
pImageSize->GetWindowText(ss);
DWORD imagesize = (DWORD)atoi(ss);
if(linecnt==0 || imagesize == 0) {
AfxMessageBox("Please enter line number and image size!");
return;
}
if (Cmd == V_RAM_BLOCK_WRITE)
{ if (imagesize >= (32*1024))
{ AfxMessageBox("Please enter smaller image size <= 32*1024");
return;
}
}
UserAbort = FALSE;
EnableAllControl(FALSE);
GetDlgItem(IDC_ABORT_BUTTON)->EnableWindow(TRUE);
GetDlgItem(IDC_TIMER)->SetWindowText(" ");
CProgressCtrl* pShowProgress = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS);
HGLOBAL hImageBuf = ::GlobalAlloc(GHND, (DWORD)imagesize);
if(hImageBuf == NULL)
{
AfxMessageBox("Insufficient memory for GlobalAlloc!");
return;
}
bBuf = (BYTE*)::GlobalLock(hImageBuf);
if(bBuf == NULL)
{
AfxMessageBox("Insufficient memory!");
GlobalFree(hImageBuf);
return;
}
CWnd* pGetImage = (CWnd*)GetDlgItem(IDC_GETIMAGE);
pShowProgress->SetPos(0);
for (i=0; i<imagesize; i++) // create a ramp pattern
bBuf[i]=(BYTE)i;
if (!UsbVendorCmdWrite(Cmd, (WORD)(imagesize>>16), (WORD)(imagesize&0xffff), 0, 0))
{
pGetImage->SetWindowText("Fail");
return;
}
DWORD starttime = GetTickCount();
for(i = 0; (i<linecnt) && !UserAbort; i++)
{
if (UsbDataWrite((DWORD)imagesize, bBuf))
{
pShowProgress->SetPos(i==linecnt -1 ? 100:(int)(i*100/linecnt));
ss.Format("WrBlock: %d", i+1);
pGetImage->SetWindowText(ss);
Idle();
}
else
{
pGetImage->SetWindowText("N/A");
break;
}
}
DWORD endtime = GetTickCount();
GlobalUnlock(hImageBuf);
GlobalFree(hImageBuf);
endtime -= starttime;
endtime /= 1000;
if (endtime)
{
ss.Format("%d", (imagesize*i)/endtime);
GetDlgItem(IDC_TIMER)->SetWindowText(ss);
}
EnableAllControl(TRUE);
if (SaveFile)
GetDlgItem(IDC_VIEWIMAGE)->EnableWindow(TRUE);
else
GetDlgItem(IDC_VIEWIMAGE)->EnableWindow(FALSE);
}
void CUsbtestDlg::OnWriteEppBlockButton()
{ // TODO: Add your control notification handler code here
WriteBlock(V_EPP_BLOCK_WRITE);
}
void CUsbtestDlg::OnWriteSramBlockButton()
{
// TODO: Add your control notification handler code here
WriteBlock(V_RAM_BLOCK_WRITE);
}
/////////////////////////////////////////////////////////////////////////////
// ReadBlock
/////////////////////////////////////////////////////////////////////////////
void CUsbtestDlg::ReadBlock(BYTE Cmd)
{ // TODO: Add your control notification handler code here
CString ss;
CEdit* pLineNumber= (CEdit*)GetDlgItem(IDC_LINENUMBER);
CEdit* pImageSize = (CEdit*)GetDlgItem(IDC_IMAGESIZE);
pLineNumber->GetWindowText(ss);
WORD linegot, linecnt = atoi(ss);
pImageSize->GetWindowText(ss);
DWORD imagesize = (DWORD)atoi(ss); int realimagesize;
if(linecnt==0 || imagesize == 0)
{
AfxMessageBox("Please enter line number and image size!");
return;
}
if (imagesize> (16*1024))
realimagesize = 16*1024;
else // make sure the imagesize if multiple of 4, for creating bmpfile
realimagesize = imagesize & 0xfffc;
UserAbort = FALSE;
EnableAllControl(FALSE);
GetDlgItem(IDC_ABORT_BUTTON)->EnableWindow(TRUE);
GetDlgItem(IDC_TIMER)->SetWindowText(" ");
if (SaveFile)
{
m_BmpFilePath = GetBmpFilePath();
if(::GetFileAttributes(m_BmpFilePath) != 0xffffffff)::DeleteFile(m_BmpFilePath);
if(!BmpFile.Open(m_BmpFilePath, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary))
{
AfxMessageBox("create bmp file fails!");
return;
}
GetDlgItem(IDC_IMAGEFILE)->SetWindowText(m_BmpFilePath);
} else
GetDlgItem(IDC_IMAGEFILE)->SetWindowText("Skip Save BMP File");
CProgressCtrl* pShowProgress = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS);
HGLOBAL hImageBuf = ::GlobalAlloc(GHND, (DWORD)imagesize);
if(hImageBuf == NULL)
{
AfxMessageBox("Insufficient memory for GlobalAlloc!");
return;
}
LPBYTE bBuf = (LPBYTE)::GlobalLock(hImageBuf);
if(bBuf == NULL)
{
AfxMessageBox("Insufficient memory!");
GlobalFree(hImageBuf);
return;
}
CWnd* pGetImage = (CWnd*)GetDlgItem(IDC_GETIMAGE);
pShowProgress->SetPos(0);
//ar* str = "This is a test for perform multiple line operatio in Edit control";
// move the reading head
if (SaveFile)
BmpFile.Seek(sizeof(BIH)+sizeof(BFH)+sizeof(RGBQUAD)*256, CFile::begin);
if (!UsbVendorCmdWrite(Cmd, (WORD)(imagesize>>16), (WORD)(imagesize & 0xffff), 0, 0))
{
pGetImage->SetWindowText("Fail");
return;
}
DWORD starttime = GetTickCount();
for(linegot = 0; (linegot<linecnt) && !UserAbort; linegot++)
{
if (UsbDataRead((DWORD)imagesize, bBuf))
{
// write image data
if (SaveFile)
BmpFile.Write(bBuf, realimagesize);
// show progress
pShowProgress->SetPos(linegot==linecnt -1 ? 100:(int)(linegot*100/linecnt));
ss.Format("RdBlock: %d", linegot+1);
pGetImage->SetWindowText(ss);
// retrieve user abort scanning message
Idle();
}
else {
pGetImage->SetWindowText("N/A");
break;
}
}
DWORD endtime = GetTickCount();
GlobalUnlock(hImageBuf);
GlobalFree(hImageBuf);
endtime -= starttime;
endtime /= 1000;
if (endtime)
{
ss.Format("%d", (imagesize*linegot)/endtime);
GetDlgItem(IDC_TIMER)->SetWindowText(ss);
}
EnableAllControl(TRUE);
if (SaveFile)
{
::SetEndOfFile((HANDLE)BmpFile.m_hFile);
BmpFile.Close();
if(linegot)
{
if(!MakeBmpFileHeader(linegot, realimagesize))
BmpFile.Remove(m_BmpFilePath);
}
else BmpFile.Remove(m_BmpFilePath);
}
else
GetDlgItem(IDC_VIEWIMAGE)->EnableWindow(FALSE);
}
void CUsbtestDlg::OnReadSramBlockButton()
{
// TODO: Add your control notification handler code here
ReadBlock(V_RAM_BLOCK_READ);
}
void CUsbtestDlg::OnSaveFileButton()
{ // TODO: Add your control notification handler code here
// allows to store bitmap file on ReadEppBlockButton and ReadSramBlockButton
CStatic* p = (CStatic*)GetDlgItem(IDC_GETIMAGE);
SaveFile = !SaveFile;
if (SaveFile)
{ p->SetWindowText("YES");
GetDlgItem(IDC_VIEWIMAGE)->EnableWindow(TRUE);
}
else
{ p->SetWindowText("NO");
GetDlgItem(IDC_VIEWIMAGE)->EnableWindow(FALSE);
}
}
void CUsbtestDlg::OnReadEppBlockButton()
{
// TODO: Add your control notification handler code here
ReadBlock(V_EPP_BLOCK_READ);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -