Gprinter Android SDK V1.0 usage Instructions

Source: Internet
Author: User

The gprinter Android SDK is designed to make it faster and more efficient for bloggers to develop and use a good Bo printer under the Android platform. If you encounter problems in using the SDK, or find a bug, please feel free to contact me, send the email to [email protected] First, download GPRINTERSDK

GPRINTERSDK can download Http://www.gainscha.cn/cn/download.aspx?current=down or click Gprintersdk on the website of Jia Bo printer.

first, the Gprinter.jar into the project

In Eclipse, copy the Gprinter.jar to the project's Libs folder.

second, establish communication with the printer 1. Get the object of the device
Gpdevice mdevice = new Gpdevice ();
2, register to receive data callback function (this interface is used to receive data)
Mdevice.registercallback (this);
3. Turn on Bluetooth, USB, network Port bluetooth communication :

A, need to get Bluetooth operation Rights, in Androidmanifest.xml, add the following code

<uses-permission android:name= "Android.permission.BLUETOOTH_ADMIN"/><uses-permission android:name= " Android.permission.BLUETOOTH "/>  

B. Call the Bluetooth Open API

Mdevice.openbluetoothport (Context context,string addr)

Context, addr is the Bluetooth address. For example, if the Bluetooth address is "98:D3:31:40:27:D7", call

Mdevice.openbluetoothport (mainactivity.  this,"98:d3:31:40:27:d7");
USB Communication

A, need to obtain the USB operation permission, in Androidmanifest.xml, add the following code

<uses-feature android:name= "Android.hardware.usb.host"/>

b, register the USB device to insert and unplug the broadcast, 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"  Androi D:resource  = "@xml/device_filter"/> <meta-data android:name  = " Android.hardware.usb.action.USB_DEVICE_DETACHED " Android:resource  ="  @xml/device_filter  "/>  

C,device_filter.xml for USB device filter file, which stores the USB device PID and vid number, only the matching device USB plug in order to produce USB plug-in or pull out the broadcast, Device_filter.xml need to put in res/ Under the XML folder, the file format is as follows, for example GP2120TL label printer vid for 26728 pid

<?xml version= "1.0" encoding= "Utf-8"?><resources> <usb-device       vendor-id= "26728" Product-id= "/></resources>"

D, the old version of the Android SDK is not supported Usbhost, the minimum SDK version is 12, so you need to join

Android:minsdkversion= "12"

E. Call the USB port to open the API

Mdevice.openbluetoothport (mainactivity.  this);
Network Port Communication

A, need to obtain network operation permission, in Androidmanifest.xml, add the following code

<uses-permission android:name= "Android.permission.INTERNET"/>

b, call the network Port API

For example, the initial IP for the 192.168.123.100 network printer is 9100 for the print port

Mdevice.openethernetport ("192.168.123.100", 9100)
4. Turn off Bluetooth, USB, network Port

Call the Close Port API

Mdevice.closeport ();
5. Send Data

Send Data API now

mdevice.senddataimmediately (vector<byte> data)

Placing the sending data in the Send buffer

Mdevice.senddata (vector<byte> data)
iii. TSC and ESC command editor

Jia Bo printer compatible with two industry command standards, 5890XIII, 58130IVC and other ticket printer compatible with esc/pos instruction set;

2120T, 2120TL series label printer compatible with TSC instruction set;

2120TF is also compatible with ESC and TSC, mode switch requires toggle dial switch

1, TSC command call template as follows, Gprinter SDK in the Javadoc file has the Tsccommand API call Description
Tsccommand TSC =NewTsccommand (60,30,0);//set Label size width, height, clearanceTsc.addreference (0, 0);//Set Origin coordinatesTsc.addspeed (speed. SPEED1DIV5);//Set the print speedTsc.adddensity (DENSITY. DNESITY0);//Set Print densityTsc.adddirection (DIRECTION. backward);//Set Print DirectionTsc.addcls ();//clear the Print bufferTsc.addsound (2, 100); Tsc.addtext (20,20,fonttype. Font_taiwan,rotation. Rotaton_0,fontmul. Mul_1,fontmul. Mul_1, "Hello gprinter");//Draw TextTsc.add1dbarcode (a), Barcodetype. CODE128, Readabel. Eanbel, ROTATION. rotation_180, "12345");//draw a one-dimensional barcodeTsc.addprint (a);//Add print label commandVector<byte> Command =NewVector<byte> (4096, 1024); Command= Tsc.getcommand ();//Get the Print command edited aboveMdevice.senddataimmediately (Command);//Send command
2. The ESC command invokes the template as follows, and the Javadoc file in the Gprinter SDK has a Esccommand API call description
 esccommand ESC = new Esccommand ();  
esc.addturnemphasizedmodeonoroff (EscCommand.ENABLE.ON); // bold mode valid esc.addtext ("Hello world\n"); // print text ESC.ADDUPCA ("123456789012"); // print UPCA barcode esc.addcode128 ("Gprinter"); // print CODE128 bar code vector<byte> Command = new vector<byte> (4096, 1024); Command = Esc.getcommand (); // get the edited command data mdevice.senddataimmediately. // send command

Call the Gprinter.jar file after setting up an Android project under Eclipse, just follow the steps above, and you'll be free to edit the tags you want.

Gprinter Android SDK V1.0 usage Instructions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.