lukevp / ESC-POS-.NET

Efficient, Easy to Use Thermal Printing & POS (Windows/Linux/OSX, WiFi/BT/USB/Ethernet)
MIT License
522 stars 171 forks source link

How to connect via bluetooth in xamarin forms ? #276

Open maltiparmak opened 3 months ago

maltiparmak commented 3 months ago

Hello all, I have sunmi v2s plus device and it has thermal printer. I'm working on it for a while but I can't print image. I tried this library but I can't connect to my thermal printer. I'm using this code below to connect and print. `using (BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter) { BluetoothDevice device = (from bd in bluetoothAdapter?.BondedDevices where bd?.Name == deviceName select bd).FirstOrDefault(); try { // "00001101-0000-1000-8000-00805f9b34fb" is common UUID for printer & scanner. using (BluetoothSocket socket = device?.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805F9B34FB"))) {

socket?.Connect();

//Print issues

socket.Close(); } } catch (Exception ex) { throw ex; }`

I can't figure out how to connect via this library . // USB, Bluetooth, or Serial var printer = new SerialPrinter(portName: "COM5", baudRate: 115200); How can I connect my thermal printer with this library ? I don't have any port or IP adress.

igorocampos commented 3 months ago

In #51 you can check the conversation about that. But currently you would have to manually open the socket (as you are already doing) and then send all bytes to it. You can still use this library to generate the bytes you need.