📄 adgsm.pas
字号:
//S := '"+' + S + '"'; {!!.01}
//end; {!!.01}
S := S + #13#10;
FComPort.Output := 'AT' +
GSMSendMessageCommands[CmdIndex] + S;
end
end else
FComPort.Output := 'AT' + GSMSendMessageCommands[CmdIndex]
+ #13;
end
end
end
end;
gsListAll : begin
// Just sent +CMGL, successful so far, send the next command
S := ResponseStr;
if Length(S) > 8 then {!!.02}
while ParseAMessage do {!!.02}
DelayTicks(1, True); {!!.02}
ResponsePacket.IncludeStrings := False;
ResponsePacket.StartCond := scString; {!!.02}
if FNeedNewMessage > 0 then begin {!!.04}
if Assigned(FOnNewMessage) then {!!.04}
FOnNewMessage(Self, FNeedNewMessage, {!!.04}
FMessageStore.Messages[FNeedNewMessage].Message);{!!.04}
FNeedNewMessage := 0; {!!.04}
end else begin {!!.04}
if Assigned(FOnMessageList) then
FOnMessageList(Self);
if Assigned(FOnGSMComplete) and not FConfigList then {!!.02}
FOnGSMComplete(Self, FGSMState, FErrorCode);
end;
FGSMState := gsNone;
ResponseStr := ''; {!!.02}
end;
gsSendFStore : begin
//Just sent +CMSS, successful so far, send the next command
inc(CmdIndex);
if CmdIndex > High(GSMSendMessFromStorage) then begin
// generate the OnComplete event, we're done
FMessageStore.ClearStore;
Synchronize;
if Assigned(FOnMessageList) then
FOnMessageList(Self);
if Assigned(FOnGSMComplete) then
FOnGSMComplete(Self, FGSMState, FErrorCode);
FGSMState := gsNone;
ResponseStr := ''; {!!.02}
end else
// send the next command if there is one
FComPort.Output := 'AT' +
GSMSendMessFromStorage[CmdIndex] + #13;
end;
gsWrite : begin
// Just sent +CMGW, successful so far, send the next command
inc(CmdIndex);
if CmdIndex > High(GSMWriteToMemoryCommands) then begin
FMessageStore.ClearStore;
Synchronize;
if Assigned(FOnMessageList) then
FOnMessageList(Self);
// generate the OnComplete event, we're done configuring
if Assigned(FOnGSMComplete) then
FOnGSMComplete(Self, FGSMState, FErrorCode);
FGSMState := gsNone; {!!.02}
ResponseStr := ''; {!!.02}
end else
// send the next command
ResponsePacket.StartString :=
GSMWriteToMemoryResponse[CmdIndex];
ResponsePacket.EndString := #13#10;
ResponsePacket.Enabled := True;
//DelayTicks(4, True); {!!.04}
if FTempWriteMess[Length(FTempWriteMess)] <> #26 then
FTempWriteMess := FTempWriteMess + #26;
FComPort.Output := FTempWriteMess;
end;
gsDelete : begin
{ Just sent +CMGD=,successful so far, send the next command}
inc(CmdIndex);
if CmdIndex > High(GSMDeleteAMessageCommand) then begin
// generate the OnComplete event, we're done
//ResponsePacket.IncludeStrings := False; {!!.01}
FMessageStore.ClearStore;
Synchronize;
if Assigned(FOnMessageList) then
FOnMessageList(Self);
if Assigned(FOnGSMComplete) then
FOnGSMComplete(Self, FGSMState, FErrorCode);
FGSMState := gsNone; {!!.02}
ResponseStr := ''; {!!.02}
end else
// send the next command
FComPort.Output := 'AT' + GSMDeleteAMessageCommand[CmdIndex]
+ #13;
end;
end; // End Case
end;
{ issues +CMGW to write message secified by FMessage and DestAddr to the phone
memory, memory location returned as function result }
procedure TApdCustomGSMPhone.WriteToMemory(const Dest, Msg: string);
var
S : string;
Res : Integer;
ET : EventTimer;
begin
if FGSMState > gsNone then begin
DoFail(secSMSBusy,-8100);
Exit;
end;
if not FConnected then begin
{ Do connection/configuration stuff }
FQuickConnect := False;
Connect;
repeat
Res := SafeYield;
until (FGSMState = gsNone) or (Res = wm_Quit);
end;
SetState(gsWrite);
ResponsePacket.StartString := GSMWriteToMemoryResponse[CmdIndex];
ResponsePacket.EndString := '>'#32;
ResponsePacket.Enabled := True;
//DelayTicks(4, True); {!!.04}
S := Dest;
if S[1] <> '"' then begin
if S[1] = '+' then
S := '"' + S + '"'
else
if S[2] <> '+' then
S := '"+' + S + '"';
end;
FComPort.Output := 'AT' + GSMWriteToMemoryCommands[CmdIndex] + S + #13#10;
FTempWriteMess := Msg + #26;
NewTimer(ET, 1080); // 60 second timer
repeat
Res := SafeYield;
until (FGSMState = gsNone) or (Res = wm_Quit) or TimerExpired(ET);
if TimerExpired(ET) then begin
DoFail(secSMSTimedOut,-8101);
Exit;
end;
end;
procedure TApdCustomGSMPhone.WndProc(var Message: TMessage);
begin
with Message do begin
if Msg = ApdGSMResponse then begin
case WParam of {!!.04}
0 : ProcessResponse;
1 : begin {!!.04}
ListAllMessages; {!!.04}
end; {!!.04}
end
end else
Result := DefWindowProc(FHandle, Msg, wParam, lParam);
end;
end;
procedure TApdCustomGSMPhone.DeleteFromMemoryIndex(PhoneIndex: Integer);
var
Res : Integer;
begin
{ Remove a single message from the phone's message store }
if FGSMState > gsNone then begin
DoFail(secSMSBusy,-8100);
Exit;
end;
if not FConnected then begin
{ Do connection/configuration stuff }
FQuickConnect := False;
Connect;
repeat
Res := SafeYield;
until (FGSMState = gsNone) or (Res = wm_Quit);
end;
CmdIndex := 0;
SetState(gsDelete);
//ResponsePacket.IncludeStrings := True; {!!.01}
ResponsePacket.StartString := GSMDeleteAMessageCommand[CmdIndex];
ResponsePacket.EndString := #13#10'OK';
ResponsePacket.Enabled := True;
//DelayTicks(4, True); {!!.04}
FComPort.Output := 'AT' + GSMDeleteAMessageCommand[CmdIndex] +
IntToStr(PhoneIndex) + #13;
end;
procedure TApdCustomGSMPhone.CheckPort;
begin
{ Make sure comport is open }
if Assigned(FComPort) then begin
if (FComPort.DeviceLayer = dlWinSock) then
{ we can't do GSM through Winsock... }
raise ECannotUseWithWinSock.Create(ecCannotUseWithWinSock, False);
if not(FComPort.Open) then
{ open the port, let the TApdComPort raise any exceptions }
FComPort.Open := True;
FGSMState := gsNone;
FConnected := True;
end else
raise EPortNotAssigned.Create(ecPortNotAssigned, False);
end;
procedure TApdCustomGSMPhone.Synchronize;
var
Res : Integer;
begin
// tell the phone to give us the message store
if FGSMState > gsNone then begin
DoFail(secSMSBusy,-8100);
Exit;
end;
if not FConnected then begin
{ Do connection/configuration stuff }
FQuickConnect := False;
Connect;
repeat
Res := SafeYield;
until (FGSMState = gsNone) or (Res = wm_Quit);
end;
//FGSMState := gsNone; {!!.02}
ListAllMessages;
end;
procedure TApdMessageStore.SetMSCapacity(const Value: Integer);
begin
FCapacity := Value;
end;
procedure TApdMessageStore.SetMessage(Index: Integer;
const Value: TApdSMSMessage);
begin
Strings[Index] := Value.FTimeStampStr;
Objects[Index] := Value;
//if Value > 160 then DoFail(ecSMSTooLong,-8102);
end;
{ Notification }
procedure TApdCustomGSMPhone.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if Operation = opRemove then begin
if AComponent = FComPort then
FComPort := nil;
end else begin
if (AComponent is TApdCustomComPort) and (FComPort = nil) then
FComPort := TApdCustomComPort(AComponent);
end;
end;
{ Set the Service Center Address/Phone Number }
procedure TApdCustomGSMPhone.SetCenter(const Value: string);
begin
FSMSCenter := Value;
end;
{ TApdGSMPhone - TApdSMSStatus to string conversion}
function TApdCustomGSMPhone.StatusToStr(StatusString: TApdSMSStatus): string;
const
StatusStrings : array[0..ord(High(TApdSMSStatus))] of string = {!!.01}
('REC UNREAD', 'REC READ', 'STO UNSENT', 'STO SENT', 'ALL',
'Unknown'); {!!.01}
begin
if ord(StatusString) > High(StatusStrings) then begin
Result := StatusStrings[High(StatusStrings)]; {!!.02}
//DoFail(ecSMSUnknownStatus,-8103); {!!.02}
Exit;
end;
Result := StatusStrings[Ord(StatusString)];
end;
procedure TApdCustomGSMPhone.DoFail(const Msg: string;
const ErrCode: Integer);
begin
if Assigned(FOnGSMComplete) then begin
FOnGSMComplete(Self, FGSMState, ErrCode);
FGSMState := gsNone;
end else begin
//raise EApdGSMPhoneException.Create(Msg, ErrCode);
FGSMState := gsNone;
raise EApdGSMPhoneException.Create(ErrCode, Msg);
end;
end;
procedure TApdCustomGSMPhone.SetState(NewState : TGSMStates);
begin
FGSMState := NewState;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -