ApdComPort Problem

I'm developing an aplication to connect a celular phone with the computer. Sometimes the port break and can't read the information of the celular. The solution to this problem was disconnect and connect again de COM Port, but in my application when I disconnect (objPSerial.Open := false;)  my debugger do an exit of my funtion. And this never finalize. How can I Connect and Disconnect my COM Port without errors?
//Here I create the COM Port called objPSerial
     {$region ' Inicializa el puerto de comunicacion serial '}
       objPSerial :=  TApdComPort.Create(nil);
       objPSerial.AutoOpen:=false;
       objPSerial.PromptForPort:=false;
       objPSerial.ComNumber:=iPuerto;
       objPSerial.Baud:=iBaud;
       objPSerial.DataBits:=iData;
       objPSerial.StopBits:=iStop;
       case iParity of
            0 : objPSerial.Parity:=pEven;
            1 : objPSerial.Parity:=pMark;
            2 : objPSerial.Parity:=pNone;
            3 : objPSerial.Parity:=pOdd;
            4 : objPSerial.Parity:=pSpace;
            else
                objPSerial.Parity:=pNone;
       end;
 
       if not Conecta then begin
          result:=RSMS_ERROR;
          exit;
       end;
     {$endregion}
 
//When I call this function first time work correctly
//But when I call the function in the second time, fails
function TCelular.Conecta: boolean;
var
   borrame : string;
begin
     try
        if objPSerial.Open then begin 
           Estado := EDSMS_DESCONECTADO;
           try
              objPSerial.Open := false; //Here the programs fails
           except
                 on E:Exception do begin
                    borrame := E.Message;
                    EjecutaComando(borrame);
                 end;
           end;
        end;
 
        objPSerial.Open:=true;
        if objPSerial.Open then begin
           if EjecutaComando('AT+CPMS="ME"') = RSMS_OK then begin
              Estado:=EDSMS_LISTO;
              CONT_ERROR:= 0;
              Result := true;
           end else begin
               Inc(CONT_ERROR);
               Result := false;
           end;
        end else begin
            Inc(CONT_ERROR);
            Estado:=EDSMS_DESCONECTADO;
        end;
 
        if CONT_ERROR > 3 then begin
           result:=false;
           Estado:=EDSMS_ERROR;
           exit;
        end else begin
          if (Estado = EDSMS_DESCONECTADO)  then begin
             sleep(3000);
             Conecta;
          end;
        end;
 
     except
           on E : Exception do begin
              Estado:=EDSMS_DESCONECTADO;
              Result := false;
           end;
     end;
end;

Open in new window

AuronixAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ziolkoCommented:
lloks like problem with that TApdComPort component try using something else like this one:
http://sourceforge.net/projects/comport/

ziolko.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.