Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
miya-hardware
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pengguangpu
miya-hardware
Commits
3506d520
Commit
3506d520
authored
Dec 25, 2018
by
pengguangpu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加打印sdk相关代码;编写标准打印接口以及状态码
parent
24f2fafb
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
273 additions
and
1 deletion
+273
-1
build_file_checksums.ser
.idea/caches/build_file_checksums.ser
+0
-0
build.gradle
print/build.gradle
+6
-0
CJusbjar.jar
print/libs/CJusbjar.jar
+0
-0
PrintCmd.jar
print/libs/PrintCmd.jar
+0
-0
BasePrinter.java
print/src/main/java/com/miya/print/BasePrinter.java
+34
-0
ChuangjiePrinter.java
print/src/main/java/com/miya/print/ChuangjiePrinter.java
+156
-0
IPrinter.java
print/src/main/java/com/miya/print/IPrinter.java
+77
-1
No files found.
.idea/caches/build_file_checksums.ser
View file @
3506d520
No preview for this file type
print/build.gradle
View file @
3506d520
...
@@ -31,4 +31,10 @@ dependencies {
...
@@ -31,4 +31,10 @@ dependencies {
testImplementation
'junit:junit:4.12'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
/**
* 创捷机器打印jar包
*/
implementation
files
(
'libs/CJusbjar.jar'
)
implementation
files
(
'libs/PrintCmd.jar'
)
}
}
print/libs/CJusbjar.jar
0 → 100644
View file @
3506d520
File added
print/libs/PrintCmd.jar
0 → 100644
View file @
3506d520
File added
print/src/main/java/com/miya/print/BasePrinter.java
0 → 100644
View file @
3506d520
package
com
.
miya
.
print
;
import
android.content.Context
;
/**
* 打印基类
*/
public
class
BasePrinter
implements
IPrinter
{
/**
* 初始化调用者的引用
*/
Context
context
;
/**
* 当前状态码,具体值参考全局状态码
*/
int
status
;
@Override
public
boolean
init
(
Context
context
)
{
return
false
;
}
@Override
public
boolean
release
()
{
return
false
;
}
@Override
public
int
beginPrint
()
{
return
0
;
}
}
print/src/main/java/com/miya/print/ChuangjiePrinter.java
0 → 100644
View file @
3506d520
package
com
.
miya
.
print
;
import
android.hardware.usb.UsbDevice
;
import
android.hardware.usb.UsbManager
;
import
com.miya.print.utils.D
;
import
com.printsdk.cmd.PrintCmd
;
import
com.printsdk.usbsdk.UsbDriver
;
/**
* 创捷打印驱动
*/
public
class
ChuangjiePrinter
extends
BasePrinter
{
private
final
static
String
TAG
=
ChuangjiePrinter
.
class
.
getSimpleName
();
private
final
static
int
PID11
=
8211
;
private
final
static
int
PID13
=
8213
;
private
final
static
int
PID15
=
8215
;
private
final
static
int
VENDORID
=
1305
;
private
UsbDriver
mUsbDriver
;
private
UsbManager
mUsbManager
;
public
UsbDevice
mUsbDev1
;
// 内置打印机
public
UsbDevice
mUsbDev2
;
// usb标签打印机
public
UsbDevice
mUsbDev
;
// 公共打印机
private
static
final
String
ACTION_USB_PERMISSION
=
"com.usb.sample.USB_PERMISSION"
;
/**
* 0 打印机正常
* 1 打印机未连接或未上电
* 2 打印机和调用库不匹配
* 3 打印头打开
* 4 切刀未复位
* 5 打印头过热
* 6 黑标错误
* 7 纸尽
* 8 纸将尽
*
* @return
*/
public
synchronized
int
connet
()
{
int
conState
=
-
1
;
//有时候会出现mUsbDev为空,但是mUsbDriver还在连接的情况
if
(
null
==
mUsbDev
)
{
if
(
mUsbDriver
.
isConnected
())
{
mUsbDriver
.
disconnet
();
}
}
getUsbDriverService
();
//获取连接状态
if
(
null
!=
mUsbDev
)
{
conState
=
getPrinterStatus
(
mUsbDev
);
}
return
conState
;
}
/**
* 0 打印机正常
* 1 打印机未连接或未上电
* 2 打印机和调用库不匹配
* 3 打印头打开
* 4 切刀未复位
* 5 打印头过热
* 6 黑标错误
* 7 纸尽
* 8 纸将尽
*
* @param usbDev
* @return
*/
private
int
getPrinterStatus
(
UsbDevice
usbDev
)
{
int
iRet
=
-
1
;
byte
[]
bRead1
=
new
byte
[
1
];
byte
[]
bWrite1
=
PrintCmd
.
getStatus1
();
if
(
mUsbDriver
.
read
(
bRead1
,
bWrite1
,
usbDev
)
>
0
)
{
iRet
=
PrintCmd
.
checkStatus1
(
bRead1
[
0
]);
}
if
(
iRet
!=
0
)
return
iRet
;
byte
[]
bRead2
=
new
byte
[
1
];
byte
[]
bWrite2
=
PrintCmd
.
getStatus2
();
if
(
mUsbDriver
.
read
(
bRead2
,
bWrite2
,
usbDev
)
>
0
)
{
iRet
=
PrintCmd
.
checkStatus2
(
bRead2
[
0
]);
}
if
(
iRet
!=
0
)
return
iRet
;
byte
[]
bRead3
=
new
byte
[
1
];
byte
[]
bWrite3
=
PrintCmd
.
getStatus3
();
if
(
mUsbDriver
.
read
(
bRead3
,
bWrite3
,
usbDev
)
>
0
)
{
iRet
=
PrintCmd
.
checkStatus3
(
bRead3
[
0
]);
}
if
(
iRet
!=
0
)
return
iRet
;
byte
[]
bRead4
=
new
byte
[
1
];
byte
[]
bWrite4
=
PrintCmd
.
getStatus4
();
if
(
mUsbDriver
.
read
(
bRead4
,
bWrite4
,
usbDev
)
>
0
)
{
iRet
=
PrintCmd
.
checkStatus4
(
bRead4
[
0
]);
}
return
iRet
;
}
/**
* 获取UsbDriverService服务
*
* @return
*/
private
boolean
getUsbDriverService
()
{
boolean
blnRtn
=
false
;
try
{
if
(!
mUsbDriver
.
isConnected
())
{
// USB线已经连接
for
(
UsbDevice
device
:
mUsbManager
.
getDeviceList
().
values
())
{
if
((
device
.
getProductId
()
==
PID11
&&
device
.
getVendorId
()
==
VENDORID
)
||
(
device
.
getProductId
()
==
PID13
&&
device
.
getVendorId
()
==
VENDORID
)
||
(
device
.
getProductId
()
==
PID15
&&
device
.
getVendorId
()
==
VENDORID
))
{
blnRtn
=
mUsbDriver
.
usbAttached
(
device
);
if
(
blnRtn
==
false
)
{
break
;
}
blnRtn
=
mUsbDriver
.
connect
(
device
);
// 打开设备
if
(
blnRtn
)
{
//内置打印机
if
(
device
.
getProductId
()
==
PID11
)
{
mUsbDev1
=
device
;
mUsbDev
=
mUsbDev1
;
}
else
{
//USB打印机
mUsbDev2
=
device
;
mUsbDev
=
mUsbDev2
;
D
.
i
(
TAG
,
"USB连接成功"
);
break
;
}
}
else
{
D
.
e
(
TAG
,
"USB连接失败"
);
break
;
}
}
}
}
else
{
blnRtn
=
true
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
blnRtn
;
}
}
print/src/main/java/com/miya/print/IPrinter.java
View file @
3506d520
package
com
.
miya
.
print
;
package
com
.
miya
.
print
;
import
android.content.Context
;
/**
/**
* 标准打印接口
* 标准打印接口
*
*
...
@@ -8,4 +10,78 @@ package com.miya.print;
...
@@ -8,4 +10,78 @@ package com.miya.print;
*/
*/
public
interface
IPrinter
{
public
interface
IPrinter
{
}
//================全局状态码定义start===============//
/**
* 操作成功
*/
int
CODE_SUCCESS
=
0
;
/**
* 操作失败
*/
int
CODE_FAILED
=
-
1
;
/**
* 打印机未连接或未上电
*/
int
CODE_NOT_CONNECTED
=
1
;
/**
* 打印机和调用库不匹配
*/
int
CODE_NOT_MATCHED
=
2
;
/**
* 打印头打开
*/
int
CODE_PRINT_HEAD_OPENED
=
3
;
/**
* 切刀未复位
*/
int
CODE_KNIFE_ERROR
=
4
;
/**
* 打印头过热
*/
int
CODE_PRINT_HEAD_HOT
=
5
;
/**
* 黑标错误
*/
int
CODE_BLACK_ERROR
=
6
;
/**
* 纸尽
*/
int
CODE_NO_PAPER
=
7
;
/**
* 纸将尽
*/
int
CODE_FEW_PAPER
=
8
;
//================全局状态码定义end===============//
/**
* 初始化驱动
*
* @param context 调用者上下文索引
* @return true==>初始化成功;false==>初始化失败
*/
boolean
init
(
Context
context
);
/**
* 销毁资源
*
* @return
*/
boolean
release
();
/**
* 开始新一轮打印
*
* @return 状态码
*/
int
beginPrint
();
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment