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;
procedure Tform3.Inicia(baud: string);
var
CommTimeouts : TCommTimeouts;
CommConfig: TCommConfig;
sizeConfig : Cardinal;
begin
salidapentra := tstringlist.Create; 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); dcb.ByteSize := 8; dcb.Parity := 0; dcb.StopBits := 0;
end;
if not SetCommConfig(hCommFile, CommConfig, sizeConfig) then
raise Exception.Create('Problemas al querer establecer la configuracion');
end;
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];
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));
end
else if resultado = chr(4) then
begin
EscribirBuffer(chr(06));
salidapentra.Clear;
end
else
begin
CopiaRenglon(resultado);
EscribirBuffer(chr(06));
end;
end;
end; 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
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