//---------------------------------------------------------------------------
#ifndef SerialH
#define SerialH
//---------------------------------------------------------------------------
enum TBaudRate{br110=CBR_110,br300=CBR_300,br600=CBR_600,
  br1200=CBR_1200,br2400=CBR_2400,br4800=CBR_4800,br9600=CBR_9600,
  br19200=CBR_19200,br38400=CBR_38400,br56000=CBR_56000,
  br57600=CBR_57600,br115200=CBR_115200,br128000=CBR_128000,
  br256000=CBR_256000};
enum TParity{pEven=EVENPARITY,pMark=MARKPARITY,
  pNo=NOPARITY,pOdd=ODDPARITY};
enum TStopBits{sb10=ONESTOPBIT,sb15=ONE5STOPBITS,
  sb20=TWOSTOPBITS};
enum TByteSize{bs4=4,bs5=5,bs6=6,bs7=7,bs8=8};
//---------------------------------------------------------------------------
class TConfigPanel;
//---------------------------------------------------------------------------
class TSerial:public TObject{
public:
  __fastcall TSerial(int Number);
  __fastcall TSerial();
  __fastcall ~TSerial();
  int __fastcall WriteByte(Byte byte);
  int __fastcall WriteChar(char Char);
  int __fastcall WriteString(const AnsiString& String);
  int __fastcall ReadByte(Byte* byte);
  int __fastcall ReadChar(char* Char);
  int __fastcall ReadString(AnsiString& String,int Length);
  void __fastcall PurgeInput();
  void __fastcall SetupComm(DWORD InQueue,DWORD OutQueue);
  __property HANDLE Handle=
    {read=FHandle};
  __property int Number=
    {read=FNumber};
  __property TBaudRate BaudRate=
    {read=GetBaudRate,write=SetBaudRate};
  __property TParity Parity=
    {read=GetParity,write=SetParity};
  __property TStopBits StopBits=
    {read=GetStopBits,write=SetStopBits};
  __property TByteSize ByteSize=
    {read=GetByteSize,write=SetByteSize};
  __property bool CTS={read=GetCTS};
  __property bool DSR={read=GetDSR};
  __property bool RING={read=GetRING};
  __property bool RLSD={read=GetRLSD};
  __property bool DTR={write=SetDTR};
  __property bool RTS={write=SetRTS};
  __property bool TxD={write=SetTxD};
  __property DWORD InputQueue={read=GetInputQueue};
  __property DWORD OutputQueue={read=GetOutputQueue};
  __property DWORD ReadIntervalTimeout=
    {read=GetRIT,write=SetRIT};
  __property DWORD ReadTotalTimeoutMultiplier=
    {read=GetRTTM,write=SetRTTM};
  __property DWORD ReadTotalTimeoutConstant=
    {read=GetRTTC,write=SetRTTC};
  __property DWORD WriteTotalTimeoutMultiplier=
    {read=GetWTTM,write=SetWTTM};
  __property DWORD WriteTotalTimeoutConstant=
    {read=GetWTTC,write=SetWTTC};
private:
  friend class TConfigPanel;
  TConfigPanel *ConfigPanel;
  HANDLE FHandle;
  int FNumber;
  DCB dcb;
  COMMTIMEOUTS to;
  DWORD EventMask;
  void __fastcall GetDCB();
  void __fastcall SetDCB();
  DWORD __fastcall gms();
  bool __fastcall GetCTS();
  bool __fastcall GetDSR();
  bool __fastcall GetRING();
  bool __fastcall GetRLSD();
  void __fastcall SetDTR(bool Status);
  void __fastcall SetRTS(bool Status);
  void __fastcall SetTxD(bool Status);
  DWORD __fastcall GetInputQueue();
  DWORD __fastcall GetOutputQueue();
  DWORD __fastcall GetRIT();
  DWORD __fastcall GetRTTM();
  DWORD __fastcall GetRTTC();
  DWORD __fastcall GetWTTM();
  DWORD __fastcall GetWTTC();
  void __fastcall SetRIT(DWORD Timeout);
  void __fastcall SetRTTM(DWORD Timeout);
  void __fastcall SetRTTC(DWORD Timeout);
  void __fastcall SetWTTM(DWORD Timeout);
  void __fastcall SetWTTC(DWORD Timeout);
  TBaudRate __fastcall GetBaudRate();
  void __fastcall SetBaudRate(TBaudRate ABaudRate);
  TParity __fastcall GetParity();
  void __fastcall SetParity(TParity AParity);
  TStopBits __fastcall GetStopBits();
  void __fastcall SetStopBits(TStopBits AStopBits);
  TByteSize __fastcall GetByteSize();
  void __fastcall SetByteSize(TByteSize AByteSize);
};
//---------------------------------------------------------------------------
class TConfigPanel:public TObject{
private:
  TComboBox *cbBaudRate,
    *cbParity,*cbStopBits,*cbByteSize;
  TLabel *lBaudRate,
    *lParity,*lStopBits,*lByteSize;  
  TSerial *Serial;
  bool FAutoSet;
  void __fastcall Change(TObject *Sender);
public:
  __fastcall TConfigPanel(TWinControl* Owner,
    int X, int Y,TSerial *Serial);
  void __fastcall SaveChanges(bool Save);
  void __fastcall Update();
  __fastcall ~TConfigPanel();
  __property bool AutoSet=
    {read=FAutoSet,write=AutoSet,default=true};
};
//---------------------------------------------------------------------------
#endif
