settingform.cpp
来自「16 relay output channels and 16 isolated」· C++ 代码 · 共 238 行
CPP
238 行
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "SettingForm.h"
#include "MainForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmSetting *frmSetting;
//---------------------------------------------------------------------------
__fastcall TfrmSetting::TfrmSetting(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::FormShow(TObject *Sender)
{
// initialize data width
if ( frmMain->dwDataWidth == 0 ) // 32-bit
RadioDataWidth32->Checked = TRUE;
else if ( frmMain->dwDataWidth == 2 ) // 16-bit
RadioDataWidth16->Checked = TRUE;
else // 8-bit
RadioDataWidth8->Checked = TRUE;
// initialize start type
if ( frmMain->dwDIStartMode == 1 ) // software
RadioStartTypeSoftware->Checked = TRUE;
if ( frmMain->dwDIStartMode == 2 ) // External
RadioStartTypeExt->Checked = TRUE;
if ( frmMain->dwDIStartMode == 3 ) // Pattern Match
RadioStartMatch->Checked = TRUE;
// initialize operation type
if ( frmMain->dwDIOperationMode == 0 ) // normal
radNormal->Checked = TRUE;
if ( frmMain->dwDIOperationMode == 1 ) // 8255
rad8255->Checked = TRUE;
if (frmMain->dwDIOperationMode == 2 ) // burst
radBurst->Checked = TRUE;
// initialize stop type
if ( frmMain->dwDIStopMode == 1 ) // software
RadioStopTypeSoftware->Checked = TRUE ;
if ( frmMain->dwDIStopMode == 2 ) // External
RadioStopTypeExt->Checked = TRUE;
if ( frmMain->dwDIStopMode == 3 ) // Pattern Match
RadioStopMatch->Checked = TRUE;
// initialize cycle mod
if ( frmMain->dwCyclicMode == 0 ) // nocyclic
RadioNonCyclic->Checked = TRUE;
else
RadioCyclic->Checked = TRUE;
// initialize trigger source listbox
ListBoxTriggerSource->ItemIndex = frmMain->dwDITriggerSource - 1;
// initialize counter 0 value
EditCounterValue->Text = IntToStr(frmMain->dwCounterValue[0]);
// initialize the user buffer
ListBoxUserBuffer->ItemIndex = frmMain->dwUserBufferSize;
// initialize the Pattern match value
txtPattern->Text = IntToHex((__int64)frmMain->dwDIMatchValue,2);
// initialize DI DMA mode
if (frmMain->dwBoardId == BD_MIC3755 )
{
if (frmMain->dwDiDmaMode == 0)
RadioDmaSlave->Checked = true;
if (frmMain->dwDiDmaMode == 1)
RadioDmaMaster->Checked = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::ButtonOKClick(TObject *Sender)
{
// save the data width
if (RadioDataWidth32->Checked) // 32-bit
frmMain->dwDataWidth = 0;
else if (RadioDataWidth16->Checked) //16-bit
frmMain->dwDataWidth = 2;
else
frmMain->dwDataWidth = 3;
// save operation type
if (radNormal->Checked) // normal
frmMain->dwDIOperationMode = 0;
if (rad8255->Checked) // 8255
frmMain->dwDIOperationMode = 1;
if (radBurst->Checked) // burst
frmMain->dwDIOperationMode = 2;
// save the start type
if (RadioStartTypeSoftware->Checked) // software
frmMain->dwDIStartMode = 1;
if (RadioStartTypeExt->Checked) // External
frmMain->dwDIStartMode = 2;
if (RadioStartMatch->Checked) // Pattern match
frmMain->dwDIStartMode = 3;
// save the stop type
if (RadioStopTypeSoftware->Checked) // software
frmMain->dwDIStopMode = 1;
if (RadioStopTypeExt->Checked) // External
frmMain->dwDIStopMode = 2;
if (RadioStopMatch->Checked) // Pattern match
frmMain->dwDIStopMode = 3;
// save the cyclic mode
if (RadioCyclic->Checked) // cyclic
frmMain->dwCyclicMode = 1;
else
frmMain->dwCyclicMode = 0;
// save the trigger source
frmMain->dwDITriggerSource = ListBoxTriggerSource->ItemIndex + 1;
// save the counter 0 value
frmMain->dwCounterValue[0] = StrToInt(EditCounterValue->Text);
// save the user bufer
frmMain->dwUserBufferSize = ListBoxUserBuffer->ItemIndex;
// save the Pattern match value
frmMain->dwDIMatchValue = StrToInt("0x"+txtPattern->Text);
// save DMA mode
if (frmMain->dwBoardId == BD_MIC3755)
{
if (RadioDmaSlave->Checked)
frmMain->dwDiDmaMode = 0;
else
frmMain->dwDiDmaMode = 1;
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::txtPatternChange(TObject *Sender)
{
int DataWidth=0;
long lStart,lLength;
//ound the Pattern Match value in 0 ~ FFFFFFFFh
if (RadioDataWidth32->Checked) // 32-bit
DataWidth = 8;
else if (RadioDataWidth16->Checked) //16-bit
DataWidth = 4;
else
DataWidth = 2;
if (txtPattern->Text.Length() > DataWidth)
{
//Out of value bound
lStart = txtPattern->SelStart;
lLength = txtPattern->SelLength;
if( lStart !=0 )
lStart = lStart - 1;
txtPattern->Text = IntToHex(txtPattern->Tag,DataWidth);
txtPattern->SelStart = lStart;
txtPattern->SelLength = lLength ;
}
if (txtPattern->Text.Length() == 0)
{
// 0 Value
txtPattern->Text = "0";
txtPattern->SelStart = 0;
}
// Valid Patterm Match value,write this new property value to device.
lStart = StrToInt("0x" + txtPattern->Text);
txtPattern->Tag = lStart;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::txtPatternKeyPress(TObject *Sender, char &Key)
{
int i;
if ((Key >= '0') && (Key <= '9') )
return;
if ( (Key >= 'A') && (Key <= 'F') )
return;
if ( (Key >= 'a') && (Key <= 'f') )
{
for (i = 0; i<Byte('a') - Byte('A'); i++)
Key=Key-1;
return;
}
Key =0;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::radBurstClick(TObject *Sender)
{
if (frmMain->dwBoardId == BD_PCI1755)
ListBoxTriggerSource->ItemIndex=4;
if (frmMain->dwBoardId == BD_MIC3755)
{
RadioDmaSlave->Enabled = true;
RadioDmaMaster->Enabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::rad8255Click(TObject *Sender)
{
RadioDmaSlave->Enabled = false;
RadioDmaMaster->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::radNormalClick(TObject *Sender)
{
RadioDmaSlave->Enabled = false;
RadioDmaMaster->Enabled = false;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?