Ver Mensaje Individual
  #19  
Antiguo 28-03-2008
[FGarcia] FGarcia is offline
Miembro Premium
 
Registrado: sep 2005
Ubicación: Cordoba, Veracruz, México
Posts: 1.123
Reputación: 22
FGarcia Va por buen camino
A ver, Egostar me corrige si me equivoco, hice algunos añadidos al ultimo codigo que mado PepePancho:

Código Delphi [-]
var
  Form1: TForm1;
  Cuantos, CuentaB : Integer;  //OJO AQUI SE MODIFICO
 
implementation
{$R *.dfm}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
if not ComPort.Connected then
ComPort.Open;
comport.WriteStr(#2#0);
end;
 
procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
Str: String;
begin
 ComPort.ReadStr(Str, Count);
 
 if length(Str)>= 8 then
   ShowMessage('OK')
 
 else if Str = #1 then  begin
   case Cuantos of
   1: begin
        ComPort.WriteStr(#2#2);
        Cuantos := 2;
      end;
   2: begin //Modo Escribir
        ComPort.WriteStr(#2#3);
        //ProcedimientoEscribir
        Cuantos := 3;
      end;
   3: begin //Modo Borrar
         //ProcedimientoBorrar
         showmessage('Chip Borrado.. OK!')
      end;
   end
 
//AQUI la cadena recibida vale 2
 else if Str = #2 then begin
   case Cuantos of
      1: begin
          //
          end;
      2: begin //Envia el primer byte. CuentaB vale 0.
             ComPort.WriteStr(Buffer[CuentaB]);
             Inc(CuentaB);
          end;
      
   end;

//AQUI el chip respondio a el envio del primer byte
 else if Str = #53 then begin
   case Cuantos of
      2: ProcedimientoEscribir;
   end;

 end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
 if not ComPort.Connected then
  ComPort.Open;
 comport.WriteStr(#4#1#0#1);
   Cuantos := 1;
end;
 
{Este procedimiento pretende escribir caracter a caracter sobre el
puerto serie. CuentaB es un contador que lleva el registro de las transmisiones efectuadas, siempre se 
compara su valor contra el valor de la longitud del buffer que contiene el archivo a transmitir.}

procedure TForm1.ProcedimientoEscribir;
begin
  if CuentaB <= Length(Buffer) then
    begin
      ComPort.WriteStr(Buffer[CuentaB]);
      Inc(CuentaB);
    end
  else
    ComPort.WriteStr(ByteFinTx);
end;
end.

Última edición por FGarcia fecha: 28-03-2008 a las 05:50:48.
Responder Con Cita