settingform.cpp
来自「16 relay output channels and 16 isolated」· C++ 代码 · 共 235 行
CPP
235 行
//---------------------------------------------------------------------------
#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;
if ( frmMain->dwDataWidth == 1 ) // 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->dwDOStartMode == 1 ) // software
RadioStartTypeSoftware->Checked = TRUE;
if ( frmMain->dwDOStartMode == 2 ) // External
RadioStartTypeExt->Checked = TRUE;
// initialize operation type
if ( frmMain->dwDOOperationMode == 0 ) // normal
radNormal->Checked = TRUE;
if ( frmMain->dwDOOperationMode == 1 ) // 8255
rad8255->Checked = TRUE;
if (frmMain->dwDOOperationMode == 2 ) // burst
radBurst->Checked = TRUE;
// initialize stop type
if ( frmMain->dwDOStopMode == 1 ) // software
RadioStopTypeSoftware->Checked = TRUE ;
if ( frmMain->dwDOStopMode == 2 ) // External
RadioStopTypeExt->Checked = TRUE;
// initialize cycle mod
if ( frmMain->dwCyclicMode == 0 ) // nocyclic
RadioNonCyclic->Checked = TRUE;
else
RadioCyclic->Checked = TRUE;
// initialize trigger source listbox
ListBoxTriggerSource->ItemIndex = frmMain->dwDOTriggerSource - 1;
// initialize counter 0 value
EditCounterValue->Text = IntToStr(frmMain->dwCounterValue[0]);
// initialize the user buffer
ListBoxUserBuffer->ItemIndex = frmMain->dwUserBufferSize;
// initialize the Pattern match value
txtDigitalValue->Text = IntToHex((__int64)frmMain->dwDigitalValue,2);
// initialize DO DMA mode
if (frmMain->dwBoardId == BD_MIC3755 )
{
if (frmMain->dwDoDmaMode == 0)
RadioDmaSlave->Checked = true;
if (frmMain->dwDoDmaMode == 1)
RadioDmaMaster->Checked = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::ButtonOKClick(TObject *Sender)
{
// save the data width
if (RadioDataWidth32->Checked) // 32-bit
frmMain->dwDataWidth = 1;
else if (RadioDataWidth16->Checked) //16-bit
frmMain->dwDataWidth = 2;
else
frmMain->dwDataWidth = 3;
// save operation type
if (radNormal->Checked) // normal
frmMain->dwDOOperationMode = 0;
if (rad8255->Checked) // 8255
frmMain->dwDOOperationMode = 1;
if (radBurst->Checked) // burst
frmMain->dwDOOperationMode = 2;
// save the start type
if (RadioStartTypeSoftware->Checked) // software
frmMain->dwDOStartMode = 1;
if (RadioStartTypeExt->Checked) // External
frmMain->dwDOStartMode = 2;
// save the stop type
if (RadioStopTypeSoftware->Checked) // software
frmMain->dwDOStopMode = 1;
if (RadioStopTypeExt->Checked) // External
frmMain->dwDOStopMode = 2;
// save the cyclic mode
if (RadioCyclic->Checked) // cyclic
frmMain->dwCyclicMode = 1;
else
frmMain->dwCyclicMode = 0;
// save the trigger source
frmMain->dwDOTriggerSource = 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->dwDigitalValue = StrToInt("0x"+txtDigitalValue->Text);
// save DMA mode
if (frmMain->dwBoardId == BD_MIC3755)
{
if (RadioDmaSlave->Checked)
frmMain->dwDoDmaMode = 0;
else
frmMain->dwDoDmaMode = 1;
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::txtDigitalValueKeyPress(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::txtDigitalValueChange(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 (txtDigitalValue->Text.Length() > DataWidth)
{
//Out of value bound
lStart = txtDigitalValue->SelStart;
lLength = txtDigitalValue->SelLength;
if( lStart !=0 )
lStart = lStart - 1;
txtDigitalValue->Text = IntToHex(txtDigitalValue->Tag,DataWidth);
txtDigitalValue->SelStart = lStart;
txtDigitalValue->SelLength = lLength ;
}
if (txtDigitalValue->Text.Length() == 0)
{
// 0 Value
txtDigitalValue->Text = "0";
txtDigitalValue->SelStart = 0;
}
// Valid Patterm Match value,write this new property value to device.
lStart = StrToInt("0x" + txtDigitalValue->Text);
txtDigitalValue->Tag = lStart;
}
//---------------------------------------------------------------------------
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::radNormalClick(TObject *Sender)
{
RadioDmaSlave->Enabled = false;
RadioDmaMaster->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSetting::rad8255Click(TObject *Sender)
{
RadioDmaSlave->Enabled = false;
RadioDmaMaster->Enabled = false;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?