update define
This commit is contained in:
parent
2c83a66633
commit
b3f8fc555f
59
protocol.c
59
protocol.c
@ -432,7 +432,11 @@ void DecodePumpStatusMsg(uint16_t reg4002) {
|
||||
(0380h)= 0x06→0x07→0x0F→0x1F,电机运行
|
||||
*/
|
||||
|
||||
static uint8_t SetValveMode(uint8_t index, uint16_t mode) {
|
||||
// 与pump通用
|
||||
void (*writeValve1Reg)(uint8_t index, uint16_t reg, uint16_t value) = WritePump1Reg;
|
||||
void (*writeValve2Reg)(uint8_t index, uint16_t reg, uint32_t value) = WritePump2Reg;
|
||||
|
||||
static uint8_t SetValveCOMMMode(uint8_t index, uint16_t mode) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_CTL_MODE, mode);
|
||||
}
|
||||
static uint8_t SetValveRunMode(uint8_t index, uint16_t mode) {
|
||||
@ -441,30 +445,63 @@ static uint8_t SetValveRunMode(uint8_t index, uint16_t mode) {
|
||||
|
||||
// PP=轮廓位置模式
|
||||
static uint8_t SetValvePPPos(uint8_t index, uint16_t pos) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_PP_POS, pos);
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_PP_POS, pos);
|
||||
}
|
||||
static uint8_t SetValvePPSpeed(uint8_t index, uint16_t speed) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_PP_SPEED, speed);
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_PP_SPEED, speed);
|
||||
}
|
||||
static uint8_t SetValvePPAcc(uint8_t index, uint16_t acc) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_PP_ACCEL, acc);
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_PP_ACCEL, acc);
|
||||
}
|
||||
static uint8_t SetValvePPDec(uint8_t index, uint16_t dec) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_PP_DECEL, dec);
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_PP_DECEL, dec);
|
||||
}
|
||||
|
||||
// HM=原点回归模式
|
||||
static uint8_t SetValveHomeMode(uint8_t index, uint16_t mode) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_HOME_MODE, mode);
|
||||
static uint8_t SetValveHomeDetectMode(uint8_t index, uint16_t mode) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_MODE, mode);
|
||||
}
|
||||
static uint8_t SetValveHomeSpeed(uint8_t index, uint16_t speed) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_HOME_SPEED, speed);
|
||||
static uint8_t SetValveHomeSwtSpeed(uint8_t index, uint16_t speed) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_SWT_SPEED, speed);
|
||||
}
|
||||
static uint8_t SetValveHomeOriSpeed(uint8_t index, uint16_t speed) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_ORI_SPEED, speed);
|
||||
}
|
||||
static uint8_t SetValveHomeAcc(uint8_t index, uint16_t acc) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_HOME_ACCEL, acc);
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_ACCEL, acc);
|
||||
}
|
||||
static uint8_t SetValveFunc(uint8_t index, uint16_t func) {
|
||||
WritePump1Reg(index, RTU_VALVE_CMD_FUNC, func);
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_FUNC, func);
|
||||
}
|
||||
static uint8_t SetValveHomeTorque(uint8_t index, uint16_t torque) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_TORQUE, torque);
|
||||
}
|
||||
static uint8_t SetValveHomeTime(uint8_t index, uint16_t time) {
|
||||
writeValve1Reg(index, RTU_VALVE_CMD_HOME_TIME, time);
|
||||
}
|
||||
|
||||
uint8_t ValveBackToOrigin(uint8_t index) {
|
||||
// 1.设置原点回归方式
|
||||
// (0416h)=37;17=负限位,18=正限位
|
||||
SetValveHomeDetectMode(index, 37);
|
||||
// 2.设置堵转检测力矩和堵转检测时间
|
||||
// (0170h)=300,(0172h)=50
|
||||
SetValveHomeTorque(index, 300);//30%
|
||||
SetValveHomeTime(index, 50);//50ms
|
||||
// 3.写 (00B1h)=0、运行模式 (03C2h)=0x06,使其工作在原点回归模式;
|
||||
SetValveCOMMMode(index, RTU_VALVE_CFG_COMM_CIA402);
|
||||
SetValveRunMode(index, RTU_VALVE_CFG_MODE_HM);
|
||||
// 4.写寻找限位开关速度和寻找原点信号速度(0417h)= 10000 (0419h)=1000;
|
||||
SetValveHomeSwtSpeed(index, 10000);
|
||||
SetValveHomeOriSpeed(index, 1000);
|
||||
// 5.设置回零加速度
|
||||
SetValveHomeAcc(index, 200000);
|
||||
// 6.写控制字
|
||||
// (0380h)= 0x06→0x07→0x0F→0x1F,电机运行
|
||||
SetValveFunc(index, RTU_VALVE_CFG_ENABLE);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_DISABLE);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_RUN);
|
||||
SetValveFunc(index, RTU_VALVE_CFG_RUN_ORIGIN);
|
||||
}
|
||||
|
||||
// 定时1s更新设备状态
|
||||
|
@ -278,11 +278,14 @@ const uint8_t statusInfo[16][32]={
|
||||
#define RTU_VALVE_CMD_PP_DECEL 0x03FE // 阀门轮廓减速度
|
||||
|
||||
#define RTU_VALVE_CMD_HOME_MODE 0x0416 // 阀门原点回归方式
|
||||
#define RTU_VALVE_CMD_HOME_SPEED 0x0417 // 阀门原点回归速度
|
||||
#define RTU_VALVE_CMD_HOME_ACCEL 0x041B // 阀门原点回归加速度
|
||||
#define RTU_VALVE_CMD_HOME_SWT_SPEED 0x0417 // 阀门回归寻找开关的速度
|
||||
#define RTU_VALVE_CMD_HOME_ORI_SPEED 0x0419 // 阀门回归寻找原点的速度
|
||||
#define RTU_VALVE_CMD_HOME_ACCEL 0x041B // 阀门回归加速度
|
||||
#define RTU_VALVE_CMD_FUNC 0x0380 // 阀门控制
|
||||
#define RTU_VALVE_CMD_HOME_TORQUE 0x0170 // 阀门原点回归堵转检测力矩
|
||||
#define RTU_VALVE_CMD_HOME_TIME 0x0172 // 阀门原点回归堵转检测时间
|
||||
|
||||
#define RTU_VALVE_CFG_CTL_CIA402 0x0000 // 为CIA402模式
|
||||
#define RTU_VALVE_CFG_COMM_CIA402 0x0000 // 为CIA402模式
|
||||
#define RTU_VALVE_CFG_MODE_HM 0x0001 // 原点回归模式(HM)
|
||||
#define RTU_VALVE_CFG_MODE_PP 0x0006 // 轮廓位置模式(PP)
|
||||
#define RTU_VALVE_CFG_ENABLE 0x0006 // 准备
|
||||
|
Loading…
Reference in New Issue
Block a user