Developer Guide Developer Guide For Android For Android
Developer Guide Developer Guide For Android For Android
TABLE OF CONTENTS
1. AEM SDK…………………………………………………………………………..03
2. AEMPrinter Class…………………………………………………………………03
3. AEM ScrybeDevice……………………………………………………………….08
4. IAEMCard Scanner……………………………………………………………….10
5. WI FI Printer…………………………………………………….………………….11
6. Packet Protocol………………………………………………..…………………..17
7. QR Code Generation…………………………………………..………………….20
8. USB SDK…………………………………………………………..………………..21
2
SDK (Software Development Kit) for ANDROID
This document describes the use of AEM SCRYBE Thermal Printer SDK for Bluetooth, USB and WiFi
Operations. This SDK provide an Interface between an Android Application and the AEM Thermal
Printer namely SCRYBE. The SDK is android based, and requires at least 10 level of android SDK and
1.6 java compiler. It comprises of the following Interfaces, Classes and functions.
AEMPrinter: AEMPrinter class handles all the Bluetooth related functions. These include:
3
4. sendByteArray: public void sendByteArrayBT(byte[] byteArr) throws IOException
In order to send any of specific byte array (sequence) to the printer via Bluetooth, you need to
call this function and pass the desired Byte Array.
5. printInNegative: public void printInNegative() throws IOException
NEGATIVE_CHAR = 0X0E
In order to print any of specific line in Negative Text Mode you need to call this function.
Alternatively, you can use the sendByte function and simply pass the value of NEGATIVE_CHAR
as defined above.
6. enableUnderline: public void enableUnderline() throws IOException
UNDERLINE = 0X15
In order to underline any of specific line you need to call this function. Alternatively, you can
use the sendByte function and simply pass the value of UNDERLINE as defined above.
7. setLineFeed: public void setLineFeed(int noOfFeeds) throws IOException
LINE_FEED = 0X0A
In order to print specific number of blank lines or line feeds you need to call this function.
Alternatively, you can use the sendByte function and simply pass the value of LINE_FEED as
defined above. You can call sendByte multiple times for printing multiple blank lines.
8. setCarriageReturn: public void setCarriageReturn() throws IOException
CARRIAGE_RETURN = 0X0D
In order to print a single blank line you need to call this function. Alternatively, you can use the
sendByte function and simply pass the value of CARRIAGE_RETURN as defined above. You can
call sendByte multiple times for printing multiple blank lines.
9. print: public void print(String text) throws IOException
This function is used to print a specified text (in the form of a string) to the printer.
10. printHindi: public void printHindi(String text) throws IOException
In the specific Hindi Font Printer Models, this function is useful in printing Devnagri Font text
for generating Bills / Receipts in HINDI (in the form of a Unicode string). This function is only
usable in SCRYBE Printer Models that have firmware version ending in ‘H’. Use of this function
by passing a normal English (or numeric/alphanumeric) text will only print those characters
normally.
4
General Guidelines for Text Printing
5
Functions for Non-Text Printing
This function is used to print a 2-Dimensional Barcode on the Printer, generated automatically
according to the string passed to this function. The string should be of Capital English Letters or
Numerals. The maximum characters in the strings can by up to 11. Under Barcode Type, the
Printer supports BARCODE_TYPE_CODE39. The Barcode Height supported is
DOUBLEDENSITY_FULLHEIGHT.
The following packet is generated internally within this function and sent to the printer:
barcodePacket[0] = 0x1D; ‘GS’
barcodePacket[1] = 0x6B; ‘k’
barcodePacket[2] = BARCODE_TYPE_CODE39; 0x45
barcodePacket[3] = (byte) (barcodeBytes.length + 2); //length of barcode data
barcodePacket[4] = 0x2A;
barcodePacket[5] to barcodePacket[length of barcode string] = BarcodeBytes;
barcodePacket[Length of barcode string + 1] = 0x2A;
6
this function is that the print is so clear and fast that there is no perceptible difference to an
end user in understanding whether this text has been printed in the form of text or in the form
of an image.
14. printBitImage: public void printBitImage(Bitmap originalBitmap, Context context, byte
image_alignment)throws IOException
IMAGE_LEFT_ALIGNMENT = 0x6C;
IMAGE_CENTER_ALIGNMENT = 0x63;
IMAGE_RIGHT_ALIGNMENT = 0x72;
This is a deprecated function that has only been kept for backward compatibility. PrintBitImage
fiunction uses the standard ESC * algorithm for printing of a bitmap
The maximum image size should be in the following range: - 355 X 500 (WxH) pixels.
For image printing, you need to half the pixel size of height of an image to get the desired width
and height.
E.g.: - Suppose you need to print a logo of dimensions 355 X 300 (WXH) pixels, then half the
size of the height of an image i.e. 150 pixel for one time in your code by scaling function (as
explained below). Width will remain same.
Bitmapscaled_bitmap = bitmap.createScaledBitmap(bitmap, 355, 150, false);
355 pixel= Width (Original Width)
150 pixel= Height (Height will get double i.e. 300 pixels as original height of an image while
printing).
Likewise, you can print the logo of desired dimensions.
Note: - Maximum Width size is 355 pixels
Maximum Height size is 500 pixels
7
AEMScrybeDevice:
This class is used to instantiate a BLUETOOTH SCRYBE Device, containing the Context, the Bluetooth
Adapter, Bluetooth Device and Bluetooth Socket. An object of AEMScrybeDevice once instantiated, is
capable of returning the AEMPrinter object that has been described previously. This class has the
following functions:
AEMScrybeDevice
1. Constructor: For Creating the Object: public AEMScrybeDevice (IAemScrybeimpl)
2. startDiscover: public void startDiscover(Context iContext)
By calling this method, a list of local Bluetooth devices will be returned.
3. pairDevice: Public String pairDevice(String printerName)
Before pairing any printer by name, first call the method
startDiscover(Context iContext) and get the result in the method public void
onDiscoveryComplete(ArrayList<String>aemPrinterList) of the Interface IAemScrybe.
Example:
AEMScrybeDevice m_AemScrybeDevice = new AEMScrybeDevice (newIAemScrybe()
{
@Override
Public void onDiscoveryComplete(ArrayList<String>aemPrinterList)
{
// TODO Auto-generated method stub
}
});
Now call the method public String pairDevice(String printerName) which returns a String
which may be:
NOT_SCANNED when you call this method before scanning.
DEVICE_NOT_FOUND when the printer is not found.
PAIRED when the device is successfully paired
FAILED_TO_PAIREDwhen the device is failed to paired
8
4. connectToPrinter: public Boolean connectToPrinter(String printerName) throws
IOException
By calling this method, printer gets connected.
5. disConnectPrinter: public Boolean disConnectPrinter() throws IOException
By calling this method, the connected printer gets disconnected.
6. getCardReader: public CardReader getCardReader(IAemCardScannerreaderimpl)
By calling this method, you can create the object of the class CardReader by passing the
reference of the class which implements IAemCardScanner Interface.
7. AEMPrinter: public AEMPrinter getAemPrinter()
By calling this method, you can create the object of the class AEMPrinter.
8. ArrayList: public ArrayList<String>getPairedPrinters()
By calling this method, a list of paired printers is returned.
9. getSDKVersion: public String getSDKVersion()
By calling this method, SDK version is obtained.
10. BtConnStatus: public Boolean BtConnStatus()
This method returns True if the Printer is already connected on Bluetooth (Bluetooth
connection is already alive). It returns False if the connection status is False, i.e. if Bluetooth
socket is disconnected.
9
IAemCardScanner:
This method will provide the MSR card data (buffer) with track type (Track1 or Track 2). You
can decode the MSR card data by calling the method:-
This method will provide the DL card data. You can decode the DL card data (buffer) by
calling the method:-
This method will provide the RC card data. You can decode the RC card data (buffer) by
calling the method:-
10
FUNCTIONS FOR WIFI PRINTER
AEMWifiPrinter:
This Class is for communicating with AEM SCRYBE Wifi Series Printers. This class does the entire
processing for various functions such as generating the bytes for Barcode and Image.
In order to send these bytes out on a physical TCP/IP Socket, there needs to be a separate Client class
to be maintained by the user in the main Java Application Project. This class has been purposely kept
outside from the SDK so that the user can customize the messages thrown by the interfaces and
accordingly process the commands. For ease of use the AEMWifiPrinter Class has been provided so
as to carry out complex processing of Images and Barcode packet generation. Since all these
functions return array of Bytes, these bytes can be easily send out to the client socket by the user.
MyClient,java class has been provided as extending AsyncTask for the user to override the
DoinBackground and OnPostExecute functions according to the functionality as needed.
This function is used to return the byte array for printing a 2-Dimensional Barcode on the
Printer, generated automatically according to the string passed to this function. The string
should be of Capital English Letters or Numerals. The maximum characters in the strings can by
up to 11. Under Barcode Type, the Printer supports BARCODE_TYPE_CODE39. The Barcode
Height supported is DOUBLEDENSITY_FULLHEIGHT. The following packet is generated internally
within this function and sent to the printer:
barcodePacket[0] = 0x1D; ‘GS’
barcodePacket[1] = 0x6B; ‘k’
barcodePacket[2] = BARCODE_TYPE_CODE39; 0x45
barcodePacket[3] = (byte) (barcodeBytes.length + 2); //length of barcode data
barcodePacket[4] = 0x2A;
barcodePacket[5] to barcodePacket[length of barcode string] = BarcodeBytes;
barcodePacket[Length of barcode string + 1] = 0x2A;
11
2. printImage: public byte[] printImage(Bitmap originalBitmap) throws IOException
This function returns the byte array for printing an Image in the form of a Raster Image, based
on the standard ESC/POS Raster Image command set of GS v protocol. You need to pass the
bitmap of the desired image to be printed. Please note that this function can be used to print
QR Codes as well, by first generating the QR code from a given string and thereafter, sending its
bitmap to the PrintImage Function. The source code for generating the QR Code has been
provided at the end of this document.
/**
* Constructor with Host, Port and MAC Address
12
*/
public MyClient(String text,Context context) {
this.dstAddress = text;
this.dstPort = 9100;
this.context = context;
}
@Override
protected Socket doInBackground(Void... arg0) {
try {
this.socket = new Socket(dstAddress, dstPort);
Log.i("SocketConnection",this.socket+"");
13
}
return this.socket;
}
@Override
protected void onPostExecute(Socket result) {
try{
if (result!=null)
{
((MainActivity)context).onSuccess(this.response,this.socket,dstAddress,dstPort,out);
}
else
{
((MainActivity)context).onError(this.response);
}
//super.onPostExecute(result);
}
catch (Exception ec){
((MainActivity)context).onError(this.response);
}}
14
try {
socket.close();
while(true)
{
if(socket.isClosed() == true)
{
retVal = 1;
return retVal;
}
}
} catch (IOException e) {
((MainActivity)context).onError(this.response);
}
}
}
return retVal;
}
}
15
Packet Protocol
16
Responses from Printer:
Packet Structure:
Response table:
17
Bit Map Image Print – Note that this method of Printing is only maintained for the purpose of Backward
compatibility. The Faster, easier, clearer and more standard way of printing is by using PrintImage
function and passing it a Bitmap object.
1. Select the image either from PC or from mobile's SD card.
2. Convert the image into monochrome bmp.
3. Resize the image to fit into the printer paper area if it is exceeding
4. Now read the processed image through fileinputstream and save it into byte array.
5. Make the packet of image and then send it to printer over outputstream.
Mode M (In Hex ) Mode M Description Vertical Dot Horizontal Dot Max Dot/Line
0x64 Single width single height 1 1 384 (48 bytes)
0x65 Single width double height 2 1 384
0x66 Single width triple height 3 1 384
0x67 Single width Quad. height 4 1 384
0x68 Double width single height 1 2 192 (24 bytes)
0x69 Double width double height 2 2 192
0x6A Double width triple height 3 2 192
0x6B Double width Quad. Height 4 2 192
0x6C Triple width single height 1 3 128 (16 bytes)
0x6D Triple width double height 2 3 128
0x6E Triple width triple height 3 3 128
0x6F Triple width Quad. height 4 3 128
Mode Table
18
QR Code Generation Function:
public void onPrintQRCode(View v) throws WriterException, IOException
{
Writer writer = new QRCodeWriter();
String text= editText.getText().toString();
String finalData = Uri.encode(text, "UTF-8");
showAlert("QR " + text);
try
{
BitMatrix bm = writer.encode(finalData,BarcodeFormat.QR_CODE, 300, 300);
Bitmap bitmap = Bitmap.createBitmap(300, 300, Config.ARGB_8888);
for(int i = 0; i < 300; i++)
{
for(int j = 0; j < 300; j++)
{
bitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK: Color.WHITE);
}
}
19
SDK FOR ACCESSING ANDROID USB
usbsdk:
The USB SDK for AEM Printers contains the basic USBController class for accessing the USB interface
of an ANDROID Device.
usbController Class:
20
7. handleMessage: void handleMessage(Message msg)
This is to be overridden in the following manner:
break;
default: break;
}
}
};
21