日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 佳博打印机,佳博蓝牙打印的java 连接

發布時間:2024/7/19 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 佳博打印机,佳博蓝牙打印的java 连接 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

適用于gp-3120tu機型通過藍牙協議與android app的對接,?用的是TSC指令.

package com.freestyle.demo;

import android.content.Intent;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.os.Handler;

import android.os.HandlerThread;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.TextView;

import android.widget.Toast;

import com.freestyle.R;

import com.freestyle.common.btprinter.SharedPreferencesUtil;

import com.gprinter.command.EscCommand;

import com.gprinter.command.LabelCommand;

import com.freestyle.common.btprinter.BTPrinterUtil;

import com.freestyle.common.btprinter.DeviceConnFactoryManager;

import com.freestyle.common.btprinter.PrinterCommand;

import com.freestyle.common.btprinter.ThreadPool;

import org.androidannotations.annotations.AfterViews;

import org.androidannotations.annotations.Click;

import org.androidannotations.annotations.EActivity;

import org.androidannotations.annotations.ViewById;

import java.util.Vector;

@EActivity(R.layout.activity_main)

public class MainActivity extends AppCompatActivity implements BTPrinterUtil.BTPrinterInterface {

BTPrinterUtil mUtil;

@ViewById

protected View disconnectBtn;

@ViewById

protected TextView info;

private SharedPreferencesUtil mSetting;

//private ThreadPool threadPool;

private String mLastDeviceMac = null;

HandlerThread mBgThread=null;

Handler mPrintHandler=null;

final static String mTitle="佳博藍牙打印機SDK演示";

@Click

protected void connectBtn() {

mUtil.selectDevice();

}

@Click

protected void disconnectBtn() {

mUtil.disconnect();

}

private Runnable mPrintTestRunnable = new Runnable() {

@Override

public void run() {

if (mUtil.deviceIsSupportTSC(0)) {

sendLabel1();

} else {

Toast.makeText(MainActivity.this, "printer command failed.", (int) 2000).show();

}

}

};

@Click

protected void testBtn() {

/*if (!mUtil.checkConnect(0)) {

Toast.makeText(this, "Connect a printer first.", (int) 2000).show();

return;

}*/

mPrintHandler.post(new Runnable() {

@Override

public void run() {

if (DeviceConnFactoryManager.getDeviceConnFactoryManagers()[0] == null ||

!DeviceConnFactoryManager.getDeviceConnFactoryManagers()[0].getConnState()) {

if (mLastDeviceMac == null) {

Toast.makeText(MainActivity.this, "Connect a printer first.", (int) 2000).show();

return;

} else { //當藍牙斷開時,重新連接后再打印

mUtil.connectDevice(mLastDeviceMac);

new Thread(new Runnable() {

@Override

public void run() {

for (int i=1;i<=15000;i++) {

try {

Thread.sleep(100);

} catch (InterruptedException e) {

e.printStackTrace();

}

if (!mUtil.waitFlag.get()) break;

}

runOnUiThread(new Runnable() {

@Override

public void run() {

if (!mUtil.checkConnect(0)) {

Toast.makeText(MainActivity.this, "Connect printer failed.", (int) 2000).show();

} else {

mPrintTestRunnable.run();

}

}

});

}

}).start();

}

}

mPrintTestRunnable.run();

}

});

}

/**

* 發送標簽

*/

void sendLabel1() {

LabelCommand tsc = new LabelCommand();

// 設置標簽尺寸,按照實際尺寸設置

tsc.addSize(65, 35);

// 設置標簽間隙,按照實際尺寸設置,如果為無間隙紙則設置為0

tsc.addGap(2);

// 設置打印方向

tsc.addDirection(LabelCommand.DIRECTION.BACKWARD, LabelCommand.MIRROR.NORMAL);

// 開啟帶Response的打印,用于連續打印

tsc.addQueryPrinterStatus(LabelCommand.RESPONSE_MODE.ON);

// 設置原點坐標

tsc.addReference(0, 10);

// 撕紙模式開啟

tsc.addTear(EscCommand.ENABLE.ON);

// 清除打印緩沖區

tsc.addCls();

tsc.addText(20, 20, LabelCommand.FONTTYPE.SIMPLIFIED_CHINESE,

LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,

"PICK0NUM0AA");

tsc.addText(20, 70, LabelCommand.FONTTYPE.SIMPLIFIED_CHINESE,

LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,

"JB0123456");

tsc.addText(20, 120, LabelCommand.FONTTYPE.SIMPLIFIED_CHINESE,

LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,

"(15)");

/*for (int i=1;i<=4;i++) {

tsc.addText(20, 20+(i-1)*40, LabelCommand.FONTTYPE.valueOf("FONT_"+String.valueOf(i)),

LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,

"PICK0NUM0");

}*/

tsc.addQRCode(300, 20, LabelCommand.EEC.LEVEL_L, 7,

LabelCommand.ROTATION.ROTATION_0, "PICK0NUM0,12351253,123542");

// 繪制一維條碼

//tsc.add1DBarcode(20, 250, LabelCommand.BARCODETYPE.CODE128, 100, LabelCommand.READABEL.EANBEL, LabelCommand.ROTATION.ROTATION_0, "SMARNET");

// 打印標簽

tsc.addPrint(1, 1);

// 打印標簽后 蜂鳴器響

tsc.addSound(2, 100);

tsc.addCashdrwer(LabelCommand.FOOT.F5, 255, 255);

Vectordatas = tsc.getCommand();

// 發送數據

mUtil.printContent(0, datas);

}

/**

* 發送標簽

*/

void sendLabel() {

LabelCommand tsc = new LabelCommand();

// 設置標簽尺寸,按照實際尺寸設置

tsc.addSize(65, 35);

// 設置標簽間隙,按照實際尺寸設置,如果為無間隙紙則設置為0

tsc.addGap(2);

// 設置打印方向

tsc.addDirection(LabelCommand.DIRECTION.BACKWARD, LabelCommand.MIRROR.NORMAL);

// 開啟帶Response的打印,用于連續打印

tsc.addQueryPrinterStatus(LabelCommand.RESPONSE_MODE.ON);

// 設置原點坐標

tsc.addReference(0, 10);

// 撕紙模式開啟

tsc.addTear(EscCommand.ENABLE.ON);

// 清除打印緩沖區

tsc.addCls();

// 繪制簡體中文

tsc.addText(20, 20, LabelCommand.FONTTYPE.SIMPLIFIED_CHINESE,

LabelCommand.ROTATION.ROTATION_0, LabelCommand.FONTMUL.MUL_1, LabelCommand.FONTMUL.MUL_1,

"Welcome to use 佳博打印機!");

// 繪制圖片

Bitmap b = BitmapFactory.decodeResource(getResources(), R.mipmap.gprinter);

tsc.addBitmap(20, 50, LabelCommand.BITMAP_MODE.OVERWRITE, b.getWidth(), b);

tsc.addQRCode(250, 50, LabelCommand.EEC.LEVEL_L, 5,

LabelCommand.ROTATION.ROTATION_0, " www.smarnet.cc");

// 繪制一維條碼

//tsc.add1DBarcode(20, 250, LabelCommand.BARCODETYPE.CODE128, 100, LabelCommand.READABEL.EANBEL, LabelCommand.ROTATION.ROTATION_0, "SMARNET");

// 打印標簽

tsc.addPrint(1, 1);

// 打印標簽后 蜂鳴器響

tsc.addSound(2, 100);

tsc.addCashdrwer(LabelCommand.FOOT.F5, 255, 255);

Vectordatas = tsc.getCommand();

// 發送數據

mUtil.printContent(0, datas);

}

@AfterViews

public void initWidgets() {

mUtil.checkPermission();

mUtil.requestPermission();

disconnectBtn.setEnabled(false);

setTitle(mLastDeviceMac!=null?mTitle+" - "+mLastDeviceMac:mTitle);

if (mLastDeviceMac!=null){

mUtil.connectDevice(mLastDeviceMac);

}

}

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

mUtil = new BTPrinterUtil(this, this);

mSetting=SharedPreferencesUtil.getInstantiation(this);

mLastDeviceMac=mSetting.getString(null,"device");

DeviceConnFactoryManager.context = this;

mBgThread=new HandlerThread("PrintThread");

mBgThread.start();

mPrintHandler=new Handler(mBgThread.getLooper());

}

@Override

protected void onDestroy(){

mBgThread.quit();

super.onDestroy();

}

@Override

public void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

mUtil.onActivityResult(requestCode, resultCode, data);

}

@Override

public void onACLDisconnected() {

mUtil.disconnect();

}

@Override

public void onDisconnected() {

Toast.makeText(this, "disconnected", (int) 1000);

disconnectBtn.setEnabled(false);

info.setText("Diconnected");

}

@Override

public void onConnecting() {

}

@Override

public void onConnected() {

disconnectBtn.setEnabled(true);

info.setText("connected:\n" + mUtil.getConnDeviceInfo());

mLastDeviceMac = mUtil.getLastPrinterMac();

mSetting.putString(mLastDeviceMac,"device");

setTitle(mTitle+" - "+mLastDeviceMac);

}

@Override

public void onConnectFailed() {

}

}

總結

以上是生活随笔為你收集整理的java 佳博打印机,佳博蓝牙打印的java 连接的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 天天操 夜夜操 | 午夜av免费在线观看 | 日韩手机视频 | 九九热最新视频 | 99久久人妻精品免费二区 | 公与妇乱理三级xxx www色 | 亚洲黄色中文字幕 | 美女污软件 | 国产草草影院ccyycom | 国产99色 | 国产精品果冻传媒潘 | 欧美不卡在线观看 | 久久精品无码专区 | 中出亚洲 | 日韩精品――色哟哟 | 色吊妞 | 强辱丰满人妻hd中文字幕 | 男人和女人日b视频 | 亚洲欧美精品午睡沙发 | 国产一级片播放 | 欧美日韩精品在线播放 | 三上悠亚在线观看一区二区 | 四级毛片 | 久久综合第一页 | 一本大道久久精品 | 大学生av | 日本中文字幕在线不卡 | 久久综合高清 | 按摩害羞主妇中文字幕 | 免费在线看黄网站 | 日本特黄一级 | 国产一区二区三区四区五区 | 性自由色xxxx免费视频 | 一区二区成人网 | 日韩不卡一二三 | 嫩草一区二区 | 欧美在线视频网 | 人妻无码一区二区三区久久 | 成人在线精品视频 | 人人干人人爱 | 国产情侣小视频 | 国产在线观看av | 国产精品免费视频一区二区三区 | 极品国产一区 | 日本成人片网站 | 久热免费在线 | 91蜜桃视频 | 成人毛片大全 | 国产综合精品视频 | 91在线观 | 麻豆射区 | 91丝袜在线| 最新福利在线 | 六月婷婷综合 | 黄色片成人 | 人妻内射一区二区在线视频 | 欧美精品在欧美一区二区少妇 | 大黑人交交护士xxxxhd | 久久亚洲精品无码va白人极品 | 精品国产无码一区二区三区 | a天堂在线资源 | 日屁网站| 丰满多毛的大隂户视频 | 熟女高潮一区二区三区视频 | 国产精品主播 | 黄色片在线免费 | 狠狠干夜夜干 | 日韩色图片 | 亚洲字幕| 国产一区二区三区四区三区四 | av有声小说一区二区三区 | 亚洲插插 | 欧美精品综合 | 亚洲综合在线网 | 日韩精品免费电影 | 国产精品波多野结衣 | 欧美色偷偷 | 婷婷色小说 | 精品国产一区二区三区日日嗨 | 日本一区二区视频 | 午夜剧场在线 | 波多野结衣精品视频 | 国产日韩在线一区 | 999这里有精品 | 成人免费影视网站 | 91精品黄色 | 国内精品一区二区三区 | 久久久久人妻一区二区三区 | 久久九九国产视频 | 好吊色视频一区二区 | 大桥未久av一区二区三区中文 | 久久99国产精品久久99果冻传媒 | a免费在线观看 | 狠狠操一区二区 | 97在线看 | 香港台湾日本三级大全 | 色婷婷av一区二区三区麻豆综合 | 二级毛片在线观看 | 男人资源网站 |