Commit 641ec581 authored by pengguangpu's avatar pengguangpu

英泰打印驱动尘埃落定

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