Commit 7e8082a6 authored by tongzifang's avatar tongzifang

1.1.8

parent 6ef2b60b
......@@ -30,7 +30,7 @@ android {
}
}
group 'com.qmai.android.zqtoolkit'
version '1.1.4'
version '1.1.8'
gradlePublish {
......
......@@ -102,9 +102,6 @@ object ScaleHub : ScaleBaseAction {
}
connectJob?.launch(context = Dispatchers.IO) {
scaleKit?.connect(cxt, scale)
if (scaleKit is ZqScaleKit) {
LEDHub.connect()
}
collectConnectData()
}
}
......@@ -113,6 +110,9 @@ object ScaleHub : ScaleBaseAction {
private suspend fun collectConnectData() {
scaleKit?.connectState?.collect {
_connectState.emit(it)
if (scaleKit is ZqScaleKit && it.isConnect) {
LEDHub.connect()
}
}
}
......
......@@ -21,6 +21,8 @@ object AclasScaleKit : ScaleBaseKit() {
get() = "AclasScaleKit"
override val STABLE_COUNT: Int
get() = 4
override val CONECT_CHECK_COUNT: Int
get() = 0
override val SCALE_TYPE: QmScaleBrand
get() = QmScaleBrand.ACLAS
private var aclasScaler: AclasScaler? = null
......
......@@ -23,6 +23,8 @@ object SunmiScaleKit : ScaleBaseKit() {
get() = "SunmiScaleKit"
override val STABLE_COUNT: Int
get() = 3
override val CONECT_CHECK_COUNT: Int
get() = 0
override val SCALE_TYPE: QmScaleBrand
get() = QmScaleBrand.SUNMI
......
......@@ -24,30 +24,54 @@ object ZqScaleKit : ScaleBaseKit() {
get() = "ZqScaleKit"
override val STABLE_COUNT: Int
get() = 4
override val CONECT_CHECK_COUNT: Int
get() = 4
override val SCALE_TYPE: QmScaleBrand
get() = QmScaleBrand.ZQEB
private var connectCache = mutableListOf<Boolean>()
override fun connect(cxt: Context?, scale: ScaleInfo) {
super.connect(cxt, scale)
val ebConnect =
zqeb.EB_Connect(String.format("%s:%s", scale.port ?: "ttyS4", scale.buad ?: "9600"), cxt)
val msg: String = when (ebConnect) {
zqeb.EB_Connect(
String.format("%s:%s", scale.port ?: "ttyS4", scale.buad ?: "9600"),
cxt
)
when (ebConnect) {
PrinterConst.ErrorCode.SUCCESS -> {
"打开成功"
}
PrinterConst.ErrorCode.INVALIDPARAM -> {
"打印机参数无效"
}
PrinterConst.ErrorCode.PORTERROR -> {
"端口错误"
}
PrinterConst.ErrorCode.NOPERMISSION -> {
"没有该端口的访问权限"
GlobalScope.launch {
flow {
connectCache.clear()
for (i in 0..CONECT_CHECK_COUNT) {
emit(getWeightTare().isStable)
delay(80)
}
}.collect {
when {
connectCache.size >= CONECT_CHECK_COUNT -> {
if (connectCache.any { cn -> cn })
updateState(ConnectState(true, "打开成功"))
else updateState(ConnectState(false, "打开失败"))
connectCache.clear()
}
else -> connectCache.add(it)
}
}
}
}
else -> "未知错误"
else -> updateState(
ConnectState(
ebConnect == PrinterConst.ErrorCode.SUCCESS, when (ebConnect) {
PrinterConst.ErrorCode.INVALIDPARAM -> "打印机参数无效"
PrinterConst.ErrorCode.PORTERROR -> "端口错误"
PrinterConst.ErrorCode.NOPERMISSION -> "没有该端口的访问权限"
else -> "未知错误"
}
)
)
}
updateState(ConnectState(ebConnect == PrinterConst.ErrorCode.SUCCESS, msg))
}
private val zqeb by lazy {
......@@ -124,14 +148,14 @@ object ZqScaleKit : ScaleBaseKit() {
if (isActive) {
weightFlow.flowOn(Dispatchers.IO)
.collect {
getWeightTare()
updateWeight(getWeightTare())
}
}
}
}
//读取重量、皮重
private fun getWeightTare() {
private fun getWeightTare(): LivingWeight {
val strRet: Array<String> = zqeb.EB_GetWeightTare()
Log.v(
TAG, String.format(
......@@ -157,14 +181,12 @@ object ZqScaleKit : ScaleBaseKit() {
&& strWeight.isNotEmpty() && strWeight.toFloat() < 0)
) {
strState = "OK"
updateWeight(
LivingWeight(
true,
strWeight.trim(),
strUnit,
strTare.trim(),
false
)
return LivingWeight(
true,
strWeight.trim(),
strUnit,
strTare.trim(),
false
)
} else {
// when (Integer.valueOf(strRet[0])) {
......@@ -174,13 +196,11 @@ object ZqScaleKit : ScaleBaseKit() {
// 1 -> strState = "Weight instability"
// 2 -> strState = "Weight overflow or not ZERO"
// }
updateWeight(
LivingWeight(
false,
strWeight.trim(),
strUnit, strTare.trim(),
Integer.valueOf(strRet[0]) == -2 || Integer.valueOf(strRet[0]) == -3
)
return LivingWeight(
false,
strWeight.trim(),
strUnit, strTare.trim(),
Integer.valueOf(strRet[0]) == -2 || Integer.valueOf(strRet[0]) == -3
)
}
}
......
......@@ -20,6 +20,7 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
abstract val TAG: String
abstract val SCALE_TYPE: QmScaleBrand
abstract val STABLE_COUNT: Int //顶尖称有假稳定情况,设置稳定达到一定次数后再给业务发数据
abstract val CONECT_CHECK_COUNT: Int //中崎外接称+sunmi 不处于物理连接状态,连接也能返回成功,增加读取重量次数,二次确认是否连接
var lastTryScale: ScaleInfo? = null
private var lastConnectScale: ScaleInfo? = null
......
......@@ -15,8 +15,8 @@ enum class SunmiPort(
HSL1("ttyHSL1", listOf("d2mini", "t1", "t1mini")),
HSL3("ttyHSL3", listOf("t2", "s1", "t2lite", "x2", "t2mini")),
S1("ttyS1", listOf("n1", "d2", "d1s")),
S3("ttyS3", listOf("n1_d", "d2_d", "d1s_d", "s2cc")),
S0("ttyS0", listOf("d2s_kdS", "d2_2nd"));
S3("ttyS3", listOf("n1_d", "d2_d", "d1s_d", "s2_cc")),
S0("ttyS0", listOf("d2s_kds", "d2_2nd"));
companion object {
fun find(): String {
......
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