Davide, what have you to print and which connection do you want to use?
If you want to print text or something like ESC/P commands via bluetooth, you can use this code:
BluetoothSocket socket = null;
BufferedReader inReader = null;
BufferedWriter outReader = null;
//BluetoothDevice hxm = BluetoothAdapter.DefaultAdapter.GetRemoteDevice (bt_printer);
UUID applicationUUID = UUID.FromString("00001101-0000-1000-8000-00805F9B34FB");
socket = MainActivity.PrinterBth.CreateRfcommSocketToServiceRecord(applicationUUID);
socket.Connect();
inReader = new BufferedReader(new InputStreamReader(socket.InputStream));
outReader = new BufferedWriter(new OutputStreamWriter(socket.OutputStream));
outReader.Write(printString);
outReader.Flush();
Thread.Sleep(5 * 1000);
var s = inReader.Ready();
inReader.Skip(0);
//close all
inReader.Close();
socket.Close();
outReader.Close();
where 'printString' contain all strings / command you have to print.
@Ignacio: I used your code to test printing to an IMZ220 printer. I don't get error's, I'm able to find the printer, open the stream and even write but the printer doesn't print anything. I also used ZPL / CPCL / Plain text ... Any idea's / suggestions?
thanks for your answer
socket = MainActivity.PrinterBth.CreateRfcommSocketToServiceRecord(applicationUUID); is good but
pleas give that method full reference MainActivity.PrinterBth.CreateRfcommSocketToServiceRecord(applicationUUID);
I am getting alert upto "Socket connected successfully".But The data is not printing from printer.Please suggest me any idea to get this problem solved.
@AlessandroCaliaro said:
Davide, what have you to print and which connection do you want to use?
If you want to print text or something like ESC/P commands via bluetooth, you can use this code:
BluetoothSocket socket = null;
BufferedReader inReader = null;
BufferedWriter outReader = null;
//BluetoothDevice hxm = BluetoothAdapter.DefaultAdapter.GetRemoteDevice (bt_printer);
UUID applicationUUID = UUID.FromString("00001101-0000-1000-8000-00805F9B34FB");
socket = MainActivity.PrinterBth.CreateRfcommSocketToServiceRecord(applicationUUID);
socket.Connect();
inReader = new BufferedReader(new InputStreamReader(socket.InputStream));
outReader = new BufferedWriter(new OutputStreamWriter(socket.OutputStream));
outReader.Write(printString);
outReader.Flush();
Thread.Sleep(5 * 1000);
var s = inReader.Ready();
inReader.Skip(0);
//close all
inReader.Close();
socket.Close();
outReader.Close();
where 'printString' contain all strings / command you have to print.
Posts
Davide, what have you to print and which connection do you want to use?
If you want to print text or something like ESC/P commands via bluetooth, you can use this code:
where 'printString' contain all strings / command you have to print.
@Ignacio: I used your code to test printing to an IMZ220 printer. I don't get error's, I'm able to find the printer, open the stream and even write but the printer doesn't print anything. I also used ZPL / CPCL / Plain text ... Any idea's / suggestions?
There is a problem in IOS 9 with printing, you have to open the input stream otherwise it will not print nothing
Thanks! Just before the writing, I'm opening the printersession its inputstream and right behind the write I close it.
It is working now!
@ignaciomachin
How do i Access AppDelegate.Current in xamarin forms (ios). I dont have anything called "Current" in AppDelegate
thanks for your answer
socket = MainActivity.PrinterBth.CreateRfcommSocketToServiceRecord(applicationUUID); is good but
pleas give that method full reference MainActivity.PrinterBth.CreateRfcommSocketToServiceRecord(applicationUUID);
tried this got an error............
which error
Unhandled Exception:
Java.IO.IOException: read failed, socket might closed or timeout, read ret: -1
here's my code:
I have had the same problem times ago... I don't remember how I have solved it.
Try to pair again the printer
Yep, I did. same error...
I did. same error...
PAPI:
what printer u have?
Hi @AlessandroCaliaro .I have Star Micronics Bluetooth printer I am using the below code.But it is now working.
`
mBluetoothAdapter = BluetoothAdapter.DefaultAdapter;
`
I am getting alert upto "Socket connected successfully".But The data is not printing from printer.Please suggest me any idea to get this problem solved.
Thanks in advance.
@Praveen.B try this
It is not working for Star Micronics printer @AlessandroCaliaro
Hi !
Please, exists full code ?