最新版本密胺计量代码

This commit is contained in:
2025-09-30 14:57:14 +08:00
parent c31aab594d
commit 6833bb7973
16 changed files with 767 additions and 1017 deletions

View File

@ -51,15 +51,15 @@ class RS485Reader:
raise
def read_weight(self):
cmd = bytes.fromhex('010300000002c40b')
cmd = bytes.fromhex('010300000002c40b') # 从地址 01 的设备读取 2 个保持寄存器,从地址 0 开始
try:
self.ser.write(cmd)
response = self.ser.read(9)
response = self.ser.read(9) # 然后读取设备返回的 9 字节响应
if len(response) == 9 and response[:3] == bytes.fromhex("010304"):
weight = int.from_bytes(response[3:5], 'big')
with self.lock:
self.buffer.append(weight)
self.current_weight = sum(self.buffer) // len(self.buffer)
self.current_weight = sum(self.buffer) // len(self.buffer) # 平滑滤波
return True
return False
except Exception as e:
@ -68,7 +68,7 @@ class RS485Reader:
return False
def tare(self): # 去皮方法
cmd = bytes.fromhex('01060064000109d5') # 01 06 00 64 00 01 09 d5
cmd = bytes.fromhex('01060064000109d5') # 01 06 00 64 00 01 09 d5 发送命令给设备地址 1将寄存器地址 0x0064 设置为 0x0001执行“去皮”指令。
try:
if self.read_weight(): # 确保有最新数据
self.ser.write(cmd)