diff --git a/protocol.c b/protocol.c index e8a1fc5..319032b 100644 --- a/protocol.c +++ b/protocol.c @@ -444,31 +444,31 @@ static uint8_t SetValveRunMode(uint8_t index, uint16_t mode) { } // PP=轮廓位置模式 -static uint8_t SetValvePPPos(uint8_t index, uint16_t pos) { - writeValve1Reg(index, RTU_VALVE_CMD_PP_POS, pos); +static uint8_t SetValvePPPos(uint8_t index, uint32_t pos) { + writeValve2Reg(index, RTU_VALVE_CMD_PP_POS, pos); } -static uint8_t SetValvePPSpeed(uint8_t index, uint16_t speed) { - writeValve1Reg(index, RTU_VALVE_CMD_PP_SPEED, speed); +static uint8_t SetValvePPSpeed(uint8_t index, uint32_t speed) { + writeValve2Reg(index, RTU_VALVE_CMD_PP_SPEED, speed); } -static uint8_t SetValvePPAcc(uint8_t index, uint16_t acc) { - writeValve1Reg(index, RTU_VALVE_CMD_PP_ACCEL, acc); +static uint8_t SetValvePPAcc(uint8_t index, uint32_t acc) { + writeValve2Reg(index, RTU_VALVE_CMD_PP_ACCEL, acc); } -static uint8_t SetValvePPDec(uint8_t index, uint16_t dec) { - writeValve1Reg(index, RTU_VALVE_CMD_PP_DECEL, dec); +static uint8_t SetValvePPDec(uint8_t index, uint32_t dec) { + writeValve2Reg(index, RTU_VALVE_CMD_PP_DECEL, dec); } // HM=原点回归模式 static uint8_t SetValveHomeDetectMode(uint8_t index, uint16_t mode) { writeValve1Reg(index, RTU_VALVE_CMD_HOME_MODE, mode); } -static uint8_t SetValveHomeSwtSpeed(uint8_t index, uint16_t speed) { - writeValve1Reg(index, RTU_VALVE_CMD_HOME_SWT_SPEED, speed); +static uint8_t SetValveHomeSwtSpeed(uint8_t index, uint32_t speed) { + writeValve2Reg(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 SetValveHomeOriSpeed(uint8_t index, uint32_t speed) { + writeValve2Reg(index, RTU_VALVE_CMD_HOME_ORI_SPEED, speed); } -static uint8_t SetValveHomeAcc(uint8_t index, uint16_t acc) { - writeValve1Reg(index, RTU_VALVE_CMD_HOME_ACCEL, acc); +static uint8_t SetValveHomeAcc(uint8_t index, uint32_t acc) { + writeValve2Reg(index, RTU_VALVE_CMD_HOME_ACCEL, acc); } static uint8_t SetValveFunc(uint8_t index, uint16_t func) { writeValve1Reg(index, RTU_VALVE_CMD_FUNC, func); @@ -480,6 +480,10 @@ static uint8_t SetValveHomeTime(uint8_t index, uint16_t time) { writeValve1Reg(index, RTU_VALVE_CMD_HOME_TIME, time); } +uint8_t updateValveStatus(uint8_t index, uint16_t status) { + // writeValve1Reg(index, RTU_VALVE_CMD_STATUS, status); +} + uint8_t ValveBackToOrigin(uint8_t index) { // 1.设置原点回归方式 // (0416h)=37;17=负限位,18=正限位 @@ -504,6 +508,31 @@ uint8_t ValveBackToOrigin(uint8_t index) { SetValveFunc(index, RTU_VALVE_CFG_RUN_ORIGIN); } +uint8_t ValveRunInit(uint8_t index) { +// 1.配置模式: +// 00B1h=0、运行模式 03C2h=0x01,使设备工作在轮廓位置模式; + SetValveCOMMMode(index, RTU_VALVE_CFG_COMM_CIA402); + SetValveRunMode(index, RTU_VALVE_CFG_MODE_PP); +// 2.参数配置: +// 2.1写目标位置 (03E7h)(用户单位); + // SetValvePPPos(index, 0); +// 2.2写当前段位移指令匀速运行速度 (03F8h) (用户单位/s); + SetValvePPSpeed(index, 1000); +// 2.3设置位移的加速度 (03FCh)(用户单位/s2) + SetValvePPAcc(index, 10000); +// 2.4设置位移的减速度 (03FEh)(用户单位/s2); + SetValvePPDec(index, 10000); +// 3.写控制字使电机使能 +// (0380h)= 0x06→0x07→ 0x0F,电机使能: + SetValveFunc(index, RTU_VALVE_CFG_ENABLE); + SetValveFunc(index, RTU_VALVE_CFG_DISABLE); + SetValveFunc(index, RTU_VALVE_CFG_RUN); +// 4.使电机运行 +// (0380h)= 0x2F→0x3F,电机运行 + SetValveFunc(index, 0x2F); + SetValveFunc(index, 0x3F); +} + // 定时1s更新设备状态 // 活度计通过网口获取 // 下挂设备通过485获取 diff --git a/protocol.h b/protocol.h index 1e37c88..8bdcbd0 100644 --- a/protocol.h +++ b/protocol.h @@ -286,8 +286,8 @@ const uint8_t statusInfo[16][32]={ #define RTU_VALVE_CMD_HOME_TIME 0x0172 // 阀门原点回归堵转检测时间 #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_MODE_HM 0x0006 // 原点回归模式(HM) +#define RTU_VALVE_CFG_MODE_PP 0x0001 // 轮廓位置模式(PP) #define RTU_VALVE_CFG_ENABLE 0x0006 // 准备 #define RTU_VALVE_CFG_DISABLE 0x0007 // 失能 #define RTU_VALVE_CFG_RUN 0x000F // 运行