📄 displayview.cpp
字号:
}
//添加代码
::GlobalUnlock((HGLOBAL) pdlg->GetDocument()->m_hDib);
// Sleep(10);
ReleaseMutex(pdlg->m_hsem);
}
SetEvent(pdlg->m_heventdone[0]);
return 0;
}
//
UINT vdatashow(LPVOID pParam)
{
//数据显示
CDisplayView *pdlg=(CDisplayView *)pParam;
if(pdlg==NULL||
!pdlg->IsKindOf(RUNTIME_CLASS(CDisplayView)))
return 2;
ResetEvent(pdlg->m_heventdone[1]);
while(WaitForSingleObject(pdlg->m_heventbuttonok,0)!=WAIT_OBJECT_0)
{
if(WaitForSingleObject(pdlg->m_hsem,INFINITE)==WAIT_OBJECT_0)
{
//添加代码
LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) pdlg->GetDocument()->m_hDib);
pdlg->m_tmp++;
BULK_TRANSFER_CONTROL bulk;
WORD inPacketSize=64;
int i;
// int sucess;
unsigned char write_buf[64];
ULONG nBytes=0;
bulk.pipeNum=0;
for(i=0;i<64;i++)
write_buf[i]=pdlg->m_tmp;
/* sucess=DeviceIoControl
(pdlg->GetDocument()->phand,IOCTL_EZUSB_BULK_WRITE,
&bulk,
sizeof(BULK_TRANSFER_CONTROL),
write_buf,
inPacketSize,
&nBytes,
NULL);
if(!sucess)
{
MessageBox(NULL,"写数据错误!","信息提示",MB_OK);
return 3;
}*/
}
//添加代码
::GlobalUnlock((HGLOBAL) pdlg->GetDocument()->m_hDib);
// Sleep(10);
ReleaseMutex(pdlg->m_hsem);
}
SetEvent(pdlg->m_heventdone[1]);
return 0;
}
//
void CDisplayView::OnViewContinue()
{
// TODO: Add your command handler code here
CDisplayDoc* pDoc = GetDocument();
if(pDoc->m_hDib==NULL)
{
MessageBox("未初始化图象","信息提示",MB_OK);
return ;
}
pDoc->phand=NULL;
char devicename[]="Ezusb-0";
if(!pDoc->bOpenDriver(&pDoc->phand,devicename))
{
MessageBox("打开设备出错","信息提示",MB_OK);
// flag=0;
return ;
}
m_heventbuttonok=CreateEvent(NULL,true,false,NULL);
for(int i=0;i<6;i++)
m_heventdone[i]=CreateEvent(NULL,true,true,NULL);
m_hsem=CreateMutex(NULL,false,NULL);
CDisplayView *pdlg=this;
AfxBeginThread(vdatagather,(LPVOID)pdlg);
AfxBeginThread(vdatashow,(LPVOID)pdlg);
// AfxBeginThread(vdatashow1,(LPVOID)pdlg);
// AfxBeginThread(vdatashow2,(LPVOID)pdlg);
// AfxBeginThread(vdatashow3,(LPVOID)pdlg);
// AfxBeginThread(vdatashow4,(LPVOID)pdlg);
}
void CDisplayView::OnStopAll()
{
// TODO: Add your command handler code here
if((WaitForSingleObject(m_heventdone[0],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[1],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[2],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[3],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[4],0)!=WAIT_OBJECT_0)
||(WaitForSingleObject(m_heventdone[5],0)!=WAIT_OBJECT_0)
)
{
SetEvent(m_heventbuttonok);
return ;
}
}
void CDisplayView::DrawGray2D( CDC *pDC, HANDLE hDIB,int con )
{
CPalette pal;
CPalette *OldPal;
BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB;
//计算位图颜色数
int nColors = bmInfo.bmiHeader.biClrUsed ? bmInfo.bmiHeader.biClrUsed :1 << bmInfo.bmiHeader.biBitCount;
if( pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE && nColors <= 256 )
{
//如果系统支持调色板且位图小于256色。
// 分配内存给调色板
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * nColors);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
//初始化系统调色板版本号
pLP->palVersion = 0x300;
//调色版颜色数
pLP->palNumEntries = nColors;
//设置灰度调色板
for( int i=0; i < nColors; i++)
{
//int nGray = (bmInfo.bmiColors[i].rgbRed*299+ bmInfo.bmiColors[i].rgbGreen*587+ bmInfo.bmiColors[i].rgbBlue*114)/1000;
int nGray=con+i;
//修改系统调色板
pLP->palPalEntry[i].peRed = nGray;
pLP->palPalEntry[i].peGreen = nGray;
pLP->palPalEntry[i].peBlue = nGray;
pLP->palPalEntry[i].peFlags = 0;
}
pal.CreatePalette( pLP );
delete[] pLP;
// 选择调色板
OldPal = pDC->SelectPalette(&pal, FALSE);
pDC->RealizePalette();
}
else if((pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) == 0 && nColors <= 256 )
{
//系统不支持调色板,但位图颜色小于256色
for( int i=0; i < nColors; i++)
{
//int nGray = (bmInfo.bmiColors[i].rgbRed*299+ bmInfo.bmiColors[i].rgbGreen*587+ bmInfo.bmiColors[i].rgbBlue*114)/1000;
int nGray=con+i;
//修改位图调色板
bmInfo.bmiColors[i].rgbRed = nGray;
bmInfo.bmiColors[i].rgbGreen = nGray;
bmInfo.bmiColors[i].rgbBlue = nGray;
}
}
}
void CDisplayView::OnColor()
{
// TODO: Add your command handler code here
gray_flag=0;
this->SetRedraw(true);
this->Invalidate(false);
high=20;
}
void CDisplayView::OnGray()
{
// TODO: Add your command handler code here
gray_flag=1;
this->SetRedraw(true);
this->Invalidate(false);
//this->RedrawWindow(NULL,NULL,RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE);
//this->OnUpdate(NULL,0,0);
}
void CDisplayView::OnIsoRead()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
CDisplayDoc* pDoc = GetDocument();
if(pDoc->m_hDib==NULL)
{
MessageBox("未初始化图象","信息提示",MB_OK);
return ;
}
pDoc->phand=NULL;
char devicename[]="Ezusb-0";
if(!pDoc->bOpenDriver(&pDoc->phand,devicename))
{
MessageBox("打开设备出错","信息提示",49);
return ;
}
//reset pipe
ISO_TRANSFER_CONTROL IsoControl;
ULONG count=0;
BOOL bResult=false;
// perform the ISO transfer
IsoControl.PacketSize =1024;
IsoControl.PacketCount = 64;
IsoControl.PipeNum = 3;
IsoControl.BufferCount =4;
IsoControl.FramesPerBuffer = 8;
ULONG nBytes=0;
bResult = DeviceIoControl (pDoc->phand,
IOCTL_Ezusb_RESETPIPE,
&IsoControl.PipeNum,
sizeof(ULONG),
NULL,
0,
&nBytes,
NULL);
if (bResult != TRUE)
{
MessageBox("初始化管道出错!","信息提示",49);
return ;
}
bResult = DeviceIoControl (pDoc->phand,
IOCTL_EZUSB_START_ISO_STREAM,
&IsoControl,
sizeof(ISO_TRANSFER_CONTROL),
NULL,
0,
&nBytes,
NULL);
if (bResult != TRUE)
{
MessageBox("初始化管道出错!","信息提示",49);
return ;
}
m_heventbuttonok=CreateEvent(NULL,true,false,NULL);
for(int i=0;i<6;i++)
m_heventdone[i]=CreateEvent(NULL,true,true,NULL);
m_hsem=CreateMutex(NULL,false,NULL);
CDisplayView *pdlg=this;
AfxBeginThread(vdatagather_iso,(LPVOID)pdlg);
AfxBeginThread(vdatashow_iso,(LPVOID)pdlg);
}
UINT vdatagather_iso(LPVOID pParam)
{
//iso_数据采集
CDisplayView *pdlg=(CDisplayView *)pParam;
if(pdlg==NULL||
!pdlg->IsKindOf(RUNTIME_CLASS(CDisplayView)))
return 2;
ResetEvent(pdlg->m_heventdone[0]);
while(WaitForSingleObject(pdlg->m_heventbuttonok,0)!=WAIT_OBJECT_0)
{
if(WaitForSingleObject(pdlg->m_hsem,INFINITE)==WAIT_OBJECT_0)
{
LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) pdlg->GetDocument()->m_hDib);
pDib+=pdlg->GetDocument()->length;
// ISO_TRANSFER_CONTROL IsoControl;
ULONG count=0;
BOOL bResult=false;
// perform the ISO transfer
ISO_TRANSFER_CONTROL IsoControl;
// ULONG packetsRead;
// PUSBD_ISO_PACKET_DESCRIPTOR isoDesc;
// ULONG i;
// PUCHAR ptr;
ULONG pass = 0;
ULONG framesRead = 0;
ULONG missedFrames = 0;
ULONG errorFrames = 0;
IsoControl.PacketSize =1024;
IsoControl.PacketCount =1024;
IsoControl.PipeNum = 3;
IsoControl.BufferCount =4;
IsoControl.FramesPerBuffer =8;
ULONG nBytes=0;
PUCHAR buffer = NULL;
ULONG bytesToRead;
bytesToRead = IsoControl.PacketCount *
(IsoControl.PacketSize + sizeof(USBD_ISO_PACKET_DESCRIPTOR));
buffer = (PUCHAR) malloc(bytesToRead);
if (!buffer)
{
MessageBox(NULL,"内存溢出!","信息提示",MB_OK);
return 3;
}
bResult = DeviceIoControl (pdlg->GetDocument()->phand,
IOCTL_EZUSB_READ_ISO_BUFFER,
&IsoControl,
sizeof(ISO_TRANSFER_CONTROL),
buffer,
bytesToRead,
&nBytes,
NULL);
if (bResult != TRUE)
{
MessageBox(NULL,"读数据错误!","信息提示",MB_OK);
return 3;
}
bResult = DeviceIoControl (pdlg->GetDocument()->phand,
IOCTL_Ezusb_RESETPIPE,
&IsoControl.PipeNum,
sizeof(ULONG),
NULL,
0,
&nBytes,
NULL);
if (bResult != TRUE)
{
MessageBox(NULL,"初始化管道出错!","信息提示",49);
return 3;
}
free(buffer);
pdlg->SetRedraw(true);
pdlg->Invalidate(false);
}
//添加代码
::GlobalUnlock((HGLOBAL) pdlg->GetDocument()->m_hDib);
// Sleep(10);
ReleaseMutex(pdlg->m_hsem);
}
SetEvent(pdlg->m_heventdone[0]);
return 0;
}
//
UINT vdatashow_iso(LPVOID pParam)
{
//数据显示
CDisplayView *pdlg=(CDisplayView *)pParam;
if(pdlg==NULL||
!pdlg->IsKindOf(RUNTIME_CLASS(CDisplayView)))
return 2;
ResetEvent(pdlg->m_heventdone[1]);
while(WaitForSingleObject(pdlg->m_heventbuttonok,0)!=WAIT_OBJECT_0)
{
if(WaitForSingleObject(pdlg->m_hsem,INFINITE)==WAIT_OBJECT_0)
{
//添加代码
LPSTR pDib = (LPSTR) ::GlobalLock((HGLOBAL) pdlg->GetDocument()->m_hDib);
pdlg->m_tmp++;
BULK_TRANSFER_CONTROL bulk;
WORD inPacketSize=64;
int i;
// int sucess;
unsigned char write_buf[64];
ULONG nBytes=0;
bulk.pipeNum=0;
for(i=0;i<64;i++)
write_buf[i]=pdlg->m_tmp;
/* sucess=DeviceIoControl
(pdlg->GetDocument()->phand,IOCTL_EZUSB_BULK_WRITE,
&bulk,
sizeof(BULK_TRANSFER_CONTROL),
write_buf,
inPacketSize,
&nBytes,
NULL);
if(!sucess)
{
MessageBox(NULL,"写数据错误!","信息提示",MB_OK);
return 3;
}*/
}
//添加代码
::GlobalUnlock((HGLOBAL) pdlg->GetDocument()->m_hDib);
// Sleep(10);
ReleaseMutex(pdlg->m_hsem);
}
SetEvent(pdlg->m_heventdone[1]);
return 0;
}
void CDisplayView::OnDebug()
{
// TODO: Add your command handler code here
// control *debug=new control(this);
// debug->Create(IDD_DIALOG1);
// debug->ShowWindow(SW_SHOW);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -