📄 untsmscontrol.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UntSMSControl.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SPComm"
#pragma link "CSPIN"
#pragma resource "*.dfm"
TfrmControl *frmControl;
//---------------------------------------------------------------------------
__fastcall TfrmControl::TfrmControl(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmControl::meoContentChange(TObject *Sender)
{
//
CodeStyle = "";
if (meoContent->Text.Length() == 0)
{
lblCurCode->Caption = "";
return;
}
for (int i = 1; i <= meoContent->Text.Length(); i++)
{
if (((unsigned char)meoContent->Text[i]) > 127)
// || (((unsigned char)meoContent->Text[i]) < 0) )
{
CodeStyle = _ud;
//meoContent->MaxLength = 140;
lblCurCode->Caption = "编码模式:Unicode,剩余字数:"
+ IntToStr(70 - ((WideString)meoContent->Text).Length());
break;
}
}
if (CodeStyle != _ud)
{
CodeStyle = _b7;
//meoContent->MaxLength = 160;
lblCurCode->Caption = "编码模式:Bit7,剩余字数:"
+ IntToStr(160 - meoContent->Text.Length());
}
}
//---------------------------------------------------------------------------
bool __fastcall TfrmControl::CheckStatus(void)
{
if (!com_open)
{
Application->MessageBox("相应的模块连接错误,执行操作失败!"
, "操作提示", MB_ICONERROR + MB_OK);
return false;
}
return true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmControl::LoadErrInfo(void)
{
TListItem *Item;
AnsiString Tmp = "";
TStrings *Cur = new TStringList();
try
{
Cur->LoadFromFile("sms.err");
for (int i = 0; i < Cur->Count; i++)
{
Tmp = Cur->Strings[i];
Item = lvErrorInfo->Items->Add();
Item->Caption = Tmp.SubString(0, Tmp.Pos("|") - 1);
Tmp = Tmp.SubString(Tmp.Pos("|") + 1, Tmp.Length());
Item->SubItems->Add(Tmp.SubString(0, Tmp.Pos("|") - 1));
Tmp = Tmp.SubString(Tmp.Pos("|") + 1, Tmp.Length());
Item->SubItems->Add(Tmp.SubString(0, Tmp.Pos("|") - 1));
Tmp = Tmp.SubString(Tmp.Pos("|") + 1, Tmp.Length());
Item->SubItems->Add(Tmp);
}
}
__finally
{
delete Cur;
}
}
void __fastcall TfrmControl::FormShow(TObject *Sender)
{
LoadErrInfo();
pcInfo->ActivePageIndex = 2;
cbCommChange(cbComm);
}
//---------------------------------------------------------------------------
void __fastcall TfrmControl::timExecuteTimer(TObject *Sender)
{
//AT+CSQ
switch(re_type)
{
case _r_ok: //设置发送模式。
{
timExecute->Enabled = false;
rec_tmp = rec_msg;
if (rec_tmp.Pos("OK") > 0)
{
SetEventResult(uid, "成功");
can_next = true;
}
else if (rec_tmp.Pos("ERROR") > 0)
{
SetEventResult(uid, "失败");
can_next = true;
}
else
{
wait_timeout++;
if (wait_timeout > CSpinEdit1->Value)
{
SetEventResult(uid, "失败!超时...");
can_next = true;
return;
}
timExecute->Enabled = true;
}
break;
}
case _r_unread:
{
timExecute->Enabled = false;
rec_tmp = rec_msg;
if (rec_tmp.Pos("OK") > 0)
{
SetEventResult(uid, "成功");
edtNumber->Text = IntToStr(GetPosDegree("+CMGL", rec_tmp));
Memo1->Lines->Clear();
Memo1->Lines->Text = rec_tmp;
can_next = true;
}
else if (rec_tmp.Pos("ERROR") > 0)
{
SetEventResult(uid, "失败");
edtNumber->Text = "失败";
can_next = true;
}
else
{
wait_timeout++;
if (wait_timeout > CSpinEdit2->Value)
{
SetEventResult(uid, "失败!超时...");
can_next = true;
return;
}
timExecute->Enabled = true;
}
break;
}
case _r_reread:
{
timExecute->Enabled = false;
rec_tmp = rec_msg;
if (rec_tmp.Pos("OK") > 0)
{
SetEventResult(uid, "成功");
edtNumber2->Text = IntToStr(GetPosDegree("+CMGL", rec_tmp));
Memo1->Lines->Clear();
Memo1->Lines->Text = rec_tmp;
can_next = true;
}
else if (rec_tmp.Pos("ERROR") > 0)
{
SetEventResult(uid, "失败");
edtNumber->Text = "失败";
can_next = true;
}
else
{
wait_timeout++;
if (wait_timeout > CSpinEdit2->Value)
{
SetEventResult(uid, "失败!超时...");
can_next = true;
return;
}
timExecute->Enabled = true;
}
break;
}
case _g_center:
{
timExecute->Enabled = false;
rec_tmp = rec_msg;
if (rec_tmp.Pos("OK") > 0)
{
SetEventResult(uid, "成功");
//处理返回值。
edtCenter->Text = GetCenter(rec_tmp);
can_next = true;
}
else if (rec_tmp.Pos("ERROR") > 0)
{
SetEventResult(uid, "失败");
edtNumber->Text = "失败";
can_next = true;
}
else
{
wait_timeout++;
if (wait_timeout > CSpinEdit1->Value)
{
SetEventResult(uid, "失败!超时...");
can_next = true;
return;
}
timExecute->Enabled = true;
}
break;
}
case _g_model:
{
timExecute->Enabled = false;
rec_tmp = rec_msg;
if (rec_tmp.Pos("OK") > 0)
{
SetEventResult(uid, "成功");
//处理返回值。
if (GetSendModal(rec_tmp) == 0)
rbPdu->Checked = true;
else
rbText->Checked = true;
can_next = true;
}
else if (rec_tmp.Pos("ERROR") > 0)
{
SetEventResult(uid, "失败");
edtNumber->Text = "失败";
can_next = true;
}
else
{
wait_timeout++;
if (wait_timeout > CSpinEdit1->Value)
{
SetEventResult(uid, "失败!超时...");
can_next = true;
return;
}
timExecute->Enabled = true;
}
break;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmControl::cbCommChange(TObject *Sender)
{
try
{
if (com_open)
{
spComm->StopComm();
com_open = false;
}
spComm->CommName = cbComm->Text;
spComm->StartComm();
com_open = true;
can_next = true;
sbInfo->Panels->Items[0]->Text = cbComm->Text + "端口打开成功!";
}
catch(...)
{
com_open = false;
sbInfo->Panels->Items[0]->Text = cbComm->Text + "端口打开失败!";
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmControl::FormClose(TObject *Sender, TCloseAction &Action)
{
//
if (com_open)
spComm->StopComm();
}
//---------------------------------------------------------------------------
void __fastcall TfrmControl::Button1Click(TObject *Sender)
{
char p[512] = {'\0'};
unsigned short e, h;
encode_bit7(p, edtAscII->Text.c_str(), &e, &h);
edtCode->Text = p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmControl::Button2Click(TObject *Sender)
{
//
char p[512] = {'\0'};
decode_bit7(p, edtCode->Text.c_str());
edtSource->Text = p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmControl::Button8Click(TObject *Sender)
{
char p[512] = {'\0'};
unsigned short e, h;
encode_unicode(p, Edit2->Text.c_str(), &e, &h);
Edit4->Text = p;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -