Ver Mensaje Individual
  #6  
Antiguo 28-08-2012
gobarrio gobarrio is offline
Registrado
NULL
 
Registrado: jul 2012
Posts: 3
Reputación: 0
gobarrio Va por buen camino
pentra 80 astm

hola ibidi, primero te cuento que soy bioquimico y no un profesional de computacion, solo amateur y programo para mi uso, esto lo aclaro porque mis programas no son muy limpios ni tampoco versatiles, en nuestro laboratorio pusimos un pentra 80 y como el sistema es propio buscamos hacerle la interface, solo la hice unidireccional pues como trabajamos con codigo de barras ponemos los hemogramas en los racket y luego trasmitimos los resultados a una interface que luego de validar mandamos al sistema, en la base de datos usamos mysql. bueno te voy a copiar las rutinas, como soy nuevo en este foro no se cuanto puedo subir directamente.
Código Delphi [-]
procedure TForm3.FormCreate(Sender: TObject);
begin

  inicia(edit1.Text);

end;

{ahora abre el puerto y pone los parametros}

procedure Tform3.Inicia(baud: string);
 var
     CommTimeouts : TCommTimeouts;
     CommConfig: TCommConfig;
     sizeConfig :  Cardinal;
begin
   salidapentra := tstringlist.Create; // inicia la variable
   sPuerto := 'COM1';
   hCommFile := CreateFile(PChar(sPuerto),
     GENERIC_READ or GENERIC_WRITE, 0, nil,
       OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

  if hCommFile=INVALID_HANDLE_VALUE then begin
      ShowMessage('Unable to open for write '+ sPuerto);
  end;
   with CommTimeouts do
   begin
     ReadIntervalTimeout := 0;
     ReadTotalTimeoutMultiplier := 0;
     ReadTotalTimeoutConstant := 300;
     WriteTotalTimeoutMultiplier := 0;
     WriteTotalTimeoutConstant := 200;
   end;
     if not SetCommTimeouts(hCommFile, CommTimeouts) then
       raise Exception.Create('Problemas estableciendo CommTimeouts');
 
     GetCommConfig(hCommFile, CommConfig, sizeConfig);
     with CommConfig do
     begin
         dcb.BaudRate := strtoint(baud);    //9600;//38400;// <-- Se comunica a esa velocidad ????
         dcb.ByteSize := 8; //8;
         dcb.Parity   := 0;  //NOPARITY; //EVENPARITY;
         dcb.StopBits := 0;
     end;
     if not SetCommConfig(hCommFile, CommConfig, sizeConfig) then
     raise Exception.Create('Problemas al querer establecer la configuracion');
end;

// escritura de ACK para que responda el pentra ( el manda un ENQ)

procedure TForm3.Button1Click(Sender: TObject);
begin
  EscribirBuffer(chr(06));

end;


procedure Tform3.EscribirBuffer(lsMensaje: string);
 var
   NumberWritten:dword;
 begin
   if hCommFile = INVALID_HANDLE_VALUE then
     raise Exception.Create('No se puede enviar los datos');
   WriteFile(hCommFile, PChar(lsMensaje)^,
     Length(lsMensaje), NumberWritten, nil);
 end;
 

 function Tform3.LeerBuffer: string;
 var
   sTmp: string;
     c1: integer;
     chBuffer: array[0..255] of char;
     NumberOfBytesRead: dword;
 begin
   if hCommFile=INVALID_HANDLE_VALUE then
     Exit;
   if not ReadFile(hCommFile, chBuffer,
     sizeof(chBuffer), NumberOfBytesRead, nil) then
         raise Exception.Create('Imposible leer datos desde el puerto');
   for c1:= 0 to NumberOfBytesRead - 1 do
     sTmp:= sTmp+chBuffer[c1];
   result:=sTmp;
 end;

procedure TForm3.Timer1Timer(Sender: TObject);
var
resultado, practica : string;
lineas : integer;
contador : integer;
begin
  resultado := LeerBuffer;
  contador := strtoint(edit2.Text);
 if resultado <> '' then
   begin
     lineas := salidapentra.Count;
        practica := resultado[11]+resultado[12]+resultado[13];
        //((resultado = chr(4)) and (lineas > 10)) or (resultado[3] = 'L') or ((resultado[3] = 'P') and (lineas > 10))
        if practica = 'MPV' then
         begin
           CopiaRenglon(resultado);
           PasaaTabla;
           contador := contador + 1;
           edit2.Text := inttostr(contador);
           EscribirBuffer(chr(06));
         end
         else
         begin
           if resultado = chr(05) then
              begin
               EscribirBuffer(chr(06));
              // Leer;
              end
             else if resultado = chr(4) then
              begin
              EscribirBuffer(chr(06));
              salidapentra.Clear;
             //  timer1.Enabled := false;
            //   spblee.Caption := 'Presionar para leer el Puerto';
              end
              else
              begin
               CopiaRenglon(resultado);
               EscribirBuffer(chr(06));
             //  Leer;
              end;
         end;
   end; // del if resultado
end;

procedure Tform3.Leer;
var
resultado : string;
begin
 resultado := LeerBuffer;
 if resultado = '' then
   begin

     Leer;
   end
   else
   begin
    if resultado = chr(4) then
     begin
       PasaaTabla;
       Leer;

     end
     else
     begin
       if resultado = chr(05) then
          begin
           EscribirBuffer(chr(06));
           Leer;
          end
          else
          begin
           CopiaRenglon(resultado);
           EscribirBuffer(chr(06));
           Leer;
          end;
     end;
   end;

end;

procedure Tform3.CopiaRenglon(renglon: string);
begin
 // salida.Lines.Add(renglon);
  salidapentra.Add(renglon);
end;

como veras utilizo un timer para ir leyendo, y un campo memo (salidapentra) para ir cargando la lectura solo porque fue mas facil

espero te sirva, ahora compramos un mindray bs400 y estamos tratando de hacer la interface esta es por tcp/ip pero tambien en el protocolo ASTM
asi que estoy estudiando el manejo de socket en delphi de lo qque no se nada.

espero te sirva, no te paso la interface pues esta muy orientada a mi base de datos y no sirve para ninguna mas.

saludos

Última edición por Casimiro Noteví fecha: 05-10-2012 a las 23:42:08.
Responder Con Cita