Download GprinterSDK
GprinterSDK can download Jia Bo printer click on the official website GprinterSDK , or contact customer service, you can download.
First, the project will be imported into gprinter.jar
In eclipse, the gprinter.jar libs file copied to the project folder.
Second, establish communication with the printer
1, target acquisition device
GpDevice mDevice = new GpDevice();
2, the callback function registered to receive data (this interface is used to receive data)
mDevice.registerCallback(this);
3, turn on Bluetooth, USB, Ethernet port
Bluetooth communication :
a, you need to obtain permission Bluetooth operation, in AndroidManifest.xml, add the following code
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH" />
b, open API calls Bluetooth
1
|
mDevice.openBluetoothPort(Context context,String addr);
|
context to context, addr Bluetooth address. Such as Bluetooth address "98: D3: 31: 40: 27: D7", the call
mDevice.openBluetoothPort(MainActivity.this,"98:D3:31:40:27:D7");
USB communication
a, USB need to obtain operating authority, in AndroidManifest.xml, add the following code
<uses-feature android:name="android.hardware.usb.host" />
B, register USB device insertion and removal broadcasting, in AndroidManifest.xml, add the following code
<intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> </intent-filter> <intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" /> </intent-filter> <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" /> <meta-data android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" android:resource="@xml/device_filter" />
C, device_filter.xml USB devices filter file, which is stored in the USB device VID and PID number, only the matching device USB plug, USB is inserted or removed in order to produce broadcast, device_filter.xml need to be placed at res / xml folder, file format, e.g. Gp2120TL label printer VID 1280 is the 26728 PID
<?xml version="1.0" encoding="utf-8"?><resources> <usb-device vendor-id="26728" product-id="1280" /> </resources>
d, older versions of the Android SDK USBhost is not supported, the minimum SDK version 12, required to join the
android:minSdkVersion="12"
e, calls the USB port open API
mDevice.openBluetoothPort(MainActivity.this);
网口 communication
a, needs to obtain network operating authority, in AndroidManifest.xml, add the following code
<uses-permission android:name="android.permission.INTERNET" />
b, Ethernet port API calls
IP network such as the initial Jia Bo printer for printing 192.168.123.100 port 9100
1
|
mDevice.openEthernetPort(“
192.168
.
123.100
”,
9100
)
|
4, turn off Bluetooth, USB, Ethernet port
API call to close ports
mDevice.closePort();
5, the transmission data
API data is sent immediately
Transmitting data in the transmission buffer
mDevice.sendData(Vector<Byte> data)
Three, TSC and ESC command editor
Jia Bo printer compatible with both industry standard command, 5890XIII, 58130IVC and other receipt printer compatible ESC / POS instruction set;
2120T, 2120TL series TSC label printer compatible instruction set;
2120TF is compatible ESC and TSC, need to toggle the mode switching dipswitches
1, TSC command invokes the template below, Gprinter SDK in JavaDoc file has TSCCommand API call description of
TscCommand tsc = new TscCommand (60,30,0) ; // set the size of the label width, height, gap tsc.addReference (0, 0); // set the origin coordinates tsc.addSpeed (SPEED.SPEED1DIV5); // Set Print speed tsc.addDensity (DENSITY.DNESITY0); // set the print density tsc.addDirection (DIRECTION.BACKWARD); // set the print orientation tsc.addCls (); // print buffer is cleared tsc.addSound (2, 100); tsc.addText (20,20, FONTTYPE.FONT_TAIWAN, ROTATION.ROTATON_0, FONTMUL.MUL_1, FONTMUL.MUL_1, "Hello Gprinter"); // draw text tsc.add1DBarcode (20, 50, BARCODETYPE.CODE128, 100, READABEL. EANBEL, ROTATION.ROTATION_180, "12345") ; // draw the one-dimensional bar tsc.addPrint (1,1); // Add command to print labels the Vector <Byte> the Vector the command new new = <Byte> (4096, 1024); the command = tsc.getCommand (); // Get a print command to edit the above mDevice.sendDataImmediately (command); // send a command
2, ESC command invokes the template below, Gprinter SDK in JavaDoc file has ESCCommand API call description of
ESC = new new EscCommand EscCommand ();
esc.addTurnEmphasizedModeOnOrOff (EscCommand.ENABLE.ON); // bold mode is active esc.addText ( "Hello World \ n" ); // print text esc.addUPCA ( "123456789012"); // print UPCA barcode esc.addCODE128 ( "Gprinter"); // print barcodes CODE128 the Vector <Byte> the Vector the command new new = <Byte> (4096, 1024); the command esc.getCommand = (); // get editing commands data mDevice.sendDataImmediately (command); // send a command
Call Gprinter.jar files, simply follow the steps above, you can edit the label you want freedom after the establishment of good Android project in Eclipse
Download GprinterSDK
GprinterSDK can download Jia Bo printer click on the official website GprinterSDK , or contact customer service, you can download.
First, the project will be imported into gprinter.jar
In eclipse, the gprinter.jar libs file copied to the project folder.
Second, establish communication with the printer
1, target acquisition device
GpDevice mDevice = new GpDevice();
2, the callback function registered to receive data (this interface is used to receive data)
mDevice.registerCallback(this);
3, turn on Bluetooth, USB, Ethernet port
Bluetooth communication :
a, you need to obtain permission Bluetooth operation, in AndroidManifest.xml, add the following code
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH" />
b, open API calls Bluetooth
1
|
mDevice.openBluetoothPort(Context context,String addr);
|
context to context, addr Bluetooth address. Such as Bluetooth address "98: D3: 31: 40: 27: D7", the call
mDevice.openBluetoothPort(MainActivity.this,"98:D3:31:40:27:D7");
USB communication
a, USB need to obtain operating authority, in AndroidManifest.xml, add the following code
<uses-feature android:name="android.hardware.usb.host" />
B, register USB device insertion and removal broadcasting, in AndroidManifest.xml, add the following code
<intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> </intent-filter> <intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" /> </intent-filter> <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" /> <meta-data android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" android:resource="@xml/device_filter" />
C, device_filter.xml USB devices filter file, which is stored in the USB device VID and PID number, only the matching device USB plug, USB is inserted or removed in order to produce broadcast, device_filter.xml need to be placed at res / xml folder, file format, e.g. Gp2120TL label printer VID 1280 is the 26728 PID
<?xml version="1.0" encoding="utf-8"?><resources> <usb-device vendor-id="26728" product-id="1280" /> </resources>
d, older versions of the Android SDK USBhost is not supported, the minimum SDK version 12, required to join the
android:minSdkVersion="12"
e, calls the USB port open API
mDevice.openBluetoothPort(MainActivity.this);
网口 communication
a, needs to obtain network operating authority, in AndroidManifest.xml, add the following code
<uses-permission android:name="android.permission.INTERNET" />
b, Ethernet port API calls
IP network such as the initial Jia Bo printer for printing 192.168.123.100 port 9100
1
|
mDevice.openEthernetPort(“
192.168
.
123.100
”,
9100
)
|
4, turn off Bluetooth, USB, Ethernet port
API call to close ports
mDevice.closePort();
5, the transmission data
API data is sent immediately
Transmitting data in the transmission buffer
mDevice.sendData(Vector<Byte> data)
Three, TSC and ESC command editor
Jia Bo printer compatible with both industry standard command, 5890XIII, 58130IVC and other receipt printer compatible ESC / POS instruction set;
2120T, 2120TL series TSC label printer compatible instruction set;
2120TF is compatible ESC and TSC, need to toggle the mode switching dipswitches
1, TSC command invokes the template below, Gprinter SDK in JavaDoc file has TSCCommand API call description of
TscCommand tsc = new TscCommand (60,30,0) ; // set the size of the label width, height, gap tsc.addReference (0, 0); // set the origin coordinates tsc.addSpeed (SPEED.SPEED1DIV5); // Set Print speed tsc.addDensity (DENSITY.DNESITY0); // set the print density tsc.addDirection (DIRECTION.BACKWARD); // set the print orientation tsc.addCls (); // print buffer is cleared tsc.addSound (2, 100); tsc.addText (20,20, FONTTYPE.FONT_TAIWAN, ROTATION.ROTATON_0, FONTMUL.MUL_1, FONTMUL.MUL_1, "Hello Gprinter"); // draw text tsc.add1DBarcode (20, 50, BARCODETYPE.CODE128, 100, READABEL. EANBEL, ROTATION.ROTATION_180, "12345") ; // draw the one-dimensional bar tsc.addPrint (1,1); // Add command to print labels the Vector <Byte> the Vector the command new new = <Byte> (4096, 1024); the command = tsc.getCommand (); // Get a print command to edit the above mDevice.sendDataImmediately (command); // send a command
2, ESC command invokes the template below, Gprinter SDK in JavaDoc file has ESCCommand API call description of
ESC = new new EscCommand EscCommand ();
esc.addTurnEmphasizedModeOnOrOff (EscCommand.ENABLE.ON); // bold mode is active esc.addText ( "Hello World \ n" ); // print text esc.addUPCA ( "123456789012"); // print UPCA barcode esc.addCODE128 ( "Gprinter"); // print barcodes CODE128 the Vector <Byte> the Vector the command new new = <Byte> (4096, 1024); the command esc.getCommand = (); // get editing commands data mDevice.sendDataImmediately (command); // send a command
Call Gprinter.jar files, simply follow the steps above, you can edit the label you want freedom after the establishment of good Android project in Eclipse