VB 程序转化为DELPHI程序(MSCOMM) (送200分) sunforme@263.net(200分)

  • 主题发起人 主题发起人 white0212
  • 开始时间 开始时间
W

white0212

Unregistered / Unconfirmed
GUEST, unregistred user!
Option Explicit
Const SOH = 1
Const STX = 2
Const EOT = 4
Const ACK = &H6
Const NAK = &H15
Const CAN = &H18
Const CPMEOF = 26
Const TXBLKSIZE = 128
Const RXBLKSIZE = 128
'
Dim baud As Integer
Dim NOFFILE As String
Dim dfname As String
Dim id As Byte
Dim CHECKSUM As Byte, RUNNINGSUM As Long
Dim DELAYCON As Long
Dim abort As Integer
Dimdo
ing As Integer
Private Sub cmdAbort_Click()
If Notdo
ing then
Exit Sub
abort = True
MsgBox ("Action Aborted")
txtDebug = "ABORTED"
Call defocusabort
End Sub
Private Sub cmdBaud_Click()
baud = (baud + 1) Mod 3
If baud = 0 then
MSComm.Settings = "9600,n,8,1"
cmdBaud.Caption = "9600 baud"
else
If baud = 1 then
MSComm.Settings = "19200,n,8,1"
cmdBaud.Caption = "19200 baud"
else
MSComm.Settings = "4800,n,8,1"
cmdBaud.Caption = "4800 baud"
End If
End Sub
Private Sub cmdQuit_Click()
'Call WakeUp
'Call SENDID
'MSComm.Output = "3"
Do
Loop While MSComm.OutBufferCount <> 0
'
'MSComm.PortOpen = False
End
End Sub
Sub GetFileName()
If Right$(Dir1, 1) = "/" then
NOFFILE = Dir1 &amp;
txtFileName
else
NOFFILE = Dir1 &amp;
"/" &amp;
txtFileName
End If
Debug.Print "getfilename - " &amp;
NOFFILE
End Sub
Sub defocusabort()
cmdReceive.Enabled = True
cmdTransmit.Enabled = True
cmdQuit.Enabled = True
cmdAbort.Enabled = False
End Sub
Sub focusabort()
cmdReceive.Enabled = False
cmdTransmit.Enabled = False
cmdQuit.Enabled = False
cmdAbort.Enabled = True
cmdAbort.SetFocus
End Sub
Private Sub cmdReceive_Click()
Dim cfgFilename As String
Dim iIndex As Integer
Dim uIndex As Integer
Dim iSection As String
Dim KeyValue As String

CommonDialog1.InitDir = App.Path
CommonDialog1.ShowOpen
cfgFilename = CommonDialog1.filename
CommonDialog1.filename = ""
If (cfgFilename <> "") And (Len(cfgFilename) > 3) then

iSection = "Receive"

KeyValue = ReadINI(iSection, "Size", cfgFilename)
uIndex = CInt(KeyValue)

For iIndex = 1 To uIndex
KeyValue = ReadINI(iSection, iSection &amp;
CStr(iIndex), cfgFilename)

NOFFILE = App.Path &amp;
"/" &amp;
KeyValue
dfname = KeyValue
Call Receive
Next

End If

'NOFFILE = App.Path &amp;
"/88.txt"
'dfname = "11.txt"
'Call Receive
End Sub
Sub Receive()
Dim ch As String
'
Dim BYTECH As Byte
Dim I As Long
Dim BLOCKNOHI As Integer, BLOCKNOLO As Integer
Dim BLOCKNOCPL As Integer, PREVBLOCKNO As Integer
Dim CRCHI As Integer, CRCLO As Integer
Dim NOFBLOCK As Integer
Dim OUTFILE As Integer
'
Call OPenPort
Call WakeUp
'
Call focusabort
doing = True
abort = False
' flush input
txtDebug.Text = "RECEIVING..."
OUTFILE = FreeFile
On Error GoTo openfileerror
'Call GetFileName '// modified by noffile
Open NOFFILE For Random As #OUTFILE Len = 1
On Error GoTo 0
MSComm.InBufferCount = 0
' send ID
Call SENDID
If (doing = False) then
Exit Sub
' Send command
Call send1byte(&amp;H31)
' send file name
'dfname = txtFileName '// modified by noffile
For I = 1 To Len(dfname)
Call send1byte(Asc(Mid$(dfname, I, 1)))
Next I
Call send1byte(0)
'
' wait sync
waitsync:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If ch = ChrB$(&amp;H7F) then
GoTo startrece
End If
GoTo waitsync
'
startrece:
Call send1byte(Asc("C"))
'
NOFBLOCK = 0
PREVBLOCKNO = 0
BLOCKNOHI = 0
'
NEXTBLOCK:
waitheader:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If ch = ChrB$(EOT) then
Close #OUTFILE
txtDebug.Text = "FINISHED"
MsgBox ("End Receiving " &amp;
NOFBLOCK &amp;
" Blocks")
GoTo EXITSUB
End If
If ch = ChrB$(SOH) then
GoTo startrecedata
End If
GoTo waitheader
'
startrecedata:
NOFBLOCK = NOFBLOCK + 1
txtBlockNo.Text = Str$(NOFBLOCK)
GoSub GET1CH
BLOCKNOLO = AscB(ch)
GoSub GET1CH
BLOCKNOCPL = AscB(ch)
If BLOCKNOLO + BLOCKNOCPL <> 255 then
MsgBox ("WRONG CPL")
GoTo EXITSUB
End If
'
PREVBLOCKNO = PREVBLOCKNO + 1
If PREVBLOCKNO = 256 then
PREVBLOCKNO = 0
BLOCKNOHI = BLOCKNOHI + 1
End If
If PREVBLOCKNO <> BLOCKNOLO then
MsgBox ("NOT IN SEQ")
GoTo EXITSUB
End If
'
RUNNINGSUM = 0
For I = 1 To RXBLKSIZE
GoSub GET1CH
Put #OUTFILE, , AscB(ch)
RUNNINGSUM = (RUNNINGSUM + AscB(ch)) Mod 256
Next I
GoSub GET1CH
CHECKSUM = AscB(ch)
If CHECKSUM <> RUNNINGSUM then
MsgBox ("WRONG CHECKSUM" &amp;
Str(RUNNINGSUM) &amp;
Str(CHECKSUM))
End If
send1byte (ACK)
GoTo NEXTBLOCK
'
GET1CH:
DoEvents
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
Return
End If
GoTo GET1CH
'
openfileerror:
MsgBox ("Error in Open File ")
EXITSUB:
Close #OUTFILE
Call closeport
do
ing = False
Call defocusabort
cmdReceive.SetFocus
Exit Sub
'
End Sub
Sub SENDID()
'id = Val(txtID)
If id < 1 Or id > 99 then
doing = False
Exit Sub
End If
Call send1byte(SOH)
Call send1byte(id)
End Sub
Sub send1byte(dbyte As Byte)
Dim bytBYTE(0 To 0) As Byte
bytBYTE(0) = dbyte
MSComm.Output = bytBYTE()
DoEvents
End Sub
Sub delay500ms()
Dim targtimer Asdo
uble
targtimer = Timer + 0.5
If targtimer >= 86400# then
targtimer = targtimer - 86400#
Do
Loop While Timer < targtimer
End Sub
Sub WakeUp()
MSComm.RTSEnable = True
Call delay500ms
MSComm.RTSEnable = False
Call delay500ms
End Sub
Sub OPenPort()
MSComm.PortOpen = True
cmdBaud.Enabled = False
End Sub
Sub closeport()
MSComm.PortOpen = False
cmdBaud.Enabled = True
End Sub
Private Sub cmdTransmit_Click()
Dim cfgFilename As String
Dim iIndex As Integer
Dim uIndex As Integer
Dim iSection As String
Dim KeyValue As String

CommonDialog1.InitDir = App.Path
CommonDialog1.ShowOpen
cfgFilename = CommonDialog1.filename
CommonDialog1.filename = ""
If (cfgFilename <> "") And (Len(cfgFilename) > 3) then

iSection = "Send"

KeyValue = ReadINI(iSection, "Size", cfgFilename)
uIndex = CInt(KeyValue)

For iIndex = 1 To uIndex
KeyValue = ReadINI(iSection, iSection &amp;
CStr(iIndex), cfgFilename)

NOFFILE = App.Path &amp;
"/" &amp;
KeyValue
dfname = KeyValue
Call Transmit
Next

End If
'Debug.Print " start "
'Call Transmit

End Sub
Sub Transmit()
Dim NOFBLOCK As Long
Dim loffile As Long
Dim fnoin As Integer
Dim byteptr As Integer
'Dim c As Variant
Dim ch As String
Dim BLOCKNO As Integer
Dim CRCHI As Byte, CRCLO As Byte
Dim inblk() As Byte
Dim inblkFIXED(0 To TXBLKSIZE - 1) As Byte
Dim iptr As Integer, optr As Integer
Dim feedback As Integer
Dim CHFEEDBACK As String
Dim BLOCKNOHI As Byte, BLOCKNOLO As Byte
Dim BLOCKNOCPL As Byte
Dim TIMEOUT As Long
'
Dim I As Integer
doing = True
abort = False
txtDebug.Text = "OPENING FILE"
'Call GetFileName ' modified by kenneth
On Error GoTo openfileerror
fnoin = FreeFile
Open NOFFILE For Random As #fnoin Len = TXBLKSIZE
On Error GoTo 0
loffile = LOF(fnoin)
NOFBLOCK = (loffile - 1) / TXBLKSIZE + 1
txtDebug.Text = "NO. OF BLOCK =" &amp;
Str$(NOFBLOCK)
' FLUSH INput
Call focusabort
Call OPenPort
Call WakeUp
MSComm.InBufferCount = 0
TIMEOUT = -1
' send ID
Call SENDID
If (doing = False) then
Exit Sub
' send command
Call send1byte(&amp;H32)
' send file name
'dfname = txtFileName // modified by kenneth
'Debug.Print "transmit" &amp;
dfname
For I = 1 To Len(dfname)
Call send1byte(Asc(Mid$(dfname, I, 1)))
Next I
Call send1byte(0)
Call delay500ms
'
SENDSYNC:
DoEvents
If abort then
GoTo EXITSUB
txtDebug.Text = "SENDING SYNC"
If MSComm.OutBufferCount = 0 then
send1byte (&amp;H7F)
' TIMEOUT = TIMEOUT + 1
' If TIMEOUT Mod 10 = 0 then
Call DELAYms(100)
' End If
End If
If MSComm.InBufferCount > 0 then
ch = MSComm.Input
If AscB(ch) = AscB("C") then
GoTo STARTSEND
End If
txtDebug.Text = "SYNC NOT ACKNOWLEDGED"
GoTo SENDSYNC
'
STARTSEND:
txtDebug.Text = "SYNC ACKNOWLEDGED"
For BLOCKNO = 1 To NOFBLOCK
'
Get #fnoin, , inblkFIXED
inblk() = inblkFIXED
'GoSub conv
txtDebug.Text = "TRANSMIT HEADER"
txtBlockNo = Str$(BLOCKNO)
Call send1byte(SOH)
'BLOCKNOHI = BLOCKNO / 256
BLOCKNOLO = BLOCKNO Mod 256
Call send1byte(BLOCKNOLO)
Call send1byte(255 - BLOCKNOLO)
txtDebug.Text = "TRANSMIT DATA"
'DoEvents
MSComm.Output = inblk()
txtDebug.Text = "TRANSMIT CHECKSUM"
RUNNINGSUM = 0
For I = 0 To TXBLKSIZE - 1
RUNNINGSUM = (RUNNINGSUM + inblkFIXED(I)) Mod 256
Next I
CHECKSUM = RUNNINGSUM
Call send1byte(CHECKSUM)
'Call send1byte(CRCHI)
'Call send1byte(CRCLO)
do
Events
If abort then
GoTo EXITSUB
txtDebug = "WAIT ACK"
feedback = 0
do
do
Events
If abort then
GoTo EXITSUB
If MSComm.InBufferCount > 0 then
CHFEEDBACK = MSComm.Input
feedback = AscB(CHFEEDBACK)
End If
Loop While feedback <> ACK
txtDebug = " ACK RECEIVED"
Next BLOCKNO
send1byte (EOT)
txtDebug = "FINISHED"
MsgBox ("End of Transmission - " &amp;
Str$(NOFBLOCK) &amp;
" Blocks")
EXITSUB:
doing = False
Call defocusabort
cmdTransmit.SetFocus
Call closeport
Close #fnoin
Exit Sub
'
openfileerror:
MsgBox ("Error in Open File")
Exit Sub
'
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
txtFileName = ""
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
txtFileName = ""
End Sub
Private Sub File1_Click()
txtFileName = File1.filename
End Sub
Private Sub Form_ACTIVATE()
Dim OTIME As String
doing = False
' default 9600 baud
baud = 0
cmdAbort.Enabled = False
'
OTIME = Time$
Do
Loop While OTIME = Time$
'
OTIME = Time$
Do
DELAYCON = DELAYCON + 1
Loop While OTIME = Time$
'
DELAYCON = DELAYCON / 1000
End Sub
Sub DELAYms(DELAYCNT As Long)
Dim I As Long
Dim OTIME As String
For I = 1 To DELAYCNT * DELAYCON
OTIME = Time$
Next I
End Sub
Function ReadINI(Section, KeyName, filename As String) As String
Dim sRet As String
sRet = String(255, Chr(0))
ReadINI = Left(sRet, GetPrivateProfileString(Section, ByVal KeyName, "", sRet, Len(sRet), filename))
End Function
 
怎么了?
想把VB 程序转化为DELPHI程序(MSCOMM) 运行吗?
是不是VB中用MSCOMM,delphi中同样用Mscomm?
 
是的!
我有VB 的源程序,想转化为 DELPHI!!
sunforme@263.net
 
老兄我真服了你了,串口通讯的东东放到我这里来了
去vcl.vclxx.org上面找一个comm的控件吧,非常好用的。
 
有什么不一样的吗?
 
我知道,可我想转为DELPHI的!
和VB一模一样的
 
那你用这个ocx也没有什么问题啊。
 
不是的,VB程序是没问题,可我想把他转化为DELPHI的!
 
问题是我们还要装个ocx来改才能确保改过的能用,真是麻烦,只好麻烦你自己了哦
 
哎,这个问题是又难又烦,看来这200分我送不出了!
好遗憾,好着急!!!!!!!!
 
问题并不难,只是有点象懒婆娘的袜子!我想你该自己对照一下翻译即可。
 
这个Vb程序没多吗复杂啊.
改成Delphi程序并不难啊.
 
用spcomm控件
 
delphi_lsl,:
可惜我不懂VB啊!
 
我爱delphi:老兄,我不懂VB。
GODDY;能给个SPCOMM的DEMO吗?》
 
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,&amp;lpSectorsPerCluster,&amp;lpBytesPerSector,&amp;lpNumberOfFreeClusters,&amp;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::BitBtn1Click(TObject *Sender)
{
int button=Application->MessageBox(" 真的要打开PTT?","警告", MB_OKCANCEL +MB_DEFBUTTON1+MB_ICONQUESTION);
if (button == IDCANCEL)
return;
if(FileExists(FMain->DataPath+"//PassWord.dat"))
{
if(mrOk!=FPass->ShowModal())
return;
}
if(!CD->QSet->Active)
{
CD->QSet->DatabaseName=DataPath;
CD->QSet->SQL->Clear();
CD->QSet->SQL->Add("SELECT DTH, CH,RM,ZT,GS");
CD->QSet->SQL->Add("FROM 'Setdata.dbf' Setdata");
CD->QSet->Open();
}
String Temp=CD->QSet->FieldByName("RM")->AsString;
C_O_RM=Temp;
if(C_O_RM=="111")
{
Application->MessageBox("你无权对总台操作","警句",MB_ICONSTOP);
MessageBeep(0);
return;
}
char a=0xcc;
bComm=true;
char temp[5];
temp[0]=a;
if(C_O_RM=="111")
{
Application->MessageBox("你无权对总台操作","警句",MB_ICONSTOP);
MessageBeep(0);
return;
}
if(!FMain->CommTV->WriteCommData(temp,1))
{
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
}
//---------------------------------------------------------------------------
void __fastcall TFMain::BitBtn2Click(TObject *Sender)
{
int button=Application->MessageBox(" 真的要关闭PTT?","警告", MB_OKCANCEL +MB_DEFBUTTON1+MB_ICONQUESTION);
if (button == IDCANCEL)
return;
if(FileExists(FMain->DataPath+"//PassWord.dat"))
{
if(mrOk!=FPass->ShowModal())
return;
}
if(!CD->QSet->Active)
{
CD->QSet->DatabaseName=DataPath;
CD->QSet->SQL->Clear();
CD->QSet->SQL->Add("SELECT DTH, CH,RM,ZT,GS");
CD->QSet->SQL->Add("FROM 'Setdata.dbf' Setdata");
CD->QSet->Open();
}
String Temp=CD->QSet->FieldByName("RM")->AsString;
C_O_RM=Temp;
if(C_O_RM=="111")
{
Application->MessageBox("你无权对总台操作","警句",MB_ICONSTOP);
return;
}
char a=0xcc;
bComm=false;
char temp[5];
temp[0]=a;
if(!FMain->CommTV->WriteCommData(temp,1))
{
Application->Hint="通信失败!请检查线路";
Application->ShowHint=true;
MessageBeep(0);
}
}
//---------------------------------------------------------------------------

 
goddy:
谢谢你的DEMO程序!可是我看不懂,有个奢侈的要求,有DELPHI的吗?
哈。。。。分数少了点!我可以给你加,648分(我就这么多了)怎样?虽然我知道你不在乎!
 
>老兄我真服了你了,串口通讯的东东放到我这里来了
不会是看到都有个com就想当然的放在这里了吧[:D]


 
我在用BCB5做多层结构系统时,我在Server端加入了一个取得服务器IP地址的方法:GetServerIP它的参数是vIP:Variant *,IN方式,并在服务端实现了这个方法,
加入的代码如下:
*vIP="192.168.0.01";最后我注册成功。
可是在我开发客户端程序时,我用TSocketConnection
当取得它的服务时我是这样做的:
Variant* vip;
SocketConnection1->AppServer.GetServerIP(vip);
Edit1->Tex=vip;
可 是我在运行程序时出错,没有编译通过。
它说getserverIP不是variant的成员
getserverIP is not a memober of variant
请问?
我该如何去调用这个方法呢?
请各位大侠多多指教?
小生的QQ:65466700(24小时在线恭候)
MAIL: alongsun@sina.com
 

Similar threads

后退
顶部