Author Topic: Sending with Multi GSM modem  (Read 629 times)

heo899

  • Newbie
  • *
  • Posts: 9
    • View Profile
Sending with Multi GSM modem
« on: February 06, 2015, 07:55:53 pm »
I use nrComm to send bulk sms with upto 8 modems in UseMainThread := False
and have no other thread which I make.

in My application, I have to access Visual component of label for counting board do display how many sms was sent, and global variable to get turn which phone no shall be sent.

for accessing variables and visual components for every nrGSM,  I am using  only TCriticalSection because I have no other thread  like
*** Code ***
u_Lock.Acquire;
    try
      MyTurn[Nomor] := TakeThisNo;
      TakeThisNo :=TakeThisNo +1 ;
    finally
      u_Lock.Release;
    end;
*** Code ***
  * TakeThisNo : Record No of Sqlite Table which contain my phone no list
  * MyTurn[Nomor] : Array Variable for Each Modem for accessing the sqlite table

Mostly my application running well, but sometimes my computer hang with no error message.

I know there is nrSemaphore in nrLib.  can you please show me how to use that component.

C. Heo

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Sending with Multi GSM modem
« Reply #1 on: February 07, 2015, 04:31:10 am »
Hello

The most correct way is using windows messages for change a visual control state.
PostMessage(...)
https://msdn.microsoft.com/en-us/library/ms644944.aspx
SendMessage(...)
https://msdn.microsoft.com/en-us/library/ms644950.aspx

If target visual control does not allow change the neccesary state over described in MSDN windows message,
you can to subclass it and add necessary functionality in child class.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

heo899

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sending with Multi GSM modem
« Reply #2 on: February 08, 2015, 09:32:07 am »
Thanks for advising..
I made some code update including "SendMessage & WM_" .. I am trying..

I send sms with 8 modems in my application.
mostly they make event "SmsSent" or "GsmError"
but sometimes there is no event occured within short time

anyway because I am sending mass sms, so I put timer there (70 Second),
if no event within 70 sec, it is assumed Error and send next sms.
Here I am worring if  the event occur 100 sec after sending sms

is there any method that preventing event if longer than 70 second...?

please see my code below

***************** My Code *****************
var
  Com : Array[1..8] of TnrComm;
  Gsm : Array[1..8] of TnrGsm ;
  nrLog : Array[1..8] of TnrLogfile;
  TimerModem : Array[1..8] of TTimer;
  CdsArr     : Array[1..8] of TClientDataSet;
  qryArr     : Array[1..8] of TDISQLite3UniDirQuery;

procedure TForm1.Timer1Timer(Sender: TObject);
var asal : integer;
    trimS : Array[1..8]of String;
begin
  asal := TTimer(Sender).Tag;
  TTimer(Sender).Enabled :=False;

    inc(cttlErr);
    Upd_ErrorCount;

    trimS[asal]:= trim(Gsm[asal].CmdSendAndWaitResult('AT<cr>'));

    if trimS[asal] = 'OK' then begin
       GetTurn(asal);
    end
    else isMass[asal] := c_Single;

    KeepOnSending(asal,'Err');
  end;
end;

procedure TForm1.nrGsm1GsmError
var tsData :string;
    asal : integer;
begin
  asal := TnrGsm(Sender).Tag;
  TimerModem[asal].Enabled :=False;

  tsData := trim(sData);
  if tsData='500' then begin

     inc(cttlErr);
     Upd_ErrorCount;

     GetTurn(asal);

     KeepOnSending(asal,'Err');
  end
  else isMass[asal] := c_Single;
end;

procedure TForm1.nrGsm1SmsSent
begin
  asal := TnrGsm(Sender).Tag;
  TimerModem[asal].Enabled :=False;

  inc(cttlOK);
  Upd_SuccessCount;

  GetTurn(asal);
  KeepOnSending(asal,'OK');
end;

procedure TForm1.KeepOnSending(asal: Integer; OkGagal: String);
begin
    Case isMass[asal] of
      c_Mass   : StartMassSending(asal);
      c_Single : ;
    end;
end;

procedure TForm1.StartMassSending(Nomor : Integer);
var pdu : Array[1..8] of TnrPduSms;
begin

  with cdsArr[Nomor] do begin
    if MyTurn[Nomor] > RecordLength then begin
      pnlStoryNo[Nomor].Caption := 'File Finished';
      exit;
    end
    else begin
      RecNo := MyTurn[Nomor];
      NoTelpNow[Nomor] := fieldbyName('TelpNo').AsString;
      dbDM.cds_work.RecNo := MyTurn[Nomor];
      pnlStoryNo[Nomor].Caption :=  NoTelpNow[Nomor] ;

      pdu[Nomor] := TnrPduSms.Create(false);
      pdu[Nomor].Text  := Kata2Now  ;
      pdu[Nomor].Phone := NoTelpNow[Nomor];
      pdu[Nomor].Confirm := False;
      pdu[Nomor].Alert := False;
  //    pdu[Nomor].TTLType := ttlAbs;               
  //    pdu[Nomor].TTLValue := Now + 1;
  //    pdu[Nomor].TTLValue := Now + (1/1440);           
      GSM[Nomor].SmsSend(pdu[Nomor]);
      pdu[Nomor].Free;

      TimerModem[Nomor].Interval := 60000;
      TimerModem[Nomor].Enabled  := True;

    end;
  end;
end;

procedure TForm1.Upd_SuccessCount;
var
  sMsg : string;
  cds : TCopyDataStruct;
begin
  sMsg := intTOstr(cttlOK);

  cds.dwData := 0; // Identify the message contents
  cds.cbData := 1 + Length(sMsg);
  cds.lpData := PChar(sMsg);

  SendMessage(Handle, WM_USER + 100, 0, Integer(@cds));
end;

procedure TForm1.WMRecvSuccess(var Msg: TWMCopyData);
begin
  pnlcttlOK.Caption := PChar(Msg.CopyDataStruct.lpData);
end;


heo899

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Sending with Multi GSM modem
« Reply #3 on: February 08, 2015, 09:35:49 am »
procedure TForm1.GetTurn(Nomor : Integer);
begin
    u_Lock.Acquire;
    try
      MyTurn[Nomor] := TakeThisNo;
      TakeThisNo :=TakeThisNo +1 ;
    finally
      u_Lock.Release;
    end;
end;