LinkOS-Android-Samples icon indicating copy to clipboard operation
LinkOS-Android-Samples copied to clipboard

How to know which device supports Zpl or CPCL?

Open MohsinIkram-Auxilium opened this issue 2 years ago • 5 comments

Hi, I have both Zebra Printing Devices which support ZPL and CPCL Languages. So I want to distinguish between both devices. I have reviewed your code, you are writing this in everywhere in your code -> ZebraPrinterFactory.getInstance(printerConnection) If I define printer with this line -> printer = ZebraPrinterFactory.getInstance(printerConnection) It always give me ZPL language. But if I write this line -> printer = ZebraPrinterFactory.getInstance(PrinterLanguage.CPCL,printerConnection) It always return me CPCL language. Kind give me best answer. I'm looking for your response. Thanks

MohsinIkram-Auxilium avatar Apr 26 '23 14:04 MohsinIkram-Auxilium

A printer can only support CPCL or ZPL at a time. It cannot support both CPCL & ZPL at the same time. The setting of the device.languages on the printer determines which label format language the printer is going to support. The application can switch the label format language at run time with the device.languages SGD (! U1 setvar "device.languages" "zpl", or ! U1 setvar "device.languages" "cpcl"). The application can also query the languages setting with the device.languages SGD (! U1 getvar "device.languages"). Once the device.languages setting on the printer is known, the application can call the getInstance() with the proper parameter, i.e., either ZebraPrinterFactory.getInstance(PrinterLanguage.CPCL,printerConnection) for CPCL printer instance, or ZebraPrinterFactory.getInstance(PrinterLanguage.ZPL,printerConnection) for ZPL printer instance. Calling ZebraPrinterFactory.getInstance(printerConnection) usually defaults to ZPL instance.

ssizebra avatar Apr 26 '23 18:04 ssizebra

@ssizebra Sorry for misunderstanding, I was saying I have two devices. One device supports ZPL and other device (ZQ210) supports CPCL Language. My scenario is I'm showing both devices in Bottom Sheet. Now how I want to know which device support ZPL or CPCL Language. So when I click on any device, I will run code according to that. So kindly if you have proper code then please send or guide me how can I distinguish between both.

MohsinIkram-Auxilium avatar Apr 27 '23 07:04 MohsinIkram-Auxilium

As mentioned early, we can use the device.languages SGD to query the printer's language as below.

printerConnection.Open();
string ptrLangStr = SGD.GET("device.languages", printerConnection);

If the ptrLangStr contains "cpcl" or "line_print", then the printer's language is set as CPCL. If the ptrLangStr contains "zpl", then the printer is in ZPL. Then we can create the proper printer instance with the correct language parameter.

ssizebra avatar Apr 27 '23 15:04 ssizebra

@ssizebra Thanks a lot its really helpful.

MohsinIkram-Auxilium avatar Apr 28 '23 06:04 MohsinIkram-Auxilium

@ssizebra can you please tell me how can I show all the connected zebra printers list in my app? Right now I'm implementing an logic but it shows all the connected Bluetooth devices with other devices as well. I just only want to show the Zebra Printers? Please guide me.

MohsinIkram-Auxilium avatar May 03 '23 12:05 MohsinIkram-Auxilium