📄 sstardlg.cpp
字号:
// -----------------------------
// Initialize Input Channel Edit
// -----------------------------
itoa(gwChannel, szBuffer, 10);
SendDlgItemMessage(IDC_EDIT_CHANNEL, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
// ------------------------------------------------------------
// Initialize Input Range List Combobox, it needs to get device
// features for gain list
// ------------------------------------------------------------
// first : Open Device
if (gnNumOfSubdevices == 0)
{
ErrCde = DRV_DeviceOpen(DeviceList[gwDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
}
else
{
ErrCde = DRV_DeviceOpen(
SubDeviceList[gwSubDevice].dwDeviceNum,
(LONG far *)&DriverHandle);
}
if (ErrCde != SUCCESS)
{
strcpy(szErrMsg,"Device open error !");
MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
return 0;
}
// second: get device features
ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
ptDevFeatures.size = sizeof(DEVFEATURES);
if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,
(LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
// third: initialize Input Range List Combobox with device features
if (DevFeatures.usNumGain != 0)
{
// EnableWindow(GetDlgItem(IDC_COMBO_RANGE), TRUE);
SendDlgItemMessage(IDC_COMBO_RANGE, CB_RESETCONTENT,
0, (LPARAM)((LPSTR)0));
for (i = 0; i < (int)DevFeatures.usNumGain; i ++)
SendDlgItemMessage(IDC_COMBO_RANGE, CB_ADDSTRING, 0,
(LPARAM)((LPSTR)(DevFeatures.glGainList[i].szGainStr)));
SendDlgItemMessage(IDC_COMBO_RANGE,
CB_SELECTSTRING, (WPARAM)(-1),
(LPARAM)((LPSTR)(DevFeatures.glGainList[gwGain].szGainStr)));
}
else
{
// EnableWindow(GetDlgItem( IDC_COMBO_RANGE), FALSE);
SendDlgItemMessage(IDC_COMBO_RANGE, CB_RESETCONTENT,
0, (LPARAM)((LPSTR)0));
}
// fourth: close device
DRV_DeviceClose((LONG far *)&DriverHandle);
//////////////////////////////////////////////////////////////////////////
// ---------------------------------------------------
// Initialize Scan Time Edit, Maximum accuracy: 40 ms
// ---------------------------------------------------
itoa(gwScanTime, szBuffer, 10);
SendDlgItemMessage(IDC_EDIT_SCANTIME, EM_REPLACESEL, 0,
(LPARAM)((LPSTR)szBuffer));
return TRUE;
}
BOOL CSSTARDlg::OnButStart()
{
// TODO: Add your control notification handler code here
if (gnNumOfSubdevices == 0)
{
ErrCde = DRV_DeviceOpen(DeviceList[gwDevice].dwDeviceNum,(LONG far *)&DriverHandle);
}
else
{
ErrCde = DRV_DeviceOpen(SubDeviceList[gwSubDevice].dwDeviceNum,(LONG far *)&DriverHandle);
}
if (ErrCde != SUCCESS)
{
strcpy(szErrMsg,"Device open error !");
MessageBox((LPCSTR)szErrMsg,"Device Open",MB_OK);
return 0;
}
//
// get gain code
//
ptDevFeatures.buffer = (LPDEVFEATURES)&DevFeatures;
ptDevFeatures.size = sizeof(DEVFEATURES);
if ((ErrCde = DRV_DeviceGetFeatures(DriverHandle,(LPT_DeviceGetFeatures)&ptDevFeatures)) != SUCCESS)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
//
// configures the gain for the specifed analog input channel
//
ptAIConfig.DasGain = DevFeatures.glGainList[gwGain].usGainCde;
ptAIConfig.DasChan = gwChannel;
if ((ErrCde = DRV_AIConfig(DriverHandle,(LPT_AIConfig)&ptAIConfig)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
//
// enable Stop Menu item and disable the others
//
// EnableMenuItem(hMenu, IDM_STOP, MF_BYCOMMAND | MF_ENABLED);
// EnableMenuItem(hMenu, IDM_START, MF_BYCOMMAND | MF_GRAYED);
//
// Set the new timer type and start it up.
//
if (SetTimer(1, gwScanTime, NULL) == (UINT)NULL)
{
MessageBox("Couldn't create timer.", "Notice!",
MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
bRun = TRUE;
gdwStartTime = GetTickCount();
gwOverrunCount = 0;
//////////////////////////////////////////////////////////////////////////
m_button_Stop.EnableWindow(true);
m_button_Start.EnableWindow(false);
return 0;
}
BOOL CSSTARDlg::OnButStop()
{
// TODO: Add your control notification handler code here
KillTimer(1);
DRV_DeviceClose((LONG far *)&DriverHandle);
m_button_Stop.EnableWindow(false);
m_button_Start.EnableWindow(true);
return true;
}
void CSSTARDlg::OnButDeivceset()
{/*
gwDevice =m_comboDeviceList.GetCurSel();//(unsigned short)atof(str_comboDeviceList);
// get sub-device selection
gwSubDevice = m_comboModuleList.GetCurSel();//(unsigned short)atof(str_comboModuleList);
// get channel number
m_editChannel.GetWindowText(str_editChannel);
gwChannel = (unsigned short)atof(str_editChannel);
// get input range selection
gwGain = m_comboRangeList.GetCurSel();//(unsigned short)atof(str_comboRangeList);
*/
//
// get device selection
//
if ((dwIndex = SendDlgItemMessage(IDC_COMBO_DEVICE,
CB_GETCURSEL, 0, 0)) != CB_ERR)
gwDevice = (WORD)dwIndex;
//
// get sub-device selection
//
if ((dwIndex = SendDlgItemMessage(IDC_COMBO_MODULE,
CB_GETCURSEL, 0, 0)) != CB_ERR)
gwSubDevice = (WORD)dwIndex;
//
// get channel number
//
if (SendDlgItemMessage(IDC_EDIT_CHANNEL,
EM_GETMODIFY, 0, 0))
{
SendDlgItemMessage(IDC_EDIT_CHANNEL,
WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
gwChannel = atoi(szBuffer);
SendDlgItemMessage(IDC_EDIT_CHANNEL,
EM_SETMODIFY, FALSE, 0) ;
}
//
// get input range selection
//
if ((dwIndex = SendDlgItemMessage(IDC_COMBO_RANGE,
CB_GETCURSEL, 0, 0)) != CB_ERR)
gwGain = (WORD)dwIndex;
}
void CSSTARDlg::OnButScanset()
{
// get scan time
/*
m_editScantime.GetWindowText(str_editScantime);
gwScanTime = (unsigned short)atof(str_editScantime);
*/
if (SendDlgItemMessage(IDC_EDIT_SCANTIME,EM_GETMODIFY, 0, 0))
{
SendDlgItemMessage(IDC_EDIT_SCANTIME,WM_GETTEXT, 10, (LPARAM)(LPSTR)szBuffer) ;
gwScanTime = atoi(szBuffer);
SendDlgItemMessage(IDC_EDIT_SCANTIME,EM_SETMODIFY, FALSE, 0) ;
}
}
void CSSTARDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case 1:
disposal_time();
break;
default:
break;
}
CDialog::OnTimer(nIDEvent);
}
BOOL CSSTARDlg::disposal_time()
{
dwCurrentTime = GetTickCount();
gdwElapseTime = gdwElapseTime + (DWORD)gwScanTime;
dwErrorTime = dwCurrentTime - gdwElapseTime - gdwStartTime;
if (dwErrorTime > (DWORD)40) // maximum 40 ms scan time
{
gdwElapseTime = dwCurrentTime - gdwStartTime;
gwOverrunCount ++;
if (gwOverrunCount >= 10)
{
bTimerOverrun = TRUE;
gwOverrunCount = 0;
}
else
bTimerOverrun = FALSE;
}
else
{
bTimerOverrun = FALSE;
gwOverrunCount = 0;
}
//
// reads an analog input channel
//
ptAIVoltageIn.chan = gwChannel;
ptAIVoltageIn.gain = ptAIConfig.DasGain;
ptAIVoltageIn.TrigMode = 0; // internal trigger
ptAIVoltageIn.voltage = (FLOAT far *)&fVoltage;
if ((ErrCde = DRV_AIVoltageIn(DriverHandle,
(LPT_AIVoltageIn)&ptAIVoltageIn)) != 0)
{
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
KillTimer(1);
MessageBox((LPCSTR)szErrMsg,"Driver Message",MB_OK);
DRV_DeviceClose((LONG far *)&DriverHandle);
return 0;
}
//
// Display Data
//
/*
hdc = GetDC();
GetClientRect(NULL, &rect);
InvalidateRect(NULL, NULL, TRUE);
UpdateWindow(NULL);
if (bTimerOverrun == FALSE)
sprintf(szBuffer, "data = %10.6f", fVoltage);
else
sprintf(szBuffer, "Timer Overrun!\n data = %10.6f", fVoltage);
DrawText(hdc, szBuffer, -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
ReleaseDC(NULL, hdc);
return 0;
*/
if (bTimerOverrun == FALSE)
sprintf(szBuffer, "data = %10.6f", fVoltage);
else
sprintf(szBuffer, "Timer Overrun!\n data = %10.6f", fVoltage);
m_editShow.SetWindowText(szBuffer);
strtemp.Format("%f",fVoltage);
//判断是否需要存储数据
if(p_Button_needsave->GetCheck())
{
AddRecord(strtemp);
}
return true;
}
void CSSTARDlg::OnCancel()
{
// TODO: Add extra cleanup here
if (AdoData != NULL)
{
delete AdoData;
AdoData = NULL;
}
CDialog::OnCancel();
}
void CSSTARDlg::AddRecord(CString str)
{
CString strUSB4711A[2];
int i=0;
CTime tm = CTime::GetCurrentTime();
//CSSTARDlg *pDlg = (CSSTARDlg *)this->GetParent();
strtemp.Format("%04d-%02d-%02d %02d:%02d:%02d",tm.GetYear(),tm.GetMonth(),tm.GetDay(),
tm.GetHour(),tm.GetMinute(),tm.GetSecond());
str_fVoltage=str;
m_USB4711A.SetAt(0,strtemp);
m_USB4711A.SetAt(1,str_fVoltage);
for(i=0;i<2;i++)
{
strUSB4711A[i] = m_USB4711A.GetAt(i);
}
AdoData->Add(0,strUSB4711A);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -