1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
const int cTimer1 = 1;
const int cTimer2 = 1;
void CENVSConfigDlg::OnBnClickedButton1()
{
SetTimer(cTimer1,1000,NULL);
}
void CENVSConfigDlg::OnBnClickedButton2()
{
KillTimer(cTimer1);
}
void CENVSConfigDlg::OnBnClickedButton3()
{
SetTimer(cTimer2,10,NULL);
}
void CENVSConfigDlg::OnBnClickedButton4()
{
KillTimer(cTimer2);
}
void CENVSConfigDlg::OnTimer(UINT_PTR ID){
if(ID==cTimer1){
char buffer[30],tempStr[5];
int sensor[6];
DWORD nbytes;
MessageBeep(0);
//Read Sensors
if(!WriteFile( hnd_serial, "1", 1, &nbytes, NULL )){KillTimer(cTimer1);MessageBox(L"Write Com Port fail!");return;}
Sleep(30);
if(!ReadFile( hnd_serial, buffer, 30, &nbytes, NULL )){KillTimer(cTimer1);MessageBox(L"Read Com Port fail!");return;}
Sleep(300);
if(ID==cTimer2)
{
if(GetAsyncKeyState(0x53) != 0)
{
DWORD nbytes;
if(!WriteFile( hnd_serial, "s", 1, &nbytes, NULL )){MessageBox(L"Write Com Port fail!");return;}
Sleep(30);
tampil.SetWindowText( (LPCTSTR)"s" ); //backward
}
else if(GetAsyncKeyState(0x57) != 0)
{
DWORD nbytes;
if(!WriteFile( hnd_serial, "w", 1, &nbytes, NULL )){MessageBox(L"Write Com Port fail!");return;}
Sleep(30);
tampil.SetWindowText( (LPCTSTR)"w" );//forward
}
}
}
}
|