|
|
@ -1,6 +1,8 @@ |
|
|
|
#include "eq20_servomotor.hpp"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "sdk\components\modbus\modbus_basic.hpp"
|
|
|
|
using namespace std; |
|
|
|
using namespace iflytop; |
|
|
|
|
|
|
@ -11,18 +13,54 @@ static void dumpbuf(const char *mark, const char *buf, int len) { |
|
|
|
} |
|
|
|
printf("\n"); |
|
|
|
} |
|
|
|
void ServoMotor::init(ModbusBlockHost *modbusBlockHost) { |
|
|
|
void Eq20ServoMotor::init(ModbusBlockHost *modbusBlockHost) { |
|
|
|
// this->com = com;
|
|
|
|
m_modbusBlockHost = modbusBlockHost; |
|
|
|
} |
|
|
|
bool ServoMotor::writereg32(int deviceid, uint32_t regadd, int value) { //
|
|
|
|
m_modbusBlockHost->writeReg10(deviceid, regadd, value, 50); |
|
|
|
} |
|
|
|
bool ServoMotor::readreg(int deviceid, uint32_t regadd, int &value) { |
|
|
|
uint16_t value16[2]; |
|
|
|
m_modbusBlockHost->readReg03Muti(deviceid, regadd, value16, 2, 50); |
|
|
|
value = value16[0] + (value16[1] << 16); |
|
|
|
bool Eq20ServoMotor::writereg32(int deviceid, uint32_t regadd, int value) { //
|
|
|
|
m_modbusBlockHost->cleanRxBuff(); |
|
|
|
|
|
|
|
uint8_t sendBuff[30] = {0}; |
|
|
|
sendBuff[0] = deviceid; |
|
|
|
sendBuff[1] = 0x10; |
|
|
|
sendBuff[2] = regadd / 256; // regadd hi
|
|
|
|
sendBuff[3] = regadd % 256; // regadd li
|
|
|
|
sendBuff[4] = (0); |
|
|
|
sendBuff[5] = (2); |
|
|
|
sendBuff[6] = 4; |
|
|
|
|
|
|
|
sendBuff[7] = (value >> 8) & 0xff; |
|
|
|
sendBuff[8] = (value >> 0) & 0xff; |
|
|
|
sendBuff[9] = (value >> 24) & 0xff; |
|
|
|
sendBuff[10] = (value >> 16) & 0xff; |
|
|
|
modbus_pack_crc_to_packet(sendBuff, 13); |
|
|
|
|
|
|
|
int sendBuff_length = 13; // 2byte УÑé
|
|
|
|
dumpbuf("tx", (char *)sendBuff, sendBuff_length); |
|
|
|
|
|
|
|
// int tx = com->send((char *)sendBuff, sendBuff_length);
|
|
|
|
HAL_StatusTypeDef statu = HAL_UART_Transmit(m_modbusBlockHost->huart, sendBuff, sendBuff_length, 1000); |
|
|
|
if (statu != HAL_OK) { |
|
|
|
ZLOGE("Eq20ServoMotor", "uart send error"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
char rxbuf[30] = {0}; |
|
|
|
// int rxsize = com->receive(rxbuf, 8, 100);
|
|
|
|
statu = HAL_UART_Receive(m_modbusBlockHost->huart, (uint8_t *)rxbuf, 8, 100); |
|
|
|
|
|
|
|
if (statu != HAL_OK) { |
|
|
|
ZLOGE("Eq20ServoMotor", "uart send error,overtime"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
// dumpbuf("rx", rxbuf, rxsize);
|
|
|
|
return true; |
|
|
|
} |
|
|
|
// bool Eq20ServoMotor::readreg(int deviceid, uint32_t regadd, int &value) {
|
|
|
|
// uint16_t value16[2];
|
|
|
|
// m_modbusBlockHost->readReg03Muti(deviceid, regadd, value16, 2, 50);
|
|
|
|
// value = value16[0] + (value16[1] << 16);
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|