Commit 340eef2d authored by pengguangpu's avatar pengguangpu

修改英泰机器是否在线状态检测方法;

英泰机器添加beginPrint方法内触发式检测是否已连接
parent 71a7607d
...@@ -5,7 +5,42 @@ ...@@ -5,7 +5,42 @@
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> <configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations> </configurations>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
android:id="@+id/btnPrintText" android:id="@+id/btnPrintText"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="打印默认字符" /> android:text="打印输入字符" />
</TableRow> </TableRow>
<TableRow android:visibility="gone"> <TableRow android:visibility="gone">
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.miya.print" /> package="com.miya.print">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>
...@@ -30,7 +30,7 @@ public class YingtaiPrinter extends BasePrinter { ...@@ -30,7 +30,7 @@ public class YingtaiPrinter extends BasePrinter {
this.context = context; this.context = context;
mPrinter = PrinterAPI.getInstance(); mPrinter = PrinterAPI.getInstance();
io = new USBAPI(context); io = new USBAPI(context);
if (!io.isOpen().booleanValue()) { if (!mPrinter.isConnect()) {
if (PrinterAPI.SUCCESS == mPrinter.connect(io)) { if (PrinterAPI.SUCCESS == mPrinter.connect(io)) {
PrintLogger.i(TAG, "英泰打印机连接成功"); PrintLogger.i(TAG, "英泰打印机连接成功");
return true; return true;
...@@ -54,11 +54,29 @@ public class YingtaiPrinter extends BasePrinter { ...@@ -54,11 +54,29 @@ public class YingtaiPrinter extends BasePrinter {
return true; return true;
} }
@Override
public int beginPrint() {
if (mPrinter != null && !mPrinter.isConnect()) {
if (PrinterAPI.SUCCESS == mPrinter.connect(io)) {
PrintLogger.i(TAG, "之前的连接断掉了,重新连接后,英泰打印机连接成功");
return PrinterStatusEnum.CODE_SUCCESS.status;
} else {
PrintLogger.e(TAG, "之前的连接断掉了,重新连接后,英泰打印机连接失败");
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.status, "重连尝试,英泰打印机连接失败,请重试");
}
}
return PrinterStatusEnum.CODE_SUCCESS.status;
}
@Override @Override
public int printText(int align, int size, String content, boolean isFeed) { public int printText(int align, int size, String content, boolean isFeed) {
if (mPrinter != null) { if (mPrinter != null) {
int ret = setAlign(align); int ret = setAlign(align);
try { try {
//设置字体大小,可传0~7
if (size >= 0 && size <= 7) {
ret = mPrinter.setCharSize(size, size);
}
ret = mPrinter.printString(content, "GBK", isFeed); ret = mPrinter.printString(content, "GBK", isFeed);
return ret; return ret;
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
......
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