Search code examples
delphiat-commandtcomport

How to get just the correct response from TComPort - Delphi?


When i send the command "AT+CUSD=1,"*200#",15" i get the response:

OK


+CUSD: 0,"Crdit :1.33DA au 21/05/20.Credit offert :0DA",15  

Is there a function or another AT command to get just

Crdit :1.33DA au 21/05/20.Credit offert :0DA 

which is the the answer i want ?


Solution

  • Modem response is string-package divided by commas.

    You can:
    - assign this string to TStringList.DelimitedText to get collection of individual substrings
    - identify package by 0-th item - here 'CUSD'
    - get 1-th item as 'Crdit...'

    Example with Memo.Lines (of type TStrings):

    var
      s: string;
      sl: TStringList;
    begin
      s := '+CUSD: 0,"Crdit :1.33DA au 21/05/20.Credit offert :0DA",15';
      sl := TStringList.Create; 
      try
        sl.Delimiter := ',';
        sl.StrictDelimiter := True;
        sl.DelimitedText := s;
        Memo1.Lines.Add(sl[1]);
      finally
        sl.Free;
    
    result in sl:
     +CUSD: 0
     Crdit :1.33DA au 21/05/20.Credit offert :0DA
     15
    in Memo:
     Crdit :1.33DA au 21/05/20.Credit offert :0DA