Andreas,
Thanks for your help. I made use of your code from
https://github.com/afriess/bluetoothlaz and changed the line
cnt:= fprecv(s,@bt_message, 1024, 0);
to
cnt:= fpsend(s,@bt_message, 1024, 0);
as fpwrite does not appear to be supported.
The good news is that it sent data to the printer
. Unfortunately, there was a lot of it, all in hex
I've tried code like this to send a string to the printer but without success. Just lots of hex.
if status = 0 then
begin
msg := 'Here is my test output' + #13#10;
cnt := fpsend(s, @msg, sizeof(msg), 0);
if cnt = -1 then
Memo1.Lines.Add('Error occured');
// close socket after message is sent
fpshutdown(s, 0);
Memo1.Lines.Add('end');
end;
I've obviously misunderstood the (limited) explanation of the fpsend function and / or handling the mapping of the string to the buffer.
I can achieve what I want by using the Raspbian Bluetooth Manager to create a rfcomm serial connection to the printer, then simply run this code to print out a string: lsPrintr is a TLazSerial component.
procedure TMainForm.btnBluetoothClick(Sender: TObject);
begin
if lsPrinter.Active = True then
lsPrinter.Close;
lsPrinter.BaudRate:= br__9600;
lsPrinter.Device := '/dev/rfcomm0';
lsPrinter.Open;
lsPrinter.WriteData('Test output' + #13#10);
end;
I was hoping to avoid needing (others) to use the Bluetooth Manager to create a connection to the printer before running my code but it looks like the simplest way to do it, unless you can offer any additional thoughts?
Many thanks for your support with this. It is appreciated.
Terry