Commit 7e8082a6 authored by tongzifang's avatar tongzifang

1.1.8

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