From 7cfe960bd5f3e45d179f3785933d066805080234 Mon Sep 17 00:00:00 2001 From: "CSSC-WORK\\murmur" Date: Fri, 3 Jan 2025 11:25:55 +0800 Subject: [PATCH] add ReadPumpCNT --- protocol.c | 11 +++++++++-- protocol.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/protocol.c b/protocol.c index 73a9b40..6923bc8 100644 --- a/protocol.c +++ b/protocol.c @@ -597,9 +597,14 @@ static uint8_t StopPump(uint8_t index) { * @param index 泵索引 * @return 0:成功 其他:失败 */ -uint8_t ReadPumpHWReg(uint8_t index) { +uint16_t ReadPumpHWReg(uint8_t index) { return ReadPump1Reg(dp.pump[index].id, RTU_PUMP_CMD_HW); } + +uint16_t ReadPumpCNT(uint8_t index) { + return ReadPump1Reg(dp.pump[index].id, RTU_PUMP_CMD_CNT); +} + /** * 设置泵的通信波特率 * @@ -1589,7 +1594,9 @@ static uint8_t HandlePumpTimeControl(uint8_t *Buff, uint8_t len) { } else { // 使用步数方式更靠谱,通过时间和速度计算步数,结束时不用发送停止命令 - int32_t step = direction*time*systemStatus.pumpsSpeed[index]*PUMP_SPEED_RPS; + uint16_t cnt = ReadPumpCNT(index);//8000 + log_d("cnt=%d",cnt); + int32_t step = direction*time*systemStatus.pumpsSpeed[index]*cnt; StopPump(index);//stop first SetPumpStepTarget(index, step); StartPumpRelativeMove(index); diff --git a/protocol.h b/protocol.h index 45c43ed..a2abbf6 100644 --- a/protocol.h +++ b/protocol.h @@ -214,6 +214,7 @@ static const uint8_t statusInfo[16][60]={ #define RTU_PUMP_CMD_VE 0x001D // 速度 #define RTU_PUMP_CMD_DI 0x001E // 目标位置 #define RTU_PUMP_CMD_HW 0x006C // 硬件版本40109 +#define RTU_PUMP_CMD_CNT 0X0034 //每转所需脉冲数 #define RTU_PUMP_CMD_BR 0x0094 //波特率BR,40149 #define RTU_PUMP_CMD_PR 0x0095 //通信协议PR,40150 #define RTU_PUMP_CMD_SPEED 0x000A //瞬时实际速度,40011