📄 rwdlg.cpp
字号:
value=m_value;
mth.InputBuffer.CharData =value;
gCS.Unlock();
mth.InputBuffer.PortNumber=m_port;
mth.DataLength = sizeof(ULONG) +
sizeof(mth.InputBuffer.CharData);
mth.IoctlResult = DeviceIoControl(
mth.hndFile, // Handle to device
mth.IoctlCode, // IO Control code for Write
&mth.InputBuffer, // Buffer to driver. Holds port & data.
mth.DataLength, // Length of buffer in bytes.
NULL, // Buffer from driver. Not used.
0, // Length of buffer in bytes.
&mth.ReturnedLength, // Bytes placed in outbuf. Should be 0.
NULL // NULL means wait till I/O completes.
);
UpdateData(FALSE);
// TODO: Add your control notification handler code here
}
VOID CALLBACK timerAPCProc(
LPVOID lpArgToCompletionRoutine,
DWORD dwTimerLowValue,
DWORD dwTimerHighValue
)
{
Cmethoda *mth;
mth=(Cmethoda *)(lpArgToCompletionRoutine);
if(count==0)
{
CloseHandle(
*mth->htimer // handle to object to close
);
}
//CancelWaitableTimer(
// HANDLE hTimer // handle to a timer object
//);
}
UINT Setfqy(LPVOID pParam)
{
CRwDlg * pdlg;
pdlg=(CRwDlg *)AfxGetApp()->m_pMainWnd;
double fqy;
fqy=pdlg->m_f;
if(fqy>10000||fqy<=0)
{
CString str;
str="频率不在0到10000Hz之间";
AfxMessageBox(str);
return 0;
}
double n;
n=(double)(1/(2*fqy));
Cmethoda mth;
// mth.htimer=&htimer;
mth.IoctlCode = IOCTL_GPD_WRITE_PORT_UCHAR;
mth.hndFile=pdlg->hndFile;
mth.bit=0;
mth.DataLength = sizeof(ULONG) +
sizeof(mth.InputBuffer.CharData);
gCS.Lock();
mth.m_bitcounta=pdlg->m_bitcount;
mth.InputBuffer.PortNumber=pdlg->m_port;
gCS.Unlock();
LARGE_INTEGER lCnt1,lFr,lCnt2;
double f1,f2;
double fTime=0;
QueryPerformanceFrequency(&lFr); //得到计数器的频率
f2=lFr.QuadPart;
QueryPerformanceCounter(&lCnt1); //起始记时
while(count==1)
{
//SwitchToThread();//防止线程占用100%的资源
if(fTime>n)
{
QueryPerformanceCounter(&lCnt1); //起始记时
mth.not(&(mth.bit));
gCS.Lock();
// AfxMessageBox("lai");
mth.bitTOchar(&value, mth.m_bitcounta,mth.bit);
mth.InputBuffer.CharData = value;
mth.IoctlResult = DeviceIoControl(
mth.hndFile, // Handle to device
mth.IoctlCode, // IO Control code for Write
&(mth.InputBuffer), // Buffer to driver. Holds port & data.
mth.DataLength, // Length of buffer in bytes.
NULL, // Buffer from driver. Not used.
0, // Length of buffer in bytes.
&(mth.ReturnedLength), // Bytes placed in outbuf. Should be 0.
NULL
);// NULL means wait till I/O completes.
gCS.Unlock();
}
SwitchToThread();
QueryPerformanceCounter(&lCnt2);
SwitchToThread();
f1=lCnt2.QuadPart-lCnt1.QuadPart;
fTime=(double)(f1/f2); //fTime就是所用的时间
}
pdlg->UpdateData(FALSE);
return 0;
}
UINT Setbittime(LPVOID pParam)
{
Cmethoda mth;
mth.IoctlCode = IOCTL_GPD_WRITE_PORT_UCHAR;
CRwDlg * pdlg;
pdlg=(CRwDlg *)AfxGetApp()->m_pMainWnd;
mth.hndFile=pdlg->hndFile;
mth.DataLength = sizeof(ULONG) +
sizeof(mth.InputBuffer.CharData);
gCS.Lock();
mth.m_bitcounta=pdlg->m_bitcount;
mth.InputBuffer.PortNumber=pdlg->m_port;
mth.bit=pdlg->m_bitvalue;
gCS.Unlock();
int icount,icount1;
icount1=0;
icount=1;
double n;
long n1;
n=pdlg->m_t;
if(n==0)
{
CString str1;
str1="时间不能为零";
AfxMessageBox(str1);
return 0;
}
n1=(long)(n*1000-1);
while(icount==1)
{
gCS.Lock();
mth.bitTOchar(&value, mth.m_bitcounta,mth.bit);
mth.InputBuffer.CharData = value;
mth.IoctlResult = DeviceIoControl(
mth.hndFile, // Handle to device
mth.IoctlCode, // IO Control code for Write
&mth.InputBuffer, // Buffer to driver. Holds port & data.
mth.DataLength, // Length of buffer in bytes.
NULL, // Buffer from driver. Not used.
0, // Length of buffer in bytes.
&mth.ReturnedLength, // Bytes placed in outbuf. Should be 0.
NULL // NULL means wait till I/O completes.
);
gCS.Unlock();
mth.not(&mth.bit);
Sleep(n1);
++icount1;
if(icount1==2)
{
pdlg->UpdateData(FALSE);
break;
}
}
pdlg->UpdateData(FALSE);
return 0;
}
void CRwDlg::OnButton3()
{
UpdateData(TRUE);
AfxBeginThread(Setbittime, this , THREAD_PRIORITY_HIGHEST);// TODO: Add your control notification handler code here
UpdateData(FALSE); // TODO: Add your control notification handler code here
}
void CRwDlg::OnButton4()
{
UpdateData(TRUE);
Cmethoda mth;
mth.m_bitcounta=m_bitcount;
mth.bit=m_bitvalue;
mth.hndFile=hndFile;
mth.bitTOchar(&value, mth.m_bitcounta,mth.bit);
mth.IoctlCode = IOCTL_GPD_WRITE_PORT_UCHAR;
mth.InputBuffer.CharData = value;
mth.InputBuffer.PortNumber=m_port;
mth.DataLength = sizeof(ULONG) +
sizeof(mth.InputBuffer.CharData);
mth.IoctlResult = DeviceIoControl(
mth.hndFile, // Handle to device
mth.IoctlCode, // IO Control code for Write
&mth.InputBuffer, // Buffer to driver. Holds port & data.
mth.DataLength, // Length of buffer in bytes.
NULL, // Buffer from driver. Not used.
0, // Length of buffer in bytes.
&mth.ReturnedLength, // Bytes placed in outbuf. Should be 0.
NULL // NULL means wait till I/O completes.
);
UpdateData(FALSE);
// TODO: Add your control notification handler code here
// TODO: Add your control notification handler code here
}
void CRwDlg::OnButton5()
{
UpdateData(TRUE);
Cmethoda mth;
gCS.Lock();
m_bitvalue=mth.readbitfromchar(&value, m_bitcount);
gCS.Unlock();
UpdateData(FALSE);
// TODO: Add your control notification handler code here
}
void CRwDlg::OnButton1()
{
UpdateData(TRUE);
gCS.Lock();
count=1;
gCS.Unlock();
AfxBeginThread(Setfqy, this , THREAD_PRIORITY_NORMAL); // TODO: Add your control notification handler code here
}
void CRwDlg::OnButton2()
{
gCS.Lock();
count=0;
gCS.Unlock();
UpdateData(FALSE); // TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -