void __fastcall TFMain::CommTVReceiveData(TObject *Sender, Pointer Buffer,
WORD BufferLength)
{
unsigned char buff[10000];
String sBuff;
sBuff.SetLength(BufferLength);
Move(Buffer,buff, BufferLength);
Move(Buffer,sBuff.c_str(),BufferLength);
if(buff[0]==0x0)
return;
String data;
for(int j=0;j<BufferLength;j++)
{
data=data+","+AnsiString(buff[j]);
}
RE->Lines->Add(data+" "+AnsiString(BufferLength)+" 个 ");
if(buff[0]==0xaa)
{
char a=0xaa;
while(sBuff.Pos(AnsiString(a))!=0)
sBuff.Delete(sBuff.Pos(AnsiString(a)),1);
wsprintf(buff,sBuff.c_str());
if(sBuff.Length()>=4)
goto LongBuff;
char temp[10];
temp[0]=0x55;
for(int i=0;i<10;i++)
{
if(CommTV->WriteCommData(temp,1))
break;
Application->Hint="通信失败!请检查线路";
MessageBeep(0);
Application->ShowHint=true;
}
return;
}
if(buff[1]==0xff)
{
if(bComm)
{
char tt=0x0d;
String s=C_O_RM+AnsiString(tt);
for(int i=0;i<10;i++)
if(!CommTV->WriteCommData(s.c_str(),s.Length()))
{
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
else
break;
}
else
{
char tt=0x0c;
String s=C_O_RM+AnsiString(tt);
for(int i=0;i<10;i++)
if(!CommTV->WriteCommData(s.c_str(),s.Length()))
{
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
else
break;
}
return;
}
if(buff[0]==0xff)
{
if(bComm)
{
char tt=0x0d;
String s=C_O_RM+AnsiString(tt);
for(int i=0;i<10;i++)
if(!CommTV->WriteCommData(s.c_str(),s.Length()))
{
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
}
else
break;
}
else
{
char tt=0x0c;
String s=C_O_RM+AnsiString(tt);
for(int i=0;i<10;i++)
if(!CommTV->WriteCommData(s.c_str(),s.Length()))
{
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
else
break;
}
return;
}
if(buff[0]==0xbb)
{
Open_CloseDT();
}
if(BufferLength==4)
{
if((buff[3]==0x0d)||(buff[3]==0x0c))
{
if(buff[3]==0x0c)
{
bWarning=true;
pbWar->Show();
}
else
bWarning=false;
char a=0xbb;
char temp[10];
temp[0]=a;
for(int i=0;i<10;i++)
{
if(CommTV->WriteCommData(temp,1))
break;
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
//MainDTH=two+s[2]+s[3]+s[4];
String temp1=sBuff;
RM=temp1.SubString(1,3);
a=0x0a;
while(RM.Pos(AnsiString(a))!=0)
{
String sChange=RM;
sChange.Delete(RM.Pos(AnsiString(a)),1);
sChange.Insert("0",RM.Pos(AnsiString(a)));
RM=sChange;
}
StartCom();
return;
}
if(buff[3]==0x0f)
{
char a=0xbb;
char temp[10];
temp[0]=a;
for(int i=0;i<10;i++)
{
if(CommTV->WriteCommData(temp,1))
break;
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
StopCom();
return;
}
}
if(BufferLength==5)
{
if(buff[4]==0x0c||buff[4]==0x0d)
{
if(buff[4]==0x0c)
{
bWarning=true;
pbWar->Show();
}
else
bWarning=false;
char a=0xbb;
char temp[10];
temp[0]=a;
for(int i=0;i<10;i++)
{
if(CommTV->WriteCommData(temp,1))
break;
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
}
//MainDTH=two+s[2]+s[3]+s[4];
String temp1=sBuff;
RM=temp1.SubString(2,3);
a=0x0a;
while(RM.Pos(AnsiString(a))!=0)
{
String sChange=RM;
sChange.Delete(RM.Pos(AnsiString(a)),1);
sChange.Insert("0",RM.Pos(AnsiString(a)));
RM=sChange;
}
StartCom();
return;
}
if(buff[4]==0x0f)
{
char a=0xbb;
char temp[10];
temp[0]=a;
for(int i=0;i<10;i++)
{
if(CommTV->WriteCommData(temp,1))
break;
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
StopCom();
return;
}
}
LongBuff:
if(BufferLength>=5)
{
char a=0xaa;
while(sBuff.Pos(AnsiString(a))!=0)
sBuff.Delete(sBuff.Pos(AnsiString(a)),1);
wsprintf(buff,sBuff.c_str());
if((buff[3]==0x0d)||(buff[3]==0x0c))
{
if(buff[3]==0x0c)
{
bWarning=true;
pbWar->Show();
}
else
bWarning=false;
char a=0xbb;
char temp[10];
temp[0]=a;
for(int i=0;i<10;i++)
{
if(CommTV->WriteCommData(temp,1))
break;
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
String temp1=sBuff;
RM=temp1.SubString(1,3);
a=0x0a;
while(RM.Pos(AnsiString(a))!=0)
{
String sChange=RM;
sChange.Delete(RM.Pos(AnsiString(a)),1);
sChange.Insert("0",RM.Pos(AnsiString(a)));
RM=sChange;
}
StartCom();
return;
}
if(buff[3]==0x0f)
{
char a=0xbb;
char temp[10];
temp[0]=a;
for(int i=0;i<10;i++)
{
if(CommTV->WriteCommData(temp,1))
break;
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
StopCom();
}
}
}
//---------------------------------------------------------------------------
inline void __fastcall TFMain::StartCom()
{
if(DM->TimeSub->Enabled)
StopCom();
Lbegin
Time->Caption=Now().FormatString("yyyy-mm-dd hh:nn:ss");
if(Mainbegin
Time==Lbegin
Time->Caption)
return;
Mainbegin
Time=Lbegin
Time->Caption;
DM->TimeSub->Enabled=true;
if(!CD->QSearch->Active)
{
CD->QSearch->DatabaseName=DataPath;
CD->QSearch->SQL->Clear();
CD->QSearch->SQL->Add("SELECT DTH, CH,RM,ZT,GS");
CD->QSearch->SQL->Add("FROM 'Setdata.dbf' Setdata");
CD->QSearch->Open();
}
TLocateOptions Opts;
Opts.Clear();
Opts << loPartialKey;
if(CD->QSearch->Locate("RM",RM,Opts))
{
MainCH=CD->QSearch->FieldByName("CH")->AsString;
MainDTH=CD->QSearch->FieldByName("DTH")->AsString;
}
else
{
DM->TimeSub->Enabled=false;
return;
}
FMain->SetMyi(0);
if(bWarning)
DM->tWaring->Enabled=true;
FMain->Icon=ITray->Picture->Icon;
TrayMessage(NIM_MODIFY);
if(LY)
{
String Temp;
try{
Temp=StrToDateTime(FMain->Mainbegin
Time).FormatString("yyyy-mm-dd hhnnss");
}
catch(...)
{
MessageBeep(0);
}
String FileName=FMain->DataPath+"//"+Temp+".wav";
/*
if(FileExists(FileName))
{
Temp=Now().FormatString("yyyy-mm-dd hhnnss");
if (!Audio1->Recorder->Stop())
Memo1->Lines->Add(Audio1->ErrorMessage);
DeleteFile(FileName);
}*/
Audio1->Recorder->RecordToFile(FileName, 0,0);
StartRecClick(this);
}
LDTH->Caption=MainDTH;
LCH->Caption=MainCH;
DM->RM=RM;
}
inline void __fastcall TFMain::StopCom()
{
if(!DM->TimeSub->Enabled)
return;
DM->TimeSub->Enabled=false;
iMain->Cursor=crDefault;
SetCursorPos(iMain->ClientOrigin.x+15,iMain->ClientOrigin.y+10);
MainStopTime=Now().FormatString("yyyy-mm-dd hh:nn:ss");
FMain->Icon=Application->Icon;
TrayMessage(NIM_MODIFY);
if(pbWar->Visible)
{
pbWar->Hide();
FMain->pbWar->Canvas->Refresh();
DM->tWaring->Enabled=false;
}
String StopTime=FMain->MainStopTime;
MainTimeSub=FormatFloat("0",Time_Cmp(Mainbegin
Time.c_str(),StopTime.c_str()));
//**********************Stop
if (!Audio1->Recorder->Stop())
Memo1->Lines->Add(Audio1->ErrorMessage);
audiorecording=false;
ButtonStatus("Idle");
//*********************Stop
CD->QGetWrite->RequestLive=true;
if(!CD->QGetWrite->Active)
{
CD->QGetWrite->DatabaseName=FMain->DataPath;
CD->QGetWrite->SQL->Clear();
// CD->QGetWrite->SQL->Add("SELECT DTH, CH,BTIME, STIME,TIMESUB,WARNING");
CD->QGetWrite->SQL->Add("SELECT * ");
CD->QGetWrite->SQL->Add("FROM 'Getdata.DBF' Getdata");
CD->QGetWrite->Open();
}
try
{
CD->QGetWrite->Edit();
CD->QGetWrite->Edit();
CD->QGetWrite->Append();
CD->QGetWrite->FieldByName("DTH")->Value=FMain->MainDTH;
CD->QGetWrite->FieldByName("CH")->Value=MainCH;
CD->QGetWrite->FieldByName("BTIME")->Value=Mainbegin
Time;
CD->QGetWrite->FieldByName("STIME")->Value=StopTime;
CD->QGetWrite->FieldByName("TIMESUB")->Value=MainTimeSub.ToInt();
if(bWarning)
CD->QGetWrite->FieldByName("WARNING")->Value="报警";
else
CD->QGetWrite->FieldByName("WARNING")->Value="正常";
CD->QGetWrite->Post();
}
catch(...)
{
Application->Hint="存盘错误!";
MainHint="存盘错误!";
Application->ShowHint=true;
CD->QGetWrite->Cancel();
MessageBeep(0);
}
if(Application->Hint!="存盘错误!")
MainHint="";
//StopPlayClick(this);
if(LY)
{
static int iTempCount=0;
REFileName->Lines->Add(Mainbegin
Time);
iTempCount++;
if(iTempCount>=20)
{
RE->Lines->Clear();
iTempCount=0;
char *lpRootPathName="d://";
String sDevice=FMain->DataPath;
sprintf(lpRootPathName,"%c://",sDevice[1]);
DWORD lpSectorsPerCluster;
DWORD lpBytesPerSector;
DWORD lpNumberOfFreeClusters;
DWORD lpTotalNumberOfClusters;
GetDiskFreeSpace(lpRootPathName,&lpSectorsPerCluster,&lpBytesPerSector,&lpNumberOfFreeClusters,&lpTotalNumberOfClusters );
if(lpNumberOfFreeClusters * lpBytesPerSector * lpSectorsPerCluster/(1024.0*1024.0)<=eDiskFree->Text.ToInt())
{
TDeleteMp3 *DelMp3;
DelMp3=new TDeleteMp3(true);
DelMp3->Priority = tpLower;
// set the priority lower than normal
DelMp3->Resume();
// now start the thread running
iTempCount=0;
}
}
}
}
/*
void __fastcall TFMain::OnMSGStop(TMessage &
Message)
{
if(!DM->TimeSub->Enabled)
return;
MainStopTime=Now().FormatString("yyyy-mm-dd hh:nn:ss");
DM->TimeSub->Enabled=false;
FMain->Icon=Application->Icon;
TrayMessage(NIM_MODIFY);
//StopPlayClick(this);
//**********************Stop
if (!Audio1->Recorder->Stop())
Memo1->Lines->Add(Audio1->ErrorMessage);
audiorecording=false;
ButtonStatus("Idle");
//*********************Stop
String StopTime=FMain->MainStopTime;
MainTimeSub=FormatFloat("0",Time_Cmp(Mainbegin
Time.c_str(),StopTime.c_str()));
if(!CD->QGetWrite->Active)
{
CD->QGetWrite->DatabaseName=FMain->DataPath;
CD->QGetWrite->SQL->Clear();
CD->QGetWrite->SQL->Add("SELECT DTH, CH,BTIME, STIME,TIMESUB,WARNING");
CD->QGetWrite->SQL->Add("FROM 'Getdata.DBF' Getdata");
CD->QGetWrite->Open();
}
try
{
CD->QGetWrite->Edit();
CD->QGetWrite->Append();
CD->QGetWrite->FieldByName("DTH")->Value=FMain->MainDTH;
CD->QGetWrite->FieldByName("CH")->Value=MainCH;
CD->QGetWrite->FieldByName("BTIME")->Value=Mainbegin
Time;
CD->QGetWrite->FieldByName("STIME")->Value=StopTime;
CD->QGetWrite->FieldByName("TIMESUB")->Value=MainTimeSub.ToInt();
if(bWarning)
CD->QGetWrite->FieldByName("WARNING")->Value="报警";
else
CD->QGetWrite->FieldByName("WARNING")->Value="正常";
CD->QGetWrite->Post();
}
catch(...)
{
Application->Hint="存盘错误!";
Application->ShowHint=true;
CD->QGetWrite->Cancel();
MessageBeep(0);
}
if(LY)
REFileName->Lines->Add(Mainbegin
Time);
} */
/*
void __fastcall TFMain::OnMSGStart(TMessage &
Message)
{
Lbegin
Time->Caption=Now().FormatString("yyyy-mm-dd hh:nn:ss");
if(Mainbegin
Time==Lbegin
Time->Caption)
return;
if(DM->TimeSub->Enabled)
Perform(MSGSTOP,0,0);
FMain->SetMyi(0);
/*
if(bWarning)
{
if(Mainbegin
Time==Lbegin
Time->Caption)
{
return;
//************
String temp=Lbegin
Time->Caption;
Lbegin
Time->Caption=temp.SubString(0,temp.Length()-1)+AnsiString(temp.SubString(temp.Length(),1).ToInt()+1);
if (!Audio1->Recorder->Stop())
Memo1->Lines->Add(Audio1->ErrorMessage);
DeleteFile(FMain->DataPath+"//"+Lbegin
Time->Caption+".wav");
//*******
}
} */
/*
Mainbegin
Time=Lbegin
Time->Caption;
DM->TimeSub->Enabled=true;
FMain->Icon=ITray->Picture->Icon;
TrayMessage(NIM_MODIFY);
if(LY)
{
// RecFileClick(this);
// if(SaveDialog1->Execute())
String Temp;
try{
Temp=StrToDateTime(FMain->Mainbegin
Time).FormatString("yyyy-mm-dd hhnnss");
//Temp=Now().FormatString("yyyy-mm-dd hhnnss");
}
catch(...)
{
//Application->MessageBox("文件不存在","警告",0);
MessageBeep(0);
}
String FileName=FMain->DataPath+"//"+Temp+".wav";
/*
if(FileExists(FileName))
{
Temp=Now().FormatString("yyyy-mm-dd hhnnss");
if (!Audio1->Recorder->Stop())
Memo1->Lines->Add(Audio1->ErrorMessage);
DeleteFile(FileName);
}*/
//Audio1->Recorder->RecordToFile(FileName, 0,0);
//Memo1->Lines->Add("Recording to file : " + ExtractFileName(FileName));
/*
if(Memo1->Lines->Count>50)
Memo1->Lines->Clear();
*/
/*
StartRecClick(this);
}
if(!CD->QSearch->Active)
{
CD->QSearch->DatabaseName=DataPath;
CD->QSearch->SQL->Clear();
CD->QSearch->SQL->Add("SELECT DTH, CH,RM,ZT,GS");
CD->QSearch->SQL->Add("FROM 'Setdata.dbf' Setdata");
CD->QSearch->Open();
}
TLocateOptions Opts;
Opts.Clear();
Opts << loPartialKey;
if(CD->QSearch->Locate("RM",RM,Opts))
{
MainCH=CD->QSearch->FieldByName("CH")->AsString;
MainDTH=CD->QSearch->FieldByName("DTH")->AsString;
}
else
{
MainCH="";
MainDTH="";
}
LDTH->Caption=MainDTH;
LCH->Caption=MainCH;
} */
void __fastcall TFMain:
BGrid1ColEnter(TObject *Sender)
{
EDTH->Text=CD->QSet->FieldByName("DTH")->AsString;
//Temp=Temp.SubString(Temp.Length()-2,3);
EP1CH->Text=CD->QSet->FieldByName("CH")->AsString;
MERM->Text=CD->QSet->FieldByName("RM")->AsString;
sTempRM=MERM->Text;
//MEP1Time->Text=CD->QSet->FieldByName("TIMES")->AsString;
}
//---------------------------------------------------------------------------
void __fastcall TFMain::HBLYClick(TObject *Sender)
{
String sTemp;
if(LY)
sTemp="真的要关闭录音";
else
sTemp="真的要打开录音";
int button=Application->MessageBox(sTemp.c_str(),"警告", MB_OKCANCEL +MB_DEFBUTTON1+MB_ICONQUESTION);
if (button == IDCANCEL)
return;
if(FileExists(FMain->DataPath+"//PassWord.dat"))
{
if(mrOk!=FPass->ShowModal())
return;
}
LY=!LY;
if(LY)
{
HBLY->Hint="录音器处于打开状态";
HBLY->FaceColor=(TColor)0x000080FF;
}
else
{
HBLY->Hint="录音器处于关闭状态";
HBLY->FaceColor=clGray;
if(audiorecording)
{
if (!Audio1->Recorder->Stop())
Memo1->Lines->Add(Audio1->ErrorMessage);
audiorecording=false;
ButtonStatus("Idle");
REFileName->Lines->Add(Mainbegin
Time);
}
}
MessageBeep(0);
}
//---------------------------------------------------------------------------