⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitcommset.cpp

📁 BCB串口通讯控件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
     EditAutoAns->SetFocus();
     Application->MessageBox(Msg.ErrInvAAns.c_str(),Caption.c_str(),MB_OK|MB_ICONSTOP);
     return;
   }

  //输入缓存
  try
   {
     s = EditInBufSize->Text.Trim();
     if(s.IsEmpty())
       throw Exception(Msg.ErrInvInBuf);
     NewInBufSize = StrToInt(s);
     if(NewInBufSize<4096)
       throw Exception(Msg.ErrInvInBuf);
   }
  catch(Exception &e)
   {
     EditInBufSize->SetFocus();
     Application->MessageBox(Msg.ErrInvInBuf.c_str(),Caption.c_str(),MB_OK|MB_ICONSTOP);
     return;
   }

  //输出缓存
  try
   {
     s = EditOutBufSize->Text.Trim();
     if(s.IsEmpty())
       throw Exception(Msg.ErrInvOutBuf);
     NewOutBufSize = StrToInt(s);
     if(NewOutBufSize<4096)
       throw Exception(Msg.ErrInvOutBuf);
   }
  catch(Exception &e)
   {
     EditOutBufSize->SetFocus();
     Application->MessageBox(Msg.ErrInvOutBuf.c_str(),Caption.c_str(),MB_OK|MB_ICONSTOP);
     return;
   }

  //设置参数
  try
   {
     _YbCommDevice->PortNo      = NewPortNo;
     _YbCommDevice->Baud        = NewBaud;
     _YbCommDevice->Parity      = NewParity;
     _YbCommDevice->ByteSize    = NewByteSize;
     _YbCommDevice->StopBits    = NewStopBits;
     _YbCommDevice->FlowControl = NewFlowControl;
     _YbCommDevice->AutoAnswer  = NewAutoAAns;
     _YbCommDevice->InBufSize   = NewInBufSize;
     _YbCommDevice->OutBufSize  = NewOutBufSize;
     _YbCommDevice->Active      = _OldActive||_ForceActive;
     ModalResult = IDOK;
   }
  catch(Exception &e)
   {
     try
      {
        _YbCommDevice->PortNo      = _OldPortNo;
        _YbCommDevice->Baud        = _OldBaud;
        _YbCommDevice->Parity      = _OldParity;
        _YbCommDevice->ByteSize    = _OldByteSize;
        _YbCommDevice->StopBits    = _OldStopBits;
        _YbCommDevice->FlowControl = _OldFlowControl;
        _YbCommDevice->AutoAnswer  = _OldAutoAAns;
        _YbCommDevice->InBufSize   = _OldInBufSize;
        _YbCommDevice->OutBufSize  = _OldOutBufSize;
        _YbCommDevice->Active      = _OldActive;
      }
     catch(...)
      {
        //do nothing, ignore this error
      }
     CbPort->SetFocus();
     MessageBox(Handle, e.Message.c_str(), Caption.c_str(), MB_OK|MB_ICONSTOP);
   }
}
//---------------------------------------------------------------------------
bool __fastcall TFormCommSettings::MoveCtrlFocus(void)
{
  if(ActiveControl == CbPort       ){ ActiveControl = CbSelBaud     ; return true; }
  if(ActiveControl == CbSelBaud    ){ ActiveControl = CbParity      ; return true; }
  if(ActiveControl == CbParity     ){ ActiveControl = CbByteSize    ; return true; }
  if(ActiveControl == CbByteSize   ){ ActiveControl = CbStopBits    ; return true; }
  if(ActiveControl == CbStopBits   ){ ActiveControl = CbFlow        ; return true; }
  if(ActiveControl == CbFlow       ){ ActiveControl = EditAutoAns   ; return true; }
  if(ActiveControl == EditAutoAns  ){ ActiveControl = EditInBufSize ; return true; }
  if(ActiveControl == EditInBufSize){ ActiveControl = EditOutBufSize; return true; }
  return false;
}
//---------------------------------------------------------------------------
void __fastcall TFormCommSettings::BnCancelClick(TObject *Sender)
{
  ModalResult = IDCANCEL;
}
//---------------------------------------------------------------------------
__fastcall TFormCommSettings::TMsgStrings::TMsgStrings()
{
  switch(AppLang.LangType)
   {
     case TAppLang::ltGbk:
          _Msg = _Msg_Chs;
          break;

     case TAppLang::ltBig5:
          _Msg = _Msg_Cht;
          break;

     default:
          _Msg = _Msg_Enu;
          break;
   }
}
//---------------------------------------------------------------------------
AnsiString __fastcall TFormCommSettings::TMsgStrings::fGetMsg(int mt)
{
  return AppLang.FromGBK(_Msg[mt]);
}
//---------------------------------------------------------------------------
char *TFormCommSettings::TMsgStrings::_Msg_Chs[] =
{
  "确定"                         , // 0 MsgOK
  "取消"                         , // 1 MsgCancel
  "端口设置"                     , // 2 MsgPortSet
  "端口"                         , // 3 MsgPort
  "波特率"                       , // 4 MsgBaud
  "奇偶校验"                     , // 5 MsgCheck
  "数据位"                       , // 6 MsgBits
  "停止位"                       , // 7 MsgStops
  "数据流控"                     , // 8 MsgFlow
  "No parity (无)"               , // 9 MsgNoParity
  "Odd (奇)"                     , //10 MsgOdd
  "Even (偶)"                    , //11 MsgEven
  "Mark (标记)"                  , //12 MsgMark
  "None (无)"                    , //13 MsgNone
  "RTS/CTS (硬件)"               , //14 MsgRtsCts
  "Xon/Xoff (软件)"              , //15 MsgXonXoff
  "RTS/CTS & Xon/Xoff (硬&软)"   , //16 MsgRtsXon
  "必须选择端口"                 , //17 ErrSelPort
  "必须输入/选择波特率"          , //18 ErrSelBaud
  "无效的波特率"                 , //19 ErrInvBaud
  "必须选择数据位"               , //20 ErrSelBits
  "必须选择奇偶校验"             , //21 ErrSelCheck
  "必须选择停止位"               , //22 ErrSelStops
  "必须选择数据流控制"           , //23 ErrSelFlow
  "关于"                         , //24 MsgAbout
  "默认"                         , //25 MsgDefault
  "端口选项"                     , //26 StrGbxBase
  "调制解调器选项"               , //27 StrGbxModem
  "缓存容量"                     , //28 StrGbxBuffer
  "自动应答"                     , //29 MsgAAns
  "输入缓存"                     , //30 MsgInBuf
  "输出缓存"                     , //31 MsgOutBuf
  "自动应答必须是 0 - 255 的整数", //32 ErrInvAAns
  "输入缓存容量错误"             , //33 ErrInvInBuf
  "输出缓存容量错误"             , //34 ErrInvOutBuf
  "Space (空格)"                 , //35 MsgSpacePty
};
//---------------------------------------------------------------------------
char *TFormCommSettings::TMsgStrings::_Msg_Cht[] =
{
  "確定"                         , // 0 MsgOK
  "取消"                         , // 1 MsgCancel
  "串列埠設置"                   , // 2 MsgPortSet
  "串 列 埠"                     , // 3 MsgPort
  "傳輸速率"                     , // 4 MsgBaud
  "奇偶校驗"                     , // 5 MsgCheck
  "資料位元"                     , // 6 MsgBits
  "停止位元"                     , // 7 MsgStops
  "資料流控"                     , // 8 MsgFlow
  "No parity (無)"               , // 9 MsgNoParity
  "Odd (奇)"                     , //10 MsgOdd
  "Even (偶)"                    , //11 MsgEven
  "Mark (標記)"                  , //12 MsgMark
  "None (無)"                    , //13 MsgNone
  "RTS/CTS (硬體)"               , //14 MsgRtsCts
  "Xon/Xoff (軟體)"              , //15 MsgXonXoff
  "RTS/CTS & Xon/Xoff (硬&軟)"   , //16 MsgRtsXon
  "必須選擇串列埠"               , //17 ErrSelPort
  "必須輸入/選擇串列傳輸速率"    , //18 ErrSelBaud
  "無效的串列傳輸速率"           , //19 ErrInvBaud
  "必須選擇資料位元"             , //20 ErrSelBits
  "必須選擇奇偶校驗"             , //21 ErrSelCheck
  "必須選擇停止位元"             , //22 ErrSelStops
  "必須選擇資料流程控制"         , //23 ErrSelFlow
  "關於"                         , //24 MsgAbout
  "默認"                         , //25 MsgDefault
  "埠選項"                       , //26 StrGbxBase
  "數據機選項"                   , //27 StrGbxModem
  "緩存容量"                     , //28 StrGbxBuffer
  "自動回應"                     , //29 MsgAAns
  "輸入緩存"                     , //30 MsgInBuf
  "輸出緩存"                     , //31 MsgOutBuf
  "自動回應必須是 0 - 255 的整數", //32 ErrInvAAns
  "輸入緩存容量錯誤"             , //33 ErrInvInBuf
  "輸出緩存容量錯誤"             , //34 ErrInvOutBuf
  "Space (空白)"                 , //35 MsgSpacePty
};
//---------------------------------------------------------------------------
char *TFormCommSettings::TMsgStrings::_Msg_Enu[] =
{
  "&OK"                       , // 0 MsgOK
  "&Cancel"                   , // 1 MsgCancel
  "COM port Setup"            , // 2 MsgPortSet
  "COM port"                  , // 3 MsgPort
  "Baud"                      , // 4 MsgBaud
  "Parity"                    , // 5 MsgCheck
  "Byte Size"                 , // 6 MsgBits
  "Stop Bits"                 , // 7 MsgStops
  "Flow Control"              , // 8 MsgFlow
  "No parity"                 , // 9 MsgNoParity
  "Odd"                       , //10 MsgOdd
  "Even"                      , //11 MsgEven
  "Mark"                      , //12 MsgMark
  "None"                      , //13 MsgNone
  "RTS/CTS"                   , //14 MsgRtsCts
  "Xon/Xoff"                  , //15 MsgXonXoff
  "RTS/CTS & Xon/Xoff"        , //16 MsgRtsXon
  "Must select COM Port"      , //17 ErrSelPort
  "Must select baud rate"     , //18 ErrSelBaud
  "Invalid baud rate"         , //19 ErrInvBaud
  "Must select byte size"     , //20 ErrSelBits
  "Must select parity check"  , //21 ErrSelCheck
  "Must select stop bits"     , //22 ErrSelStops
  "Must select flow control"  , //23 ErrSelFlow
  "&About"                    , //24 MsgAbout
  "&Default"                  , //25 MsgDefault
  "Port"                      , //26 StrGbxBase
  "Modem"                     , //27 StrGbxModem
  "Buffer"                    , //28 StrGbxBuffer
  "Auto Answer"               , //29 MsgAAns
  "Input Buf."                , //30 MsgInBuf
  "Output Buf."               , //31 MsgOutBuf
  "Auto Answer: 0 - 255"      , //32 ErrInvAAns
  "Input Buffer size error"   , //33 ErrInvInBuf
  "Output Buffer size error"  , //34 ErrInvOutBuf
  "Space Parity"              , //35 MsgSpacePty
};
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -