procedure
TForm1
.
TimerReceiveTimer(Sender: TObject);
var
CountCharWait:
word
;
TimeOut:
byte
;
NumberWritten:
cardinal
;
PhoneCommand:
string
;
procedure
ReadPort;
var
inBuf:
array
[
0..1024
]
of
char
;
cbCharsRead,dwErrorCode: dword;
i:
integer
;
procedure
HexDecReceive;
var
InBuf:
array
[
0..1024
]
of
byte
;
cbByteRead:dword;
i:
integer
;
begin
if
ReadFile(Port,InBuf,CountCharWait,cbByteRead,
nil
)
then
begin
for
i:=
0
to
cbByteRead-
1
do
if
RadioButton1
.
Checked
then
CharsReceived
.
Caption:=CharsReceived
.
Caption+intToHex(inBuf[i],
2
)+
' '
else
CharsReceived
.
Caption:=CharsReceived
.
Caption+intToStr(inBuf[i])+
' '
;
end
;
end
;
begin
inc(TimeOut);
ClearCommError(Port,dwErrorCode,@PortStat);
CountCharWait := PortStat
.
cbInQue;
if
CountCharWait >
0
then
begin
TimeOut:=
0
;
if
(RadioButton1
.
Checked)
or
(RadioButton2
.
Checked)
then
HexDecReceive
else
if
ReadFile(Port,InBuf,CountCharWait,cbCharsRead,
nil
)
then
for
i:=
0
to
cbCharsRead-
1
do
CharsReceived
.
Caption:=CharsReceived
.
Caption+inBuf[i]
else
dwErrorCode := GetLastError;
end
;
end
;
begin
ReadPort;
if
(TimeOut<>
0
)
and
(CharsReceived
.
Caption<>
''
)
then
begin
if
trim(CharsReceived
.
Caption) =
'RING'
then
begin
NumberWritten :=
0
;
PhoneCommand:=
'ATA'
+#
13
#
10
;
WriteFile(Port,
PChar
(PhoneCommand)^, Length(PhoneCommand), NumberWritten,
nil
);
end
;
if
trim(CharsReceived
.
Caption) =
'send'
then
begin
Timer2
.
Enabled:=
True
;
TimerReceive
.
Enabled:=
False
;
exit;
end
;
if
triim(
Char
)
MemoRx
.
Lines
.
Add(CharsReceived
.
Caption);
if
CheckBox1
.
Checked
then
begin
Edit1
.
Text:=CharsReceived
.
Caption;
if
Radiobutton3
.
Checked
then
TransmitClick(Sender)
else
TxHexButtonClick(Sender);
Edit1
.
Text:=
''
;
end
;
CharsReceived
.
Caption:=
''
;
end
;
if
TimeOut>
10
then
TimeOut:=
0
;
end
;