API description: Difference between revisions

From wizarPOS
No edit summary
Line 1: Line 1:
== Printer API ==
  There are three layers of printer API, the lower layer is C, the device provid C interface, and the third app to write their own JNI source by calling the C interface.
  The middle layer is JNI interface, wizarPOS write JNI source and generate the device so files, so the third app just use the JNIInterface to finish the calling.
  The upper layer is Java interface, wizarPOS provide Java interface for the third app, the third app only need to import the .aar pakcage to their libs.
  The app should request permission in manifest file. The permission is '''''android.permission.CLOUDPOS_PRINTER'''''
=== C interface ===
==== Functions ====
==== Functions ====
The calling sequence is open>query_status>begin>write>end>close.
The calling sequence is open>query_status>begin>write>end>close.
Line 76: Line 70:
===== read =====
===== read =====
===== query_voltage =====
===== query_voltage =====
==== Sample ====
=== JNI interface ===
==== Functions ====
===== open =====
  native static int open()
===== close=====
  native static int close()
===== begin=====
  native static int begin()
===== end=====
  native static int end()
===== write=====
  native static int write(byte arryData[], int nDataLength);
===== read=====
  native static int read(byte arryData[], int nDataLength, int nTimeout);
===== write=====
  native static int write(byte arryData[], int offset, int nDataLength);
===== queryStatus=====
  native static int queryStatus();
===== queryVoltage=====
  native static int queryVoltage(int[] pCapacity, int[] pVoltage);
===== isOpened=====
  native static boolean isOpened();
==== Sample ====
==== Sample ====
   The following code shows how to print some content:
   The following code shows how to print some content:
Line 138: Line 108:
   }
   }
  PrinterInterface.close();
  PrinterInterface.close();
=== Java interface ===
==== [http://{{SERVERNAME}}:9292/wizarposapi/ Java API]====
==== Sample ====

Revision as of 10:21, 3 April 2018

Functions

The calling sequence is open>query_status>begin>write>end>close.

open
 int printer_open()

Open the printer device.This operation should be used before other operations.

Parameters

Returns

The result code, >= 0, success; <0 error code.

begin
 int printer_begin()

Prepare to print, the app should print data after this funciton.

Parameters

Returns

The result code, >= 0, success; <0 error code.

end
 int printer_end()

End to print,the begin and end apis are pair operations.

Parameters

Returns

The result code, >= 0, success; <0 error code.

close
 int printer_close()

Close the device.The open and close apis are pair operations. If you don’t want to use the device, you should call close to release the device.

Parameters

Returns

The result code, >= 0, success; <0 error code.

query_status
 int printer_query_status()

Query the status of the printer.This api should be used inner open and close, but not inner begin and end.


Parameters

Returns

The result code, == 1, has paper; == 0, success; <0 error code.

write
 int printer_write(unsigned char* pData, int nDataLength)

Write data to the device. The data can be String, Bitmap data or ESC command.


Parameters

pData data or ESC command
nDataLength Length of data

Returns

The result code, >= 0, success; <0 error code.

read
query_voltage

Sample

 The following code shows how to print some content:
 int result = PrinterInterface.open();
 if (result <0){
   return;
 }
 Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(),
               R.drawable.printer_barcode_low);
 byte[] arryBeginText = null;
 byte[] arryEndText = null;
 try {
   arryBeginText = mContext.getResources().getString(R.string.print_QR_code).getBytes("GB2312");
   arryEndText = "This is a Bitmap of Barcode".getBytes("GB2312");
 } catch (UnsupportedEncodingException e) {
   e.printStackTrace();
 }
 int result = PrinterInterface.begin();
 if (result <0){
   return;
 }
 result = PrinterInterface.write(arryBeginText, arryBeginText.length);
 if (result <0){
   return;
 }
 // print line break
 writeLineBreak(2);       
 PrinterBitmapUtil.printBitmap(bitmap, 0, 0, true);
 // print line break
 writeLineBreak(2);
 // print text
 write(arryEndText);
 // print line break
 writeLineBreak(2);
 result = PrinterInterface.end();
 if (result <0){
   return;
 }
PrinterInterface.close();