Commit eff70a11 authored by 高英祥's avatar 高英祥

添加称重去皮皮重

parent abd5cb8e
......@@ -30,7 +30,7 @@ android {
}
}
group 'com.qmai.android.zqtoolkit'
version '1.3.6'
version '1.3.9.5'
gradlePublish {
......
......@@ -9,6 +9,6 @@ data class LivingWeight(
val isStable: Boolean,
val weight: String,
var unit: String,
val tare: String,
val isReadErr: Boolean
val tare: String,//皮重
val isReadErr: Boolean //是否读错
)
package com.qmai.zqtoolkit.base
import android.annotation.SuppressLint
import android.content.Context
import android_serialport_api.SerialPortFinder
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.TimeUtils
import com.qmai.zqtoolkit.ConnectState
import com.qmai.zqtoolkit.LivingWeight
import com.qmai.zqtoolkit.ScaleInfo
import com.qmai.zqtoolkit.base.scale.ScaleBaseKit
import com.qmai.zqtoolkit.config.QmScaleBrand
import tp.xmaihh.serialport.SerialHelper
......@@ -23,7 +26,7 @@ object SllchKit : ScaleBaseKit() {
override val SCALE_TYPE: QmScaleBrand
get() = QmScaleBrand.SLLCH
override val STABLE_COUNT: Int
get() = 0
get() = 6
override val CONECT_CHECK_COUNT: Int
get() = 4
......@@ -36,27 +39,11 @@ object SllchKit : ScaleBaseKit() {
private val serialPortFinder by lazy { SerialPortFinder() }
private var serialHelper: SerialHelper? = null
init {
serialHelper = object : SerialHelper("dev/ttyS9", 9600) {
override fun onDataReceived(comBean: ComBean) {
updateScaleInfo(
"${AclasScaleKit.TAG} :onRcvData " + TimeUtils.getNowString() + " data: " + GsonUtils.toJson(
comBean
)
)
// getTare()
updateWeight(
LivingWeight(
isStable(comBean),
weightKg(comBean),
"kg",
"",
comBean.bRec.isNotEmpty()
)
)
}
}
}
//自己记录皮重
private var tare = "0.00"
//最后一次重量
private var lastWeight = "0.00"
/**
* 是否稳定
......@@ -96,19 +83,44 @@ object SllchKit : ScaleBaseKit() {
}
}
override fun readData() {
try {
serialHelper?.close()
serialHelper?.port = lastTryScale?.port
serialHelper?.baudRate = lastTryScale?.buad?.toInt() ?: 9600
override fun connect(cxt: Context?, scale: ScaleInfo) {
super.connect(cxt, scale)
if (serialHelper == null) {
serialHelper = object : SerialHelper("/dev/ttyS9", 9600) {
override fun onDataReceived(comBean: ComBean) {
updateScaleInfo(
"${AclasScaleKit.TAG} :onRcvData " + TimeUtils.getNowString() + " data: " + GsonUtils.toJson(
comBean
)
)
val it = LivingWeight(
isStable = isStable(comBean),
weight = weightKg(comBean),
unit = "kg",
tare = tare,
isReadErr = false
)
updateWeight(it)
lastWeight = weightKg(comBean)
LogUtils.e(TAG, GsonUtils.toJson(it))
}
}
serialHelper?.open()
updateState(ConnectState(true, "打开成功"))
} catch (e: Exception) {
updateState(ConnectState(false, "打开失败"))
}
}
override fun readData() {
// try {
// updateState(ConnectState(true, "打开成功"))
// } catch (e: Exception) {
// updateState(ConnectState(false, "打开失败"))
// }
}
override fun stopReadData() {
//serialHelper?.close()
}
override fun setZero() {
......@@ -117,16 +129,19 @@ object SllchKit : ScaleBaseKit() {
//去皮
override fun setNetWeight() {
this.tare = lastWeight
serialHelper?.send(cmd)
}
//去皮
override fun setNetWeightByElec(tare: Double) {
this.tare = lastWeight
serialHelper?.send(cmd)
}
//清除去皮
override fun clearTare() {
this.tare = "0.00"
serialHelper?.send(cmdZero)
}
......
......@@ -22,7 +22,7 @@ abstract class ScaleBaseKit : ScaleBaseAction, ScaleUpdateAction {
abstract val TAG: String
abstract val SCALE_TYPE: QmScaleBrand
abstract val STABLE_COUNT: Int //顶尖称有假稳定情况,设置稳定达到一定次数后再给业务发数据
abstract val STABLE_COUNT: Int //顶尖称有假稳定情况,设置稳定达到一定次数后再给业务发数据:必须 > 0
abstract val CONECT_CHECK_COUNT: Int //中崎外接称+sunmi 不处于物理连接状态,连接也能返回成功,增加读取重量次数,二次确认是否连接
var lastTryScale: ScaleInfo? = null
private var lastConnectScale: ScaleInfo? = null
......
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