Print QR code on generic bluetooth printer using xamarin forms

33 Views Asked by At

I'm trying to print a QR on a generic printer using xamarin forms, when I print text I don't have problems, but when I want to print a QR code I can't. I thought it was the printer but in its demo print it does show qrs codes

**qrCodeData **has a base 64 QR code and **qrCodeBytes **is the conversion in array,

in this line bluetoothSocket?.OutputStream.Write(qrCodeBytes, 0, qrCodeBytes.Length); should print

public async Task Print(string deviceName, string text)
        {

            BluetoothDevice device = (from bd in bluetoothAdapter?.BondedDevices
                                      where bd?.Name == deviceName
                                      select bd).FirstOrDefault(); 

            string qrCodeData = Base64CodeQR();
            byte[] qrCodeBytes = Convert.FromBase64String(qrCodeData);          

            try
            {                 
              
                BluetoothSocket bluetoothSocket = device?.
                CreateRfcommSocketToServiceRecord(
                UUID.FromString("00001101-0000-1000-8000-00805f9b34fb"));

                bluetoothSocket?.Connect();
             
                bluetoothSocket?.OutputStream.Write(qrCodeBytes, 0, qrCodeBytes.Length);                 

                await Task.Delay(1000);

                bluetoothSocket.Close() ;
              

            }
            catch(Exception exp)
            {
                
                throw exp;
            }

            
        }
0

There are 0 best solutions below