Forum Xamarin Xamarin.iOS

zebra bluetooth printers

2»

Posts

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    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?

  • ignaciomachinignaciomachin USMember ✭✭

    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!

  • BjornBBjornB USMember ✭✭✭

    @ignaciomachin

    How do i Access AppDelegate.Current in xamarin forms (ios). I dont have anything called "Current" in AppDelegate

  • BappiBappi BDMember ✭✭

    thanks for your answer
    socket = MainActivity.PrinterBth.CreateRfcommSocketToServiceRecord(applicationUUID); is good but
    pleas give that method full reference MainActivity.PrinterBth.CreateRfcommSocketToServiceRecord(applicationUUID);

  • EL_PAPIEL_PAPI USMember ✭✭

    tried this got an error............

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @EL_PAPI said:
    tried this got an error............

    which error

  • EL_PAPIEL_PAPI USMember ✭✭

    Unhandled Exception:

    Java.IO.IOException: read failed, socket might closed or timeout, read ret: -1

    here's my code:

                    if (d.Name.ToString().Trim() == "pigeon02")
                    {
                        applicationUUID = UUID.FromString(d.GetUuids().ElementAt(i).Uuid.ToString());
                        socket = d.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();
                        x = 1;
                    }
    
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I have had the same problem times ago... I don't remember how I have solved it.

    Try to pair again the printer

  • EL_PAPIEL_PAPI USMember ✭✭

    @AlessandroCaliaro said:
    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...

  • EL_PAPIEL_PAPI USMember ✭✭
    edited June 2017

    @AlessandroCaliaro said:
    I have had the same problem times ago... I don't remember how I have solved it.

    Try to pair again the printer

    I did. same error...

  • michelizquierdomichelizquierdo USMember ✭✭

    PAPI:

    what printer u have?

  • Praveen.BPraveen.B INMember ✭✭

    Hi @AlessandroCaliaro .I have Star Micronics Bluetooth printer I am using the below code.But it is now working.

    `
    mBluetoothAdapter = BluetoothAdapter.DefaultAdapter;

                if (mBluetoothAdapter == null)
                {
                    await MyFavHelper.InformUser("No bluetooth adapter found", "Bluetooth");
                    return;
                }
                else
                {
                    await MyFavHelper.InformUser("Bluetooth found", "Success");
                }
    
                if (!mBluetoothAdapter.IsEnabled)
                {
                    mBluetoothAdapter.Enable();
                }
                else
                {
                    await MyFavHelper.InformUser("Bluetooth Enabled", "Success");
                }
    
                ICollection<BluetoothDevice> pairedDevices = mBluetoothAdapter.BondedDevices;
    
                if (pairedDevices.Count > 0)
                {
                    foreach (BluetoothDevice device in pairedDevices)
                    {
                        if (device.Name.Contains("TSP"))
                        {
                            mmDevice = device;
                            break;
                        }
                    }
                }
                else
                {
                    await MyFavHelper.InformUser("Paired Devices not found", "Bluetooth");
                    return;
                }
    
                ParcelUuid uuid = mmDevice.GetUuids().ElementAt(0);
                //UUID.FromString("00001101-0000-1000-8000-00805f9b34fb");
    
                if (mmDevice == null)
                {
                    await MyFavHelper.InformUser("No Device Found", "Sorry");
                }
    
                mmsSocket = mmDevice.CreateInsecureRfcommSocketToServiceRecord(uuid.Uuid);
    
                mmsSocket.Connect();
    
                if (mmsSocket.IsConnected)
                {
                    await MyFavHelper.InformUser("Socket Connected Successfully", "Success");
                }
                else
                {
                    await MyFavHelper.InformUser("Socket Not Connected Successfully", "Sorry");
                }
    
                var datastream = mmsSocket.OutputStream;
    
                byte[] byteArray = Encoding.ASCII.GetBytes("Sample Text");
    
                datastream.Write(byteArray, 0, byteArray.Length);
    

    `

    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.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Try to add some \r\n at the end of your string
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @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.

    @Praveen.B try this

  • Praveen.BPraveen.B INMember ✭✭

    It is not working for Star Micronics printer @AlessandroCaliaro

  • gladsonreisgtrgladsonreisgtr Member ✭✭

    Hi !
    Please, exists full code ?

Sign In or Register to comment.