Sending ZXING generated barcode/QRcode to a Bluetooth Printer

Hello,
My first question, Is there a way to use the Zebra SDK with any other Printer?? Second, Here is a very simple code,
MainActivity.cs:

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Graphics;
using ZXing;

namespace QR_Code_Scanner
{
[Activity(Label = "QR_Code_Scanner", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        ImageView view = FindViewById<ImageView> (Resource.Id.qrCodeView);
        Button scannerButton = FindViewById<Button> (Resource.Id.scannerButton);
        view.SetImageBitmap (GetQRCode ());

        scannerButton.Click += async (sender, e) => {
            var scanner = new ZXing.Mobile.MobileBarcodeScanner(this);
            var result = await scanner.Scan();

            //Console.WriteLine(result.Text);
            Toast.MakeText(this, result.Text, ToastLength.Long).Show();


        };
    }

    private Bitmap GetQRCode()
    {
        var writer = new BarcodeWriter 
        {
            Format = BarcodeFormat.QR_CODE,
            Options = new ZXing.Common.EncodingOptions 
            {
                Height = 600,
                Width = 600
            }
        };
        return  writer.Write ("LEC-15 8320");
    }
}

}
Is there a way to send this output to the BlueTooth Printer??

Thanks

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you can take a look to these documents

    https://developer.zebra.com/community/technologies/printers/label-printers/blog/2016/04/25/cross-platform-app-development-for-printing.
    I have never used this SDK (it's very young).

    Usually you could use directly printer command. I don't remember which command languages use Zebra, I think they use ESC/PL or ZPL https://zebra.com/content/dam/zebra/manuals/en-us/software/zpl-zbi2-pm-en.pdf

    For example in ZPL I think you should send ^BC for a Code128

  • janomardonesjanomardones Member ✭✭

    Hello Tayyab, Could you send the barcode to the BTprinter ?
    I generate the barcode, but i don´t know how to send it to the BTprinter.

    any help?

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    I think you should have a printer Sdk or you can open a Bluetooth socket and send data to te printer using the socket
  • TayyabHussainTayyabHussain USMember ✭✭

    Dear janomardones

    I used an HPRT MPT-II bluetooth print. The printer had an SDK in Java. I converted it to DLL using the Binding Library project. after conversion

    In the MainActivity

    Along with other variables I declared
    int portOpen = -1;
    BluetoothDevice device;
    BluetoothAdapter blue = null;
    .
    .
    .

    blue = BluetoothAdapter.DefaultAdapter; // getting bluetooth default adapter
    device = (from bd in blue.BondedDevices
    where bd.Name == "MPT-II"
    select bd).FirstOrDefault();

    In the Activity where the barcode to be printed

    // Define the Barcode
    private Bitmap GetQRCode()
    {
    var writer = new BarcodeWriter
    {
    Format = BarcodeFormat.CODE_128, // BarcodeFormat member of the ZXing Class
    Options = new ZXing.Common.EncodingOptions
    {
    Height = 75,
    Width = 400,
    Margin = 5
    }
    };

            return writer.Write(plateNumber);
    

    // The SDK in Action

    HPRTPrinterHelper.PrintBitmap(GetQRCode(), 0, 0); // Where the Barcode gets printed

  • janomardonesjanomardones Member ✭✭

    Thanks to you both, i'll try the solution and i will tell you how it´s going.

    Thanks Alessandro and Tayyab

  • janomardonesjanomardones Member ✭✭

    ah! .... i'm using the same printer ..

  • janomardonesjanomardones Member ✭✭

    Hello Tayyab, i'm trying to use the SDK but when i use the PortOpen Method the App goes down.
    I´m doing this.

    `
    ....
    blue = BluetoothAdapter.DefaultAdapter; // getting bluetooth default adapter
    device = (from bd in blue.BondedDevices
    where bd.Name == "MTP-II"
    select bd).FirstOrDefault();

    HPRTPrinterHelper.PortOpen("Bluetooth,"+device.Address);
    HPRTPrinterHelper.PrintText("Probando ...");
    HPRTPrinterHelper.PortClose();
    `

    Can you show me how did you use the PortOpen Method?

    Regards

  • TayyabHussainTayyabHussain USMember ✭✭
    edited April 2

    //Global Variable Section
    private Button mBtnSave;

            protected override void OnCreate(Bundle savedInstanceState)
        {
        .
        .
        mBtnSave = FindViewById<Button>(Resource.Id.btnSave);
    
    
            mBtnSave.Click += (object sender, EventArgs args) =>
            {
    
                    Boolean IsPortOpen = HPRTPrinterHelper.IsOpened;
    
                    if (IsPortOpen == true)
                    {
                // Your Program Logic Goes Here
                .
                .
                .
        else
                {
                    Some Else Statements;
                } //For the else statement
            } // For the if statement   
        }
    }
    
  • janomardonesjanomardones Member ✭✭

    Thanks.

    It seems that the error is in the library (SDK) cause any method (PortOpen, PortClose, IsOpened, etc) that i try to use is getting an error.
    The error description is: "java.Lang.UnsatisfiedLinkError"

  • TayyabHussainTayyabHussain USMember ✭✭
    How did you compile the library? While compiling did you take care of the .so files? finally what version Of android you are using?
  • janomardonesjanomardones Member ✭✭

    In Visual Studio I made a new Binding Library (Android) project and then I generate the DLL file, wich i use in my Xamarin project.

    No, i didn´t take care of .so files (i´ll figure out how to do that)

    Android version is 5.0.1

  • janomardonesjanomardones Member ✭✭

    Where i have to add de .so files? In the Binding Library project? Under Additions folder? ....

  • TayyabHussainTayyabHussain USMember ✭✭
    edited April 4
    I'll share some pics to guide out to to add .so files... let me prepare them. What version of Android you are using?
  • janomardonesjanomardones Member ✭✭
    Android versión is Android 5.0 (Lollipop)
  • janomardonesjanomardones Member ✭✭
    Hello!! I got a question.. the .so files must been added into the Binding library project or into my “mobileApp project
  • TayyabHussainTayyabHussain USMember ✭✭
    Binding library projectp
  • TayyabHussainTayyabHussain USMember ✭✭
    Like this
  • janomardonesjanomardones Member ✭✭
    Thanks, i’ll try that way
  • janomardonesjanomardones Member ✭✭

    Hi TayyabHussain, me again ...
    i´m still trying to make printer works for PDF417 barcodes.

    when i'm trying to open port the application crashes.

    the error description identifies linenumber 1570.
    well, in runtime i see that __id variable is with no value. (see pic)

    The error descrption is :
    "
    at Java.Interop.JniEnvironment+StaticMethods.GetStaticMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x0005b] in :0
    at Java.Interop.JniType.GetStaticMethod (System.String name, System.String signature) [0x0000c] in
    :0
    at Java.Interop.JniPeerMembers+JniStaticMethods.GetMethodInfo (System.String encodedMember) [0x00036] in
    :0
    at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeInt32Method (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00000] in
    :0
    at HPRTAndroidSDK.HPRTPrinterHelper.PortOpen (System.String p0) [0x00021] in C:\XamarinProjects\sdk_printer_android\obj\Debug\generated\src**\HPRTAndroidSDK.HPRTPrinterHelper.cs:1570 **
    "

    i don´t know hao to fix this.
    Hope your help, tks !!

  • janomardonesjanomardones Member ✭✭

    Finally, i solve this issue generating de project in other location.

    But i have another issue now. When i run de app it crashes with this msg,

    "... ase.apk"],nativeLibraryDirectories=[/data/app/com.companyname.VentApp-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find **"libhprt_printer_model.so" **"

    Any idea about this? How i add this so files at the Android Project?

    Tks in advance ..

Sign In or Register to comment.