Connect via Bluetooth with Delphi XE7 using portable printer -
i'm trying communicate sewoo lk-p32 printer via bluetooth. using delphi xe7. made few examples come delphi , not having success. put paired printer in tablet , not able print continuously.
when print have restart application, can print again. below sources.
could me? support on issue? time short try other technologies.
method initiates communication printer
procedure tform2.buttonclickstart(sender: tobject); var msg, texto: string; i, b: integer; bluetoothadapter: tbluetoothadapter; listadeaparelhospareados: tbluetoothdevicelist; lservices: tbluetoothservicelist; begin try memo1.lines.add('ponto 1'); fbluetoothmanager := tbluetoothmanager.current; if fbluetoothmanager = nil memo1.lines.add('fbluetoothmanager esta nulo'); memo1.lines.add('ponto 2'); bluetoothadapter := fbluetoothmanager.currentadapter; if bluetoothadapter = nil memo1.lines.add('bluetoothadapter esta nulo'); listadeaparelhospareados := bluetoothadapter.paireddevices; memo1.lines.add('ponto 3'); if listadeaparelhospareados = nil memo1.lines.add('listadeaparelhospareados esta nulo'); := 0 listadeaparelhospareados.count - 1 begin ldevice := listadeaparelhospareados[i] tbluetoothdevice; if ldevice.ispaired begin lservices := ldevice.getservices; b := 0 lservices.count - 1 begin servicegui := guidtostring(lservices[b].uuid); guid := lservices[b].uuid; servicename := lservices[b].name; memo1.lines.add(lservices[b].name + ' --> ' + servicegui); memo1.gototextend; end; end; end; except on e: exception begin msg := e.message; memo1.lines.add('erro ao conectar na impressora: ' + msg); memo1.gototextend; end; end; end;
method sends text printer
procedure tform2.buttonclicksendtext(sender: tobject); var fsocket: tbluetoothsocket; tosend: tbytes; msg, texto: string; begin try memo1.lines.add('aparelho pareado:' + booltostr(ldevice.ispaired)); memo1.lines.add('dados guid:' + guidtostring(guid)); fsocket := ldevice.createclientsocket(guid, true); if fsocket = nil memo1.lines.add('fsocket nulo'); memo1.lines.add('criou bluetooth cliente.'); memo1.gototextend; if fsocket <> nil begin // fsocket.connect; fsocket.connect; memo1.lines.add('criou socket cliente com o serversocket'); texto := #27 + '|ca' + 'teste' + #13#10; tosend := tencoding.utf8.getbytes(texto); fsocket.senddata(tosend); memo1.lines.add('enviou ' + texto + ' para impressora.'); end else begin memo1.lines.add('fsocket nulo.'); end; except on e: exception begin msg := e.message; memo1.lines.add('erro ao conectar na impressora: ' + msg); memo1.gototextend; end; end; end;
in loop, keep assigning ldevice
. if there second unpaired device ldevice
pointing that. need top exit
once have detected paired.
also, don't raising exceptions deliberately. if class instance nil should exit, nolt drill down it..
for instance
if fbluetoothmanager = nil begin memo1.lines.add('fbluetoothmanager esta nulo'); exit; end;
Comments
Post a Comment