📄 portsettings.cpp
字号:
/**************************************************************************
Project: WinAVRIDE Class: Serial Port Settings Dialog
Copyright (C) 2005 Philipp Schober
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
History
19.Feb 2005 - First Release (V1.0)
****************************************************************************/
#include <vcl.h>
#pragma hdrstop
#include "PortSettings.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TPortSet *PortSet;
//---------------------------------------------------------------------------
__fastcall TPortSet::TPortSet(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TPortSet::ShowWindow (void)
{
Position = poScreenCenter;
switch (Baudrate)
{
case 110: BaudBox->ItemIndex = 0;
break;
case 300: BaudBox->ItemIndex = 1;
break;
case 600: BaudBox->ItemIndex = 2;
break;
case 1200: BaudBox->ItemIndex = 3;
break;
case 2400: BaudBox->ItemIndex = 4;
break;
case 4800: BaudBox->ItemIndex = 5;
break;
case 9600: BaudBox->ItemIndex = 6;
break;
case 14400: BaudBox->ItemIndex = 7;
break;
case 19200: BaudBox->ItemIndex = 8;
break;
case 28800: BaudBox->ItemIndex = 9;
break;
case 38400: BaudBox->ItemIndex = 10;
break;
case 56000: BaudBox->ItemIndex = 11;
break;
case 57600: BaudBox->ItemIndex = 12;
break;
case 115200: BaudBox->ItemIndex = 13;
break;
default: BaudBox->ItemIndex = 6;
}
if (Databits < 5 || Databits > 8) Databits = 8;
DataGroup->ItemIndex = Databits - 5;
switch (Parity)
{
case 'O':
case 'o': ParityGroup->ItemIndex = 1;
break;
case 'E':
case 'e': ParityGroup->ItemIndex = 2;
break;
case 'M':
case 'm': ParityGroup->ItemIndex = 3;
break;
default: ParityGroup->ItemIndex = 0; // No Parity as default
}
/*switch (Stopbits)
{
case 15: StopGroup->ItemIndex = 1;
break;
case 20: StopGroup->ItemIndex = 2;
break;
default: StopGroup->ItemIndex = 0; // 1 Stopbit as default
}*/
if (Stopbits == 20) StopGroup->ItemIndex = 2;
else StopGroup->ItemIndex = 0;
switch (Flow)
{
case fcXFlow: FlowGroup->ItemIndex = 1;
break;
case fcRTSCTS: FlowGroup->ItemIndex = 2;
break;
case fcDTRDSR: FlowGroup->ItemIndex = 3;
break;
default: FlowGroup->ItemIndex = 0;
}
ShowModal ();
}
//---------------------------------------------------------------------------
void __fastcall TPortSet::OkButtonClick(TObject *Sender)
{
switch (BaudBox->ItemIndex)
{
case 0: Baudrate = 110;
break;
case 1: Baudrate = 300;
break;
case 2: Baudrate = 600;
break;
case 3: Baudrate = 1200;
break;
case 4: Baudrate = 2400;
break;
case 5: Baudrate = 4800;
break;
case 6: Baudrate = 9600;
break;
case 7: Baudrate = 14400;
break;
case 8: Baudrate = 19200;
break;
case 9: Baudrate = 28800;
break;
case 10: Baudrate = 38400;
break;
case 11: Baudrate = 56000;
break;
case 12: Baudrate = 57600;
break;
case 13: Baudrate = 115200;
break;
}
Databits = DataGroup->ItemIndex + 5;
switch (ParityGroup->ItemIndex)
{
case 0: Parity = 'N';
break;
case 1: Parity = 'O';
break;
case 2: Parity = 'E';
break;
case 3: Parity = 'M';
break;
}
switch (StopGroup->ItemIndex)
{
case 0: Stopbits = 10;
break;
/*case 1: Stopbits = 15;
break;*/
case 1: Stopbits = 20;
break;
}
switch (FlowGroup->ItemIndex)
{
case 0: Flow = fcNone;
break;
case 1: Flow = fcXFlow;
break;
case 2: Flow = fcRTSCTS;
break;
case 3: Flow = fcDTRDSR;
break;
}
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TPortSet::CancelClick(TObject *Sender)
{
ModalResult = mrCancel;
}
//---------------------------------------------------------------------------
void __fastcall TPortSet::BaudBoxKeyPress(TObject *Sender, char &Key)
{
Key = 0;
}
//---------------------------------------------------------------------------
void __fastcall TPortSet::BaudBoxKeyBlock(TObject *Sender, WORD &Key,
TShiftState Shift)
{
Key = 0;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -