Question

I have a SMS gateway that i control using AT Commands the component works fine but i am not able to parse the strings recieved from the device corectly.

First of all i use hardware Flow Control how that affects me ?

I use the TComDataPacket component witch has an event onPacket() where i recieve a string if i use the debugger i can see the string ok but if i use pos() to search or ShowMessage() to show the string the string is very short and i don't see any #00

I tryied using the RxChar event but is not triggered and RxBuf gives an access violation.

I using Delphi XE 2 is there any thing wrong with the component or i am doing something wrong?

LE : The event onPacket() freezes if i don't insert a sleep at the end of the method here is my code :

procedure TfrmMain.comPacketPacket(Sender: TObject; const Str: string);
var
  S,numar,coord : string;
  i,poi,rr,j,tmp2 : Integer;
const
  Readul = 'READ|';
  delim  = 'gps=';
  CMG = 'CMGL';
begin
  if pos('CMTI',Str) > 0 then
                          SendATCommand('AT+CMGL="ALL"');
  for i := 1 to Length(Str) do
    if Str[i] in ['A'..'Z','a'..'z','0'..'9','=','.'] then S := S + Str[i]
    else if Str[i] = '"' then S := S + '|';
    repeat
       poi := Pos('gps=',S);
       if poi > 0 then
       begin
          j := poi;
          repeat
            Dec(j);
            rr := PosEx(Readul,S,j);
            if rr >= poi then  rr := 0;
          until (rr>0) or (j = 1);
          numar := Copy(S,rr+Length(Readul)+1,PosEx('|',S,(rr+Length(Readul)+1)) - (rr + Length(Readul) + 1));
          ShowMessage('Trimit la numarul ' + numar);
          coord := Copy(S,poi + Length(delim),PosEx(CMG,S,poi) - poi - Length(CMG));
          S := Copy(S,poi + Length(delim),Length(S));
       end;
    until poi = 0;
    Sleep(1500);
end;
Was it helpful?

Solution

The problem here is string. In XE2, string is unicode string. in Delphi 2007 and below, string is ansi string. Their size is different. You must make it sure by checking TComport source.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top