Problem with printing zebra extension with Rhostudio 4.1

I have a problem calling the Rho::PrinterZebra api.

Actions taken:

Installed 4.1 beta 28 of rhostudio.

Made sure my existing application builds with 4.1 beta 28 and runs on android device

Added extension printing_zebra to build.yml as explained here.

Implemented a method which calls Rho::PrinterZebra.searchPrinters

Build the application again and deployed it to an android device. The build log shows printing_zebra is compiled correctly.

After application start I tested the call to Rho::PrinterZebra.searchPrinters but the log gives the following errors:

03-04 11:50:18.112: I/APP(3069): I 03/04/2014 11:50:18:122 00000c16 APP| const_missing: PrinterZebra

03-04 11:50:18.122: I/APP(3069): NameError: uninitialized constant Rho::PrinterZebra

03-04 11:50:18.212: I/APP(3069): I 03/04/2014 11:50:18:228 00000c16 APP| App error: uninitialized constant Rho::PrinterZebra

I already tried to add the require ‘printing_zebra’  but that’s not working.

Do I miss something?

Robert Galvin
Can you give some more

Can you give some more details on your setup? Device? OS version? Printer version?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Dave van der Veen
Android version: 4.3Device:

Android version: 4.3

Device: Samsung Galaxy S4

Printer: Zebra RW 420

Printer Bluetooth library version: 2.1.19

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
I am going to try this now. I

I am going to try this now. I have an MC40 (Android 4.1.1) and MZ320. I also see in the docs it says something about discovering non printer devices:

Android platfrom specific:

  • When you call searchPrinters() with Bluetooth search (with CONNECTION_TYPE_ANY or CONNECTION_TYPE_BLUETOOTH) then Zebra SDK enumerate all Bluetooth devices around and you can see a lot of pairing request to non-printer devices too. Just cancel them. This produced because we can not detect printer before real connection to device, but real connection require pairing :–).

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Dave van der Veen
Tanks for trying and I am

Tanks for trying and I am curious which printerID you get back from the zebra printer.

And I am familiar with the remark in the documentation about enumerating all Bluetooth devices. Thats why the callback is called multiple times.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
Here is some code that is

Here is some code that is used by our testing team:

var printers  = []

var discovery_finished = false;

Function callback(printer) {

  If (printer.status == Rho.Printer.STATUS_SUCCESS)

  {

        printers.push(printer);

  }

  else if (printer.status == Rho.Printer.STATUS_DONE || printer.status ==  Rho.Printer.STATUS_ERR_TIMEOUT)

  {

        discovery_finished = true;

  }

}

Rho.Printer.searchPrinters({“printerType”:Printer.PRINTER_TYPE_ZEBRA, “connectionType”: Rho.Printer.CONNECTION_TYPE_BLUETOOTH}, callback)


Then to Print


var printer = Rho.PrinterZebra.getPrinterByID(printers[0].printerID);

printer.connect();

If (printer.isConnected || printer.isReadyToPrint)

{

  printer.sendFileContents("path/to/printing_format.zpl");

  printer.printStoredFormatWithHash("Z:printing_format.zpl", {"id”:"foo", “location”:”bar", “code":123});

  printer.disconnect();

}


I know you are not getting past the connection stage, but are you going to try printing ZPL or an image (JPG/PNG)?


To connect with BT MAC address you would do something like this:

Rho.PrinterZebra.deviceAddress = '00:03:7A:42:F2:DB';

Rho.PrinterZebra.connect();


Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Robert Galvin
Hi Dave,There is an error in

Hi Dave,

There is an error in the doc. The Extensions in your build.yml should be:

extensions: ["printing","printing_zebra"]

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Dave van der Veen
Tanks for your response. Api

Tanks for your response. Api can be called now.

Is their any example code available for zebra_printing?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Dave van der Veen
When I call searchPrinters I

When I call searchPrinters I get multiple callbacks for the different bluetooth devices in the area.

All of them come back with @params['status'] == "PRINTER_STATUS_SUCCESS"

The callback for the zebra printer also comes back with @params['printerID'] == "ZEBRA_PRINTER_1"

When I use the obtained printerID to call Rho::PrinterZebra.getPrinterByID( "ZEBRA_PRINTER_1" ) the result is nil.

"ZEBRA_PRINTER_1" doesn't look like a very unique ID so I also tried to call getPrinterByID with the bluetooth address (00:22:58:39:6A:E5) and 'friendly name' (XXRCJ103900784) of my zebra printer but the result is also nil.

Any idea what the problem might be?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
Ok here is what I tried:Rho

Ok here is what I tried:

Rho.PrinterZebra.searchPrinters({"deviceAddress":"00:03:7A:4C:F2:DB"},function (e) {console.log(e);})


On device the BT Pairing dialog appeared and I entered '000'


On console log (I am using to rapidly test this, which I highly recommend), I see two callbacks. Both say success but, the first one says the ID is ZEBRA_PRINTER_1 (This is our own ID not any spoecial ID that Zebra has assigned)

Screen Shot 2014-03-05 at 9.55.55 AM.jpg

I then create an instance object myPrinter:

myPrinter = Rho.PrinterZebra.getPrinterByID('ZEBRA_PRINTER_1')


Now I connect:

myPrinter.connect()


I see the Blue light on the MZ320 light up (yeah!)


Then I issue a command to see if communication is happening

myPrinter.requestState(['PRINTER_STATE_IS_READY_TO_PRINT','PRINTER_STATE_IS_PAPER_OUT','PRINTER_STATE_IS_BATTERY_LOW'],function (e){console.log(e);})

Screen Shot 2014-03-05 at 9.56.37 AM.jpg

Then I do a test print of raw text:

myPrinter.printRawString('This is a test')

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Mark Nongkhlaw
BTW, RhoStudio 4.1 is being

BTW, RhoStudio 4.1 is being mentioned as the Subject here. Is RMS 4.1 out already?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Dave van der Veen
RhoStudio 4.1 is still in

RhoStudio 4.1 is still in beta.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Dave van der Veen
I managed to connect to the

I managed to connect to the printer using Weinre and the javascript api. Weinre is indeed ideal to test the libraries! However the following is not working for me:

myPrinter.printRawString( 'This is a test' ) 

Instead I have to send a zpl string to the printer like the following:

myPrinter.printRawString( '^XA^LH30,30

^FO20,10^ADN,90,50^AD^TESTSTRING^FS

^XZ', {}, function (e){console.log(e);} )

Using the Windows program 'Zebra Setup Utilities' I am able to print plain text. Zebra Technologies - How to Enable ZPL or Line Print Mode on Mobile Printers

Is it possible to print plain text through the RhoMobile api? Or does it depend on the printer type?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Robert Galvin
DaveTo me that tells me your

Dave

To me that tells me your printer is in ZPL mode. You will have to switch to 'line mode'. Check out the doc from Zebra: Zebra Technologies - How to Enable ZPL or Line Print Mode on Mobile Printers

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Dave van der Veen
Setting the printer once to

Setting the printer once to mode line_print is not enough. For reasons unkown to me the mode is reset to zpl mode. So before sending the lines to print, I always send the following command with printRawString to make sure line_printing is enabled.

  • ! U1 setvar "device.languages" "line_print"

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Dave van der Veen
Connecting to the zebra

Connecting to the zebra printer with bluetooth doesn't work most of the time on my Samsung Galaxy S4 with Android 4.3. LogCat shows an socket error.

Updating to 4.4 doesn't solve the problem.

I also tested it on LG Nexus 4 with android 4.4 and the error also occurs.

What to do?

Socket error.png

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments