Commit 641ec581 authored by pengguangpu's avatar pengguangpu

英泰打印驱动尘埃落定

parent ed9f6ba9
......@@ -137,7 +137,7 @@ public class PrintActivity extends Activity implements View.OnClickListener {
break;
case R.id.btnRelease:
if (PrinterManager.getInstance().isConnected()) {
if (PrinterManager.getInstance().getPrinter().release() == true) {
if (PrinterManager.getInstance().release() == true) {
tvResult.setText("销毁成功");
} else {
tvResult.setText("没初始化过");
......
......@@ -8,6 +8,11 @@ import android.graphics.Bitmap;
*/
public class BasePrinter implements IPrinter {
/**
* 80mm打印纸允许打印的最大图片的宽度,此为经验值
*/
final static int MAX_IMG_WIDTH_80MM = 570;
/**
* 初始化调用者的引用
*/
......
......@@ -41,11 +41,6 @@ public class ChuangjiePrinter extends BasePrinter {
*/
int textSize = -1;
/**
* 80mm打印纸允许打印的最大图片的宽度,此为经验值
*/
final static int MAX_IMG_WIDTH_80MM = 570;
@Override
public boolean init(Context context) {
this.context = context;
......@@ -71,9 +66,7 @@ public class ChuangjiePrinter extends BasePrinter {
}
ret = setAlign(align);
ret = printString(content);
if (isFeed) {
ret = LF();
}
//创捷机器打印完后会强制走纸一行,这里不再判断是否走纸标志
return ret;
}
......@@ -89,12 +82,17 @@ public class ChuangjiePrinter extends BasePrinter {
@Override
public boolean release() {
super.release();
if (null == mUsbDev) {
if (mUsbDriver != null && mUsbDev != null) {
if (mUsbDriver.isConnected()) {
mUsbDriver.disconnet();
if (null != mUsbDev) {
mUsbDriver.disconnet(mUsbDev);
}
}
mUsbDev = null;
mUsbDriver = null;
context = null;
}
D.i(TAG, "创捷打印资源已关闭");
return true;
}
......@@ -319,9 +317,6 @@ public class ChuangjiePrinter extends BasePrinter {
int ret = setAlign(align);
//创捷机器打印条码只能居左、居中打印,并且内部会强制走纸
ret = printBarCode(content);
if (isFeed) {
ret = feedPaper();
}
return ret;
}
......
......@@ -17,10 +17,11 @@ public class PrinterManager {
enum Type {
//这里添加扩展的驱动
// TYPE_HISENSE("hisense", ChuangjiePrinter.class.getName()),
// TYPE_YINGTAI("yingtai", ChuangjiePrinter.class.getName()),
// TYPE_SUNMI("shangmi", ChuangjiePrinter.class.getName()),
TYPE_SANGDA("sangda", SangdaPrinter.class.getName()),
TYPE_CHUANGJIE("chuangjie", ChuangjiePrinter.class.getName());
// TYPE_SUNMI("shangmi", ChuangjiePrinter.class.getName()),
TYPE_YINGTAI("yingtai", YingtaiPrinter.class.getName()),
TYPE_CHUANGJIE("chuangjie", ChuangjiePrinter.class.getName()),
TYPE_SANGDA("sangda", SangdaPrinter.class.getName());
/**
* 设备类型名称
......@@ -96,6 +97,23 @@ public class PrinterManager {
return false;
}
/**
* 销毁相关资源
*
* @return
*/
public boolean release() {
if (isConnected()) {
boolean result = printer.release();
if (result == false) {
return false;
}
printer = null;
return true;
}
return true;
}
/**
* 获取当前打印接口
*
......
......@@ -25,17 +25,13 @@ public class SangdaPrinter extends BasePrinter {
final static String TAG = SangdaPrinter.class.getSimpleName();
public PrinterAPI mPrinter = PrinterAPI.getInstance();
public PrinterAPI mPrinter;
InterfaceAPI io = null;
/**
* 80mm打印纸允许打印的最大图片的宽度,此为经验值
*/
final static int MAX_IMG_WIDTH_80MM = 570;
@Override
public boolean init(Context context) {
super.init(context);
mPrinter = PrinterAPI.getInstance();
if (isConnect()) {
mPrinter.disconnect();
}
......
This diff is collapsed.
package com.miya.weighing;
import android.content.Context;
import android.os.Build;
import android.os.CountDownTimer;
import android.util.Log;
......@@ -30,6 +31,10 @@ public class ChuangjieWeighing extends BaseWeighing {
@Override
public boolean init(Context context) {
//根据序列号判断是否是创捷机器
if (!Build.SERIAL.startsWith("CCL")) {
return false;
}
serialPortFunction = SerialPortFunction.getInstance();
serialPortFunction.setContext(context);
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment