|
|
@ -6,9 +6,7 @@ using namespace iflytop; |
|
|
|
ModbusBlockHost::ModbusBlockHost() {} |
|
|
|
ModbusBlockHost::~ModbusBlockHost() {} |
|
|
|
|
|
|
|
void ModbusBlockHost::initialize(UART_HandleTypeDef *huart) { |
|
|
|
this->huart = huart; |
|
|
|
} |
|
|
|
void ModbusBlockHost::initialize(UART_HandleTypeDef *huart) { this->huart = huart; } |
|
|
|
void ModbusBlockHost::cleanRxBuff() { //
|
|
|
|
HAL_StatusTypeDef status; |
|
|
|
do { |
|
|
@ -17,6 +15,7 @@ void ModbusBlockHost::cleanRxBuff() { // |
|
|
|
} |
|
|
|
|
|
|
|
void ModbusBlockHost::uarttx(uint8_t *buff, size_t len) { |
|
|
|
ZASSERT(len < sizeof(txbuff)); |
|
|
|
#if DEBUG
|
|
|
|
printf("uarttx:\n"); |
|
|
|
for (size_t i = 0; i < len; i++) { |
|
|
@ -28,6 +27,8 @@ void ModbusBlockHost::uarttx(uint8_t *buff, size_t len) { |
|
|
|
} |
|
|
|
bool ModbusBlockHost::uartrx(uint8_t *buff, size_t len, int overtimems) { |
|
|
|
HAL_StatusTypeDef status; |
|
|
|
ZASSERT(len < sizeof(rxbuff)); |
|
|
|
|
|
|
|
status = HAL_UART_Receive(huart, buff, len, overtimems); |
|
|
|
#if DEBUG
|
|
|
|
if (status == HAL_OK) { |
|
|
@ -55,7 +56,7 @@ bool ModbusBlockHost::readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t *r |
|
|
|
uarttx(txbuff, 6 + 2); |
|
|
|
|
|
|
|
bool status; |
|
|
|
status = uartrx(rxbuff, 7, overtimems); |
|
|
|
status = uartrx(rxbuff, 5 + 2, overtimems); |
|
|
|
|
|
|
|
if (status && modbus_checkcrc16(rxbuff, 7)) { |
|
|
|
*regVal = rxbuff[3] << 8 | rxbuff[4]; |
|
|
@ -78,7 +79,8 @@ bool ModbusBlockHost::readReg03Muti(uint8_t slaveAddr, uint16_t regAddr, uint16_ |
|
|
|
uarttx(txbuff, 6 + 2); |
|
|
|
|
|
|
|
bool status; |
|
|
|
status = uartrx(rxbuff, 7 + regNum * 2, overtimems); |
|
|
|
// 14*2 = 28
|
|
|
|
status = uartrx(rxbuff, 5 + regNum * 2, overtimems); |
|
|
|
|
|
|
|
if (status && modbus_checkcrc16(rxbuff, 7 + regNum * 2)) { |
|
|
|
for (int i = 0; i < regNum; i++) { |
|
|
|