|
开发板上有几个跳线,我写了一个测试的程序,却出问题了,大家帮忙看看...
跳线驱动部分内容:
BOOL Addr_Init()
{
//地址映射
}
BOOL WINAPI DllEntry(HANDLE hInstDll,DWORD dwReason,LPVOID lpvReserved)
{
}
DWORD JMP_Init(DWORD dwContext)
{
Addr_Init();
return 1;
}
DWORD JMP_Deinit(DWORD dwContext)
{
//取消地址映射,释放内存等
}
DWORD JMP_Open(DWORD hDeviceContext,DWORD AccessCode,DWORD ShareMode)
{
//相关引脚的初始化
return 1;
}
BOOL JMP_Close(DWORD hOpenContext)
{
//还原引脚状态
}
BOOL JMP_IOControl(DWORD hOpenContext,
DWORD dwCode,
PBYTE pBufIn,
DWORD dwLenIn,
PBYTE pBufOut,
DWORD dwLenout,
PDWORD pdwActualOut
)
{
//这个部分返回引脚状态
unsigned int pin = 0;
pin = g_pPIOB->PIO_PDSR & JUMP_MASK;
pin = pin ^ JUMP_MASK;
*((unsigned int *)pBufOut) = pin;
return 1;
}
测试程序部分,一个按钮触发测试,有一个线程调用ReadJumphread检测。如下
HANDLE hFile = NULL; //设备文件操作句柄
HANDLE ExitThreadEvent;
BOOL CJump_TestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
ExitThreadEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
DWORD CJump_TestDlg::ReadJumphread(PVOID pArg)
{
CString strCount;
static unsigned int flag = 0xff;
unsigned long Size =0;
unsigned int Jump = 0;
CJump_TestDlg *pDlg = (CJump_TestDlg *)pArg;
CStatic * pTestStatic = (CStatic *)pDlg ->GetDlgItem(IDC_JUMP);
while(1)
{
if(WaitForSingleObject(ExitThreadEvent,0) == WAIT_OBJECT_0)
{ ResetEvent(ExitThreadEvent);
strCount.Format(_T("%s"), _T("kill thread "));
pTestStatic->SetWindowText(strCount);
break;
}
else
{
DeviceIoControl(hFile,0,NULL,0,&Jump,sizeof(unsigned int),&Size,NULL);
if(Jump == flag)
continue;
else
{
if(Jump == 0)
{
strCount.Format(_T("%s"), _T("JUMP 0 1 2 3 opened "));
pTestStatic->SetWindowText(strCount);
}
else if(Jump == (1<<6))
{
strCount.Format(_T("%s"), _T("JUMP 0 closed 1 2 3 opened "));
pTestStatic->SetWindowText(strCount);
}
else if(Jump == (1<<7))
{
strCount.Format(_T("%s"), _T("JUMP 1 closed 0 2 3 opened "));
pTestStatic->SetWindowText(strCount);
}
else if(Jump == (1<<8))
{
strCount.Format(_T("%s"), _T("JUMP 2 closed 0 1 3 opened "));
pTestStatic->SetWindowText(strCount);
}
else if(Jump == (1<<10))
{
strCount.Format(_T("%s"), _T("JUMP 3 closed 0 1 2 opened "));
pTestStatic->SetWindowText(strCount);
}
Size =0;
flag = Jump;
}
}
}
return 1;
}
void CJump_TestDlg::OnOpen()
{
// TODO: Add your control notification handler code here
hFile = CreateFile(TEXT("JMP0:"),GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
if(hFile == NULL)
{
MessageBox(_T("不能打开JMP"));
}
else
{
MessageBox(_T("打开JMP成功"));
}
}
void CJump_TestDlg::OnTest()
{
// TODO: Add your control notification handler code here
HANDLE hJumpTestThread ;
DWORD IDThread;
hJumpTestThread = CreateThread(0,0,ReadKeyThread,this,0,&IDThread);
if(hJumpTestThread == NULL)
{
CloseHandle(hFile);
hFile = NULL;
return ;
}
CloseHandle(hJumpTestThread);
}
void CJump_TestDlg::OnClose()
{
// TODO: Add your control notification handler code here
SetEvent(ExitThreadEvent);
KillThread = 1;
Sleep(200);
if(hFile)
{
CloseHandle(hFile);
hFile = NULL;
MessageBox(_T("关闭JMP"));
}
}
void CJump_TestDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
CloseHandle(ExitThreadEvent);
}
现象:完成一次测试后,点击关闭驱动的按钮,弹出对话框后,触摸屏没有反应了。界面也停留不动了,但是用鼠标还是可以关闭之前的界面。
完成一次测试,点击关闭驱动后,在点打开驱动,开始测试,无法得到测试结果...
好多天了,可能就是那一个地方我给弄错了,可是就是没有找出来,高分求救,等......
|
|