![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
#2
|
|||
|
|||
|
Los visores más sencillos suelen comunicarse con el puerto serie del ordenador. Para manipularlos simplemente tienes que enviar las cadenas que quieres visualizar por el puerto serie. Tienes varios metodos para hacerlo:
1) Con un componente especializado en puerto serie (por ejemplo CportLib) es una buena solución. 2) Abriendo el puerto com como si se tratara de un fichero texto Código:
procedure imprimehola; var F: Textfile; begin assign(F,'com1'); rewrite(F); writeln(F,'HOLA VISOR') closefile(F); end; Código:
function AbrirPuerto(puerto : String) : THandle;
var
hCom : Thandle;
cb : Tdcb;
begin
hCom:=CreateFile(Pchar(puerto),
GENERIC_WRITE,0,nil,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);
BuildCommDCB(Pchar(puerto+': baud=9600 parity=N data=8 stop=1'),cb);
cb.Flags:=$2000;
EscapeCommFunction(hCom,SETXON);
EscapeCommFunction(hCom,SETXOFF);
SetCommState(hCom, cb);
AbrirPuerto:=hCom;
end;
procedure writestring(s : string; hCom : THandle);
var
i : integer;
begin
EscapeCommFunction(hCom,SETRTS);
EscapeCommFunction(hCom,SETDTR);
for i:=1 to length(s) do
writebyte(ord(s[i]), hCom);
end;
procedure writebyte(c : Byte; hCom : THandle);
var
n : dword;
p : Byte;
z : Pbyte;
ovr : TOverlapped;
begin
p:=c;
z:=@p;
EscapeCommFunction(hCom,SETRTS);
EscapeCommFunction(hCom,SETDTR);
WriteFile(hCom,z^,1,n,@ovr);
end;
4) Con una rutina en assembler (te lo desaconsejo, no funciona bien con NT y derivados.). Código:
procedure Manda3Displ(Str : string);
begin
If TipoDisplay = 3 then
Asm
Cld
Lea Si,Str
Segss LodSB
StoSB
XOR AH,AH
XCHG AX,CX
JCXZ @2
@1:
SEGSS LODSB
MOV DX,0
MOV AH,1
INT 14H
STOSB
LOOP @1
@2:
end;
end;
Código:
Function AbreImpresora(PrinterName:String):Thandle;
var
DocInfo1:TDocInfo1;
Handle:Thandle;
begin
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
ShowMessage('error ' + IntToStr(GetLastError));
AbreImpresora:=Handle;
Exit;
end;
with DocInfo1 do begin
pDocName := PChar('Programa TPV');
pOutputFile := nil;
pDataType := 'RAW';
end;
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
AbreImpresora:=Handle;
end;
Procedure Imprime(Handle:THandle; S:String);
var
N: DWORD;
begin
S:=S+char(13)+CHar(10);
WritePrinter(Handle, PChar(S), Length(S), N);
end;
Procedure CierraImpresora(Handle:Thandle);
begin
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;
procedure RawPrinter(PrinterName:String; S:String);
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
begin
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
ShowMessage('error ' + IntToStr(GetLastError));
Exit;
end;
with DocInfo1 do begin
pDocName := PChar('Programa TPV');
pOutputFile := nil;
pDataType := 'RAW';
end;
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(S), Length(S), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;
6) La ultima forma y la que se deberia emplear es a traves de ole por Opos (una especie de API especializada para manejar impresoras de tiquets, visores clientes, teclados de TPV etc...) Desgraciadamente la documentación del Opos es muy confusa y sin ejemplos claros (al menos hace unos años) y no todos los dispositivos de TPV tienen 'drivers' Opos. |
| Herramientas | Buscar en Tema |
| Desplegado | |
|
|
|