📄 mainform.cpp
字号:
txtDiInterrupt4->Text = IntToStr(m_DI4Count);
break;
case ADS_EVT_INTERRUPT_DI5:
m_DI5Count++;
txtDiInterrupt5->Text = IntToStr(m_DI5Count);
break;
case ADS_EVT_INTERRUPT_DI6:
m_DI6Count++;
txtDiInterrupt6->Text = IntToStr(m_DI6Count);
break;
case ADS_EVT_INTERRUPT_DI7:
m_DI7Count++;
txtDiInterrupt7->Text = IntToStr(m_DI7Count);
break;
default :
break;
}
}
return true;
}
void __fastcall TfrmMain::cmdExitClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::lstDiSignalCondition7Click(TObject *Sender)
{
m_DITriggerMode=0;
for(int i=0;i<8;i++)
m_DITriggerMode = m_DITriggerMode | (lstDiSignalCondition[i]->ItemIndex << i);
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiTriggerSignals, &m_DITriggerMode, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::lstDiSignalCondition6Click(TObject *Sender)
{
m_DITriggerMode=0;
for(int i=0;i<8;i++)
m_DITriggerMode = m_DITriggerMode | (lstDiSignalCondition[i]->ItemIndex << i);
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiTriggerSignals, &m_DITriggerMode, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::lstDiSignalCondition5Click(TObject *Sender)
{
m_DITriggerMode=0;
for(int i=0;i<8;i++)
m_DITriggerMode = m_DITriggerMode | (lstDiSignalCondition[i]->ItemIndex << i);
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiTriggerSignals, &m_DITriggerMode, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::lstDiSignalCondition4Click(TObject *Sender)
{
m_DITriggerMode=0;
for(int i=0;i<8;i++)
m_DITriggerMode = m_DITriggerMode | (lstDiSignalCondition[i]->ItemIndex << i);
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiTriggerSignals, &m_DITriggerMode, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::lstDiSignalCondition3Click(TObject *Sender)
{
m_DITriggerMode=0;
for(int i=0;i<8;i++)
m_DITriggerMode = m_DITriggerMode | (lstDiSignalCondition[i]->ItemIndex << i);
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiTriggerSignals, &m_DITriggerMode, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::lstDiSignalCondition2Click(TObject *Sender)
{
m_DITriggerMode=0;
for(int i=0;i<8;i++)
m_DITriggerMode = m_DITriggerMode | (lstDiSignalCondition[i]->ItemIndex << i);
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiTriggerSignals, &m_DITriggerMode, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::lstDiSignalCondition1Click(TObject *Sender)
{
m_DITriggerMode=0;
for(int i=0;i<8;i++)
m_DITriggerMode = m_DITriggerMode | (lstDiSignalCondition[i]->ItemIndex << i);
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiTriggerSignals, &m_DITriggerMode, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::lstDiSignalCondition0Click(TObject *Sender)
{
m_DITriggerMode=0;
for(int i=0;i<8;i++)
m_DITriggerMode = m_DITriggerMode | (lstDiSignalCondition[i]->ItemIndex << i);
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiTriggerSignals, &m_DITriggerMode, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::txtPatternMatchValueChange(TObject *Sender)
{
long lStart;
long lLength;
String sHex;
//
// Bound the Pattern Match value in 0 ~ FFFFFFFFh
//
if (strlen(txtPatternMatchValue->Text.c_str()) > 8)
{
// Out of value bound
lStart = txtPatternMatchValue->SelStart;
lLength = txtPatternMatchValue->SelLength;
if(lStart != 0)
lStart--;
txtPatternMatchValue->Text = IntToHex(txtPatternMatchValue->Tag, 2);
txtPatternMatchValue->SelStart = lStart;
txtPatternMatchValue->SelLength = lLength;
}
if(strlen(txtPatternMatchValue->Text.c_str()) == 0)
{
// 0 Value
txtPatternMatchValue->Text = "0";
txtPatternMatchValue->SelStart = 0;
}
//
// Valid Patterm Match value,write this new property value to device.
//
sHex = "0x" + txtPatternMatchValue->Text;
lStart = StrToInt(sHex);
txtPatternMatchValue->Tag = lStart;
m_MatchValue = lStart;
//
// Before setting CFG_DiPatternMatchValue, the user must set CFG_DioFdioDirection
// and CFG_DiPacerSource.
// CFG_DioFdioDirection can be set 32-bit DI, 16-bit DIO or 8-bit DIO, depending
// on the data wides.
// NOTE: 32-bit DO is not support.
// If the user doesn't choose a pacer clock, 10MHz internal pacer clock is the default.
//
DWORD dwDioFdioDirection, dwDiPacerSource;
dwDioFdioDirection = 0; // 32-bit DI
m_ErrCde = DRV_DeviceSetProperty(m_DeviceHandle, CFG_DioFdioDirection, &dwDioFdioDirection, 4);
dwDiPacerSource = 3; // 10MHz
m_ErrCde = DRV_DeviceSetProperty(m_DeviceHandle, CFG_DiPacerSource, &dwDiPacerSource, 4);
// PM
m_ErrCde = DRV_DeviceSetProperty(m_DeviceHandle, CFG_DiPatternMatchValue, &m_MatchValue, 4);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::txtPatternMatchValueKeyPress(TObject *Sender,
char &Key)
{
//
// Key pressing filter, only passing 0-9, A-F and backspace keys
//
if(Key >= '0' && Key <= '9')
return;
if(Key == 8)
return;
if(Key >= 'A' && Key <= 'F')
return;
if(Key >= 'a' && Key <= 'f')
{
Key = Key + 'A' - 'a';
return;
}
Key = 0;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormClose(TObject *Sender, TCloseAction &Action)
{
DWORD ExitCode;
if ( m_DeviceHandle!= NULL )
{
if(pThread)
{
GetExitCodeThread((void *)pThread->Handle,&ExitCode);
if(ExitCode==STILL_ACTIVE)
TerminateThread((void *)pThread->Handle,ExitCode);
}
DRV_DeviceClose( &m_DeviceHandle );
}
}
//---------------------------------------------------------------------------
void TfrmMain::EnableControls(bool bEnabled)
{
//TODO: Add your source code here
chkTimer->Enabled = bEnabled;
txtCounterEvent->Enabled = bEnabled;
txtCounterValue->Enabled = bEnabled;
// Pattern match interrupt event controls enable or disable
chkFDiPatternMatch->Enabled = bEnabled;
txtPatternMatchEvent->Enabled = bEnabled;
txtPatternMatchValue->Enabled = bEnabled;
// Status change interrupt event controls enable or disable
chkStatusChange->Enabled = bEnabled;
txtStatusChangeEvent->Enabled = bEnabled;
txtChangeStatusChannel->Enabled = bEnabled;
// Auxiliary DI interrupt event controls enable or disable
for (int i = 0; i < 8; i++)
{
lstDiSignalCondition[i]->Enabled = bEnabled;
chkDiInterrupt[i]->Enabled = bEnabled;
txtDiInterrupt[i]->Enabled = bEnabled;
}
// Execution controls enable and disable
cmdStart->Enabled = bEnabled;
cmdStop->Enabled = False;
}
void __fastcall TfrmMain::txtCounterValueChange(TObject *Sender)
{
//
// Check value boundary and set counter 2 value to device.
// Counter 2 is the timer interrupt source, base frequency on 10 Mhz.
//
DWORD dwData[3];
DWORD dwCount;
long dwLength;
long lStart;
long lLength;
if(txtCounterValue->Text.Length() == 0 )
txtCounterValue->Text="2";
lStart = txtCounterValue->SelStart;
lLength = txtCounterValue->SelLength;
//
// Bound the input value between 2 ~ 65535.
//
if(StrToInt(txtCounterValue->Text) < 2)
{
txtCounterValue->Text = IntToStr(txtCounterValue->Tag);
txtCounterValue->SelStart = 0;
txtCounterValue->SelLength = 5;
}
else if(StrToInt(txtCounterValue->Text) > 65535)
{
if(lStart != 0)
lStart--;
txtCounterValue->Text = IntToStr(txtCounterValue->Tag);
txtCounterValue->SelStart = lStart;
txtCounterValue->SelLength = lLength;
}
else
{
//
// Counter 2 value chaged, write new value to device.
//
txtCounterValue->Tag = StrToInt(txtCounterValue->Text);
// Write setting to device's counter1.
dwCount = sizeof(DWORD)*3;
DRV_DeviceGetProperty(m_DeviceHandle, CFG_CounterCountValue, &(dwData[0]), &dwCount);
dwData[2] = txtCounterValue->Tag;
DRV_DeviceSetProperty(m_DeviceHandle, CFG_CounterCountValue, &(dwData[0]), dwCount);
txtCounterValue->Text = txtCounterValue->Tag;
txtCounterValue->SelStart = lStart;
txtCounterValue->SelLength = lLength;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::txtChangeStatusChannelChange(TObject *Sender)
{
long lStart;
long lLength;
long lValue;
//
// Change status channel setting.
//
if(txtChangeStatusChannel->Text.Length() == 0 )
txtChangeStatusChannel->Text="0";
lValue = StrToInt(txtChangeStatusChannel->Text);
if(lValue > 31)
{
// Out of value bound, only support upto 31 DI channel
lStart = txtChangeStatusChannel->SelStart;
lLength = txtChangeStatusChannel->SelLength;
if(lStart != 0)
lStart --;
txtChangeStatusChannel->Text = IntToStr(txtChangeStatusChannel->Tag);
txtChangeStatusChannel->SelStart = lStart;
txtChangeStatusChannel->SelLength = lLength;
return;
}
if(lValue == 0)
{
// 0 Value
txtChangeStatusChannel->Text = "0";
txtChangeStatusChannel->SelStart = 0;
}
//
// Before setting CFG_IrqDiChangeStatusChannel, the user must set CFG_DioFdioDirection
// and CFG_DiPacerSource.
// CFG_DioFdioDirection can be set 32-bit DI, 16-bit DIO or 8-bit DIO, depending
// on the channel which the user want to monitor.
// NOTE: 32-bit DO is not support.
// If the user doesn't choose a pacer clock, 10MHz internal pacer clock is the default.
//
DWORD dwDioFdioDirection, dwDiPacerSource;
dwDioFdioDirection = 0; // 32-bit DI
m_ErrCde = DRV_DeviceSetProperty(m_DeviceHandle, CFG_DioFdioDirection, &dwDioFdioDirection, 4);
dwDiPacerSource = 3; // 10MHz
m_ErrCde = DRV_DeviceSetProperty(m_DeviceHandle, CFG_DiPacerSource, &dwDiPacerSource, 4);
// Write Change status channel property to device driver.
txtChangeStatusChannel->Tag = lValue;
DRV_DeviceSetProperty(m_DeviceHandle, CFG_IrqDiChangeStatusChannel, &lValue, 4);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -