This commit is contained in:
2026-04-23 11:30:05 +08:00
parent 4260918f36
commit 01df5523a7
11 changed files with 480 additions and 3229 deletions

12
.vscode/settings.json vendored
View File

@ -66,6 +66,16 @@
"functional": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp"
"utility": "cpp",
"random": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"string_view": "cpp",
"initializer_list": "cpp",
"cmath": "cpp",
"streambuf": "cpp"
}
}

View File

@ -1,357 +0,0 @@
#include "VinceMotorControllerUsb.h"
VinceMotorControllerUsb::VinceMotorControllerUsb(QString serialPortNumber, QString paramJson, QObject* parent)
:QObject(parent)
{
m_pSerialPort = new QSerialPort(this);
m_pSerialPort->setPortName(serialPortNumber);
m_pSerialPort->setReadBufferSize(512);
bool bRes = m_pSerialPort->setBaudRate(9600);
if (!bRes)
{
//qDebug() << "Err:setBaudRate Failed.Exit Code:1";
//std::cout << "Err.setBaudRate Failed" << std::endl;
printf("Err:setBaudRate Failed.Exit Code:1");
}
bRes = m_pSerialPort->open(QIODevice::ReadWrite);
if (!bRes)
{
//qDebug() << "Err:open Failed.Exit Code:2";
//std::cout << "Err.open Failed" << std::endl;
printf("Err:open Failed.Exit Code:2");
}
m_iSpeed = 3000;
init(paramJson);
}
VinceMotorControllerUsb::~VinceMotorControllerUsb()
{
delete m_pSerialPort;
}
int VinceMotorControllerUsb::sendCommand2Motor(QString cmd)
{
QByteArray commandData = cmd.toUtf8(); // <20><> QString ת<><D7AA>Ϊ QByteArray
qint64 bytesWritten = m_pSerialPort->write(commandData);
/*if (bytesWritten == -1) {
qDebug() << "д<><D0B4>ʧ<EFBFBD><CAA7>:" << m_pSerialPort->errorString();
}
else if (bytesWritten != commandData.size()) {
qDebug() << "д<><EFBFBD><EBB2BB><EFBFBD><EFBFBD>";
}
else {
qDebug() << "<22><><EFBFBD><EFBFBD>ͳɹ<CDB3>";
}*/
return bytesWritten;
}
int VinceMotorControllerUsb::recvData(QByteArray& dataRecv)
{
dataRecv.clear();
QByteArray temp;
temp = m_pSerialPort->readAll();
dataRecv.append(temp);
while (dataRecv.size() < 21)
{
m_pSerialPort->waitForReadyRead(100);
temp = m_pSerialPort->readAll();
dataRecv.append(temp);
}
return 0;
}
IrisMotorErrorCode VinceMotorControllerUsb::extractOneValidFrame(QByteArray& buffer)
{
//std::cout << "before------" << buffer.size() << std::endl;
//std::cout << buffer.toHex().toStdString() << std::endl;
IrisMotorErrorCode errorCode = MOTOR_NO_ERROR;
//<2F><>ʽ1<CABD><31>
/*int startPos = buffer.lastIndexOf('\xFF');
int endPos = buffer.indexOf('\xFE');
if (endPos <= startPos)
{
errorCode = MOTOR_INVALID_FRAME;
return errorCode;
}
buffer = buffer.mid(startPos, endPos - startPos + 1);*/
//<2F><>ʽ2<CABD><32>
//ff00ffffff000200000000000000391f6900000d42030001feff00ff000200000000000000391f6900000d42030001feff0002043458000000003c745e00000d402b001afeff00ff0002000000000000003d3b7200000d4207003efeff00020c34580000000039076e00000d4023005cfeff00ff00020000000000000038411900000d420f0022feff000204345800000000477e7700000d402b0042feff00ff00020000000000000048456a00000d420b0021feff00020434245400000049006d00000d400b0020feff00ff000200000000000000493c3100000d4203000afeff0002043458000000004d444b00000d402f004afe
//ff00ffffffff000200000000000000112d6f00000c42070018fe
QList<QByteArray> validFrames;
int start = 0;
while (start < buffer.size())
{
// <20><><EFBFBD><EFBFBD>֡ͷ 'ff'
int frameStart = buffer.indexOf(MOTOR_SYNC, start);
if (buffer.at(frameStart + 1) == MOTOR_SYNC)
continue;
if (frameStart == -1)
{
break; // û<><C3BB><EFBFBD>ҵ<EFBFBD>֡ͷ<D6A1><CDB7><EFBFBD>˳<EFBFBD>ѭ<EFBFBD><D1AD>
}
// <20><><EFBFBD><EFBFBD>֡β 'fe'
int frameEnd = buffer.indexOf(MOTOR_ETX, frameStart + 1);
if (frameEnd == -1)
{
break; // û<><C3BB><EFBFBD>ҵ<EFBFBD>֡β<D6A1><CEB2><EFBFBD>˳<EFBFBD>ѭ<EFBFBD><D1AD>
}
// <20><>ȡ<EFBFBD><C8A1>Ч֡<D0A7><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡ͷ<D6A1><CDB7>֡β<D6A1><CEB2>
QByteArray frame = buffer.mid(frameStart, frameEnd - frameStart + 1);
// <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>21
if (frame.size() == 21)
{
validFrames.append(frame);
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ<CABC>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>֡
start = frameEnd + 1;
}
if (validFrames.size() == 0)
{
std::cout << "error--------------: " << buffer.toHex().toStdString() << std::endl;
errorCode = MOTOR_INVALID_FRAME;
return errorCode;
}
buffer = validFrames.at(validFrames.size() - 1);
//<2F><>ʽ3<CABD><33><EFBFBD>ӽ<EFBFBD>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Ч֡<D0A7><D6A1>1<EFBFBD><31><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>fe<66><65>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>fe<66><65>ʼ<EFBFBD><CABC>ǰ<EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>Ч֡<D0A7><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ21<32><31>
//std::cout << "after" << buffer.size() << std::endl;
//std::cout << buffer.toHex().toStdString() << std::endl;
return errorCode;
}
IrisMotorErrorCode VinceMotorControllerUsb::parseOneValidFrame(QByteArray& buf, State& backdatt)
{
IrisMotorErrorCode errorCode = MOTOR_NO_ERROR;
backdatt.Speed = MOTOR_disconnection;
buf.remove(0, 3);
buf.remove(buf.length() - 3, 3);
int location;
unsigned char a[15];
memcpy(a, buf.data(), 15);
location = ((a[0] & 0x0f) << 28) | ((a[1] & 0x7f) << 21) | ((a[2] & 0x7f) << 14) | ((a[3] & 0x7f) << 7) | ((a[4] & 0x7f));
float speed;
memcpy(&speed, &location, 4);
backdatt.Speed = speed;
int loc;
loc = ((a[5] & 0x0f) << 28) | ((a[6] & 0x7f) << 21) | ((a[7] & 0x7f) << 14) | ((a[8] & 0x7f) << 7) | ((a[9] & 0x7f));
backdatt.Location = loc;
backdatt.Speed = speed;
location = ((a[10] & 0x0f) << 28) | ((a[11] & 0x7f) << 21) | ((a[12] & 0x7f) << 14) | ((a[13] & 0x7f) << 7) | ((a[14] & 0x7f));
backdatt.Stata = unsigned int(location);
/*QString str1 = "Speed " + QString::number(backdatt.Speed, 'f', 2) + " location " + QString::number(backdatt.Location);
qDebug() << str1;*/
return errorCode;
}
IrisMotorErrorCode VinceMotorControllerUsb::parseBytedata(QByteArray buf, State& backdatt)
{
IrisMotorErrorCode errorCode = extractOneValidFrame(buf);
backdatt.Speed = MOTOR_disconnection;
backdatt.Location = 0;
if (errorCode == MOTOR_NO_ERROR)
{
parseOneValidFrame(buf, backdatt);
return errorCode;
}
errorCode = MOTOR_INVALID_FRAME;
return errorCode;
}
void VinceMotorControllerUsb::init(QString jsonPath)
{
enable();
JsonOperate xxx(jsonPath);
//xxx.createJsonFile();
QStringList re = xxx.parseJsonFile();
for (const QString& pair : re)
{
//qDebug().noquote() << pair;
sendCommand2Motor(pair);
QByteArray buf;
recvData(buf);
}
//QString cmd;
////cmd = "cfg s1f=2\n";//<2F>ò<EFBFBD><C3B2><EFBFBD>
////sendCommand2Motor(cmd);
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//cmd = "cfg zmd=2\n";
//sendCommand2Motor(cmd);
//cmd = "cfg snr=0\n";
//sendCommand2Motor(cmd);
//cmd = "cfg osv=0\n";//<2F><><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//sendCommand2Motor(cmd);
//cmd = "cfg zsd=3000\n";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD>
//sendCommand2Motor(cmd);
//cmd = "cfg zsp=2400\n";
//sendCommand2Motor(cmd);
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//cmd = "cfg msr=1\n";//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//sendCommand2Motor(cmd);
//cmd = "cfg msv=0\n";
//sendCommand2Motor(cmd);
//cmd = "cfg psr=2\n";
//sendCommand2Motor(cmd);
//cmd = "cfg psv=0\n";
//sendCommand2Motor(cmd);
////<2F>Ӽ<EFBFBD><D3BC>ٶȺ͵<C8BA><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//cmd = "cfg mcs=7\n";//<2F><><EFBFBD><EFBFBD>ϸ<EFBFBD><CFB8>
//sendCommand2Motor(cmd);
//cmd = "cfg acc=20000\n";
//sendCommand2Motor(cmd);
//cmd = "cfg dec=20000\n";
//sendCommand2Motor(cmd);
//cmd = "cfg crn=4\n";
//sendCommand2Motor(cmd);
//cmd = "cfg cra=4\n";
//sendCommand2Motor(cmd);
//cmd = "cfg crh=1\n";
//sendCommand2Motor(cmd);
}
bool VinceMotorControllerUsb::isConnected()
{
State re = getState();
if (re.Speed == MOTOR_disconnection)
{
return false;
}
else
{
return true;
}
}
void VinceMotorControllerUsb::enable()
{
QString cmd = "ena\n";
sendCommand2Motor(cmd);
QByteArray buf;
recvData(buf);
}
void VinceMotorControllerUsb::move2Pos(double pos)
{
QString cmd = "pos " + QString::number(pos, 'f', 10) + "\n";
sendCommand2Motor(cmd);
QByteArray buf;
recvData(buf);
}
void VinceMotorControllerUsb::move(bool towardOrigin)
{
if (towardOrigin)
{
setSpeed(abs(m_iSpeed) * -1);
}
else
{
setSpeed(abs(m_iSpeed));
}
sendCommand2Motor("mov\n");
QByteArray buf;
recvData(buf);
}
void VinceMotorControllerUsb::stopMove()
{
QString cmd = "stp\n";
sendCommand2Motor(cmd);
QByteArray buf;
recvData(buf);
}
void VinceMotorControllerUsb::setSpeed(double speed)
{
m_iSpeed = speed;
QString cmd = "cfg spd=" + QString::number(speed) + "\n";
sendCommand2Motor(cmd);
QByteArray buf;
recvData(buf);
}
double VinceMotorControllerUsb::getSpeed()
{
State re = getState();
return re.Speed;
}
double VinceMotorControllerUsb::getCurrentLoc()
{
State re = getState();
return re.Location;
}
void VinceMotorControllerUsb::zeroStart()
{
QString cmd = "zero start\n";
sendCommand2Motor(cmd);
QByteArray buf;
recvData(buf);
}
int VinceMotorControllerUsb::getSpeedLocation(double& speed, double& locatioin)
{
State re = getState();
speed = re.Speed;
locatioin = re.Location;
return 0;
}
State VinceMotorControllerUsb::getState()
{
QString cmd = "sts\n";
sendCommand2Motor(cmd);
QByteArray buf;
recvData(buf);
//std::cout << buf.size() << std::endl;
//std::cout << buf.toHex().toStdString() << std::endl;
State back;
IrisMotorErrorCode errorCode = parseBytedata(buf, back);
return back;
}

View File

@ -1,50 +0,0 @@
#pragma once
#include <QObject>
#include <QString>
#include <QtSerialPort/QSerialPort>
#include <QDebug>
#include <iostream>
#include "JsonOperate.h"
#include "MotorControllerBase.h"
#define MOTOR_SYNC (0xFF)//֡ͷ
#define MOTOR_ETX (0xFE)//֡β
#define MOTOR_disconnection -1000000//<2F>ٶȵ<D9B6><C8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨѶ<CDA8>
class VinceMotorControllerUsb :
public MotorControllerBase, QObject
{
Q_OBJECT
public:
VinceMotorControllerUsb(QString serialPort, QString paramJson, QObject* parent = nullptr);
~VinceMotorControllerUsb();
void init(QString jsonPath);
int sendCommand2Motor(QString cmd);
bool isConnected();
void enable();
void move2Pos(double pos);
void move(bool towardOrigin);//true<75><65>Զ<EFBFBD><D4B6>ԭ<EFBFBD>㣬false<73><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>
void stopMove();
void setSpeed(double speed);
double getSpeed();
double getCurrentLoc();
void zeroStart();
int getSpeedLocation(double& speed, double& locatioin);
State getState();
int recvData(QByteArray& dataRecv);
IrisMotorErrorCode parseBytedata(QByteArray buf, State& backdatt);
IrisMotorErrorCode extractOneValidFrame(QByteArray& buffer);
IrisMotorErrorCode parseOneValidFrame(QByteArray& buffer, State& result);
private:
QSerialPort* m_pSerialPort;
double m_iSpeed;
};

View File

@ -1,73 +0,0 @@
{"command": "cfg"}
{"command": "ena"}
{"command": "off"}
{"command": "mov"}
{"command": "org"}
{"command": "dev"}
{"command": "sts"}
{"command": "zero_start"}
{"command": "zero_stop"}
{"command": "sav"}
{"command": "pos", "PA": {"value": 1000}}
{"command": "rmv", "PA": {"value": 500}}
{"command": "pps", "PA": {"value": 1000}}
{"command": "stp", "PA": {"value": 1}}
{"command": "cfg_bdr", "PA": {"value": 115200}}
{"command": "cfg_mcs", "PA": {"value": 5}}
{"command": "cfg_spd", "PA": {"value": 10000}}
{"command": "cfg_acc", "PA": {"value": 100000}}
{"command": "cfg_dec", "PA": {"value": 100000}}
{"command": "cfg_cra", "PA": {"value": 1.5}}
{"command": "cfg_crn", "PA": {"value": 1.0}}
{"command": "cfg_crh", "PA": {"value": 0.5}}
{"command": "cfg_zmd", "PA": {"value": 2}}
{"command": "cfg_snr", "PA": {"value": 1}}
{"command": "cfg_osv", "PA": {"value": 0}}
{"command": "cfg_zsd", "PA": {"value": 5000}}
{"command": "cfg_zsp", "PA": {"value": 100}}
{"command": "cfg_dmd", "PA": {"value": 1}}
{"command": "cfg_dar", "PA": {"value": 30}}
{"command": "cfg_msr", "PA": {"value": 3}}
{"command": "cfg_msv", "PA": {"value": 0}}
{"command": "cfg_psr", "PA": {"value": 4}}
{"command": "cfg_psv", "PA": {"value": 1}}
//编码器配置命令
{"command": "cfg_pae", "PA": {"value": 1}}
{"command": "cfg_emod", "PA": {"value": 2}}
{"command": "cfg_elns", "PA": {"value": 1000}}
{"command": "cfg_estp", "PA": {"value": 200}}
{"command": "cfg_erty", "PA": {"value": 3}}
{"command": "cfg_edir", "PA": {"value": 0}}
{"command": "cfg_ez", "PA": {"value": 5}}
{"command": "cfg_ewr", "PA": {"value": 1}}
//S3-S6传感器触发事件配置命令
{"command": "cfg_s3f", "PA": {"value": 5}}
{"command": "cfg_s3r", "PA": {"value": 6}}
{"command": "cfg_s4f", "PA": {"value": 7}}
{"command": "cfg_s4r", "PA": {"value": 8}}
{"command": "cfg_s5f", "PA": {"value": 9}}
{"command": "cfg_s5r", "PA": {"value": 0}}
{"command": "cfg_s6f", "PA": {"value": 1}}
{"command": "cfg_s6r", "PA": {"value": 2}}
{"command": "cfg_s3", "PA": {"value": 1}}
{"command": "cfg_s4", "PA": {"value": 0}}
{"command": "cfg_s5", "PA": {"value": 1}}
{"command": "cfg_s6", "PA": {"value": 0}}
//S3-S6端口输出控制命令
{"command": "s3_on"}
{"command": "s3_off"}
{"command": "s4_on"}
{"command": "s4_off"}
{"command": "s5_on"}
{"command": "s5_off"}
{"command": "s6_on"}
{"command": "s6_off"}

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,10 @@
// 外部串口对象声明
extern HardwareSerial DebugSerial;
// 全局变量用于CID和RS485模式管理
static uint8_t currentTargetCID = 0; // 当前目标设备CID
static bool isCurrentRS485Mode = false; // 当前是否为RS485模式
void sendJsonResponse(const char* command, const char* status, int value) {
StaticJsonDocument<JSON_BUFFER_SIZE> responseDoc;
@ -63,218 +67,244 @@ void processJsonCommand(const char* jsonString) {
return;
}
// 解析命令中的CID
uint8_t cid = 0;
char actualCommand[64];
bool isRS485 = parse_command_with_cid(command, &cid, actualCommand);
// 设置全局变量供其他函数使用
currentTargetCID = cid;
isCurrentRS485Mode = isRS485;
if (isRS485) {
DebugSerial.print("RS485 Command - CID: ");
DebugSerial.print(cid);
DebugSerial.print(", Command: ");
DebugSerial.println(actualCommand);
} else {
DebugSerial.print("RS232 Command: ");
DebugSerial.println(actualCommand);
}
// 获取 PA 参数对象(可选)
JsonObject params = doc["PA"];
// 根据command执行相应操作
if (strcmp(command, "cfg") == 0) {
// 根据actualCommand执行相应操作
if (strcmp(actualCommand, "cfg") == 0) {
handle_cfg_cmd();
} else if (strcmp(command, "ena") == 0) {
} else if (strcmp(actualCommand, "ena") == 0) {
handle_ena_cmd();
} else if (strcmp(command, "off") == 0) {
} else if (strcmp(actualCommand, "off") == 0) {
handle_off_cmd();
} else if (strcmp(command, "mov") == 0) {
} else if (strcmp(actualCommand, "mov") == 0) {
handle_mov_cmd();
} else if (strcmp(command, "pos") == 0) {
} else if (strcmp(actualCommand, "pos") == 0) {
int value = params.containsKey("value") ? params["value"].as<int>() : 0;
handle_pos_cmd(value);
} else if (strcmp(command, "rmv") == 0) {
} else if (strcmp(actualCommand, "rmv") == 0) {
int value = params.containsKey("value") ? params["value"].as<int>() : 0;
handle_rmv_cmd(value);
} else if (strcmp(command, "pps") == 0) {
} else if (strcmp(actualCommand, "pps") == 0) {
if (params.containsKey("value")) {
int value = params["value"].as<int>();
handle_pps_cmd(value);
} else {
handle_pps_cmd();
}
} else if (strcmp(command, "org") == 0) {
} else if (strcmp(actualCommand, "org") == 0) {
handle_org_cmd();
} else if (strcmp(command, "stp") == 0) {
} else if (strcmp(actualCommand, "stp") == 0) {
if (params.containsKey("value")) {
int value = params["value"].as<int>();
handle_stp_cmd(value);
} else {
handle_stp_cmd(); // 无参数默认为0减速停止
}
} else if (strcmp(command, "dev") == 0) {
} else if (strcmp(actualCommand, "dev") == 0) {
handle_dev_cmd();
} else if (strcmp(command, "sts") == 0) {
} else if (strcmp(actualCommand, "sts") == 0) {
handle_sts_cmd();
} else if (strcmp(command, "zero_start") == 0) {
} else if (strcmp(actualCommand, "zero_start") == 0) {
handle_zero_start_cmd();
} else if (strcmp(command, "zero_stop") == 0) {
} else if (strcmp(actualCommand, "zero_stop") == 0) {
handle_zero_stop_cmd();
} else if (strcmp(command, "cfg_bdr") == 0) {
} else if (strcmp(actualCommand, "cfg_bdr") == 0) {
int baudrate = params["value"].as<int>();
handle_cfg_bdr_cmd(baudrate);
} else if (strcmp(command, "cfg_mcs") == 0) {
} else if (strcmp(actualCommand, "cfg_mcs") == 0) {
//设置微步细分
int mcs = params["value"].as<int>();
handle_cfg_mcs_cmd(mcs);
} else if (strcmp(command, "cfg_spd") == 0) {
} else if (strcmp(actualCommand, "cfg_spd") == 0) {
//设置运行速度
int spd = params["value"].as<int>();
handle_cfg_spd_cmd(spd);
} else if (strcmp(command, "cfg_acc") == 0) {
} else if (strcmp(actualCommand, "cfg_acc") == 0) {
//设置加速度
int acc = params["value"].as<int>();
handle_cfg_accSpeed_cmd(acc);
} else if (strcmp(command, "cfg_dec") == 0) {
} else if (strcmp(actualCommand, "cfg_dec") == 0) {
//设置减速度
int dec = params["value"].as<int>();
handle_cfg_decSpeed_cmd(dec);
} else if (strcmp(command, "cfg_cra") == 0) {
} else if (strcmp(actualCommand, "cfg_cra") == 0) {
//设置加速时电流
float cra = params["value"].as<float>();
handle_cfg_cra_cmd(cra);
} else if (strcmp(command, "cfg_crn") == 0) {
} else if (strcmp(actualCommand, "cfg_crn") == 0) {
//设置匀速时电流
float crn = params["value"].as<float>();
handle_cfg_crn_cmd(crn);
} else if (strcmp(command, "cfg_crh") == 0) {
} else if (strcmp(actualCommand, "cfg_crh") == 0) {
//设置HOLD电流
float crh = params["value"].as<float>();
handle_cfg_crh_cmd(crh);
// ***************************S3-S6传感器触发事件配置参数范围0-9**********************/
} else if (strcmp(command, "cfg_s3f") == 0) {
} else if (strcmp(actualCommand, "cfg_s3f") == 0) {
int s3f = params["value"].as<int>();
handle_cfg_sensor_cmd("s3f", s3f);
} else if (strcmp(command, "cfg_s3r") == 0) {
} else if (strcmp(actualCommand, "cfg_s3r") == 0) {
int s3r = params["value"].as<int>();
handle_cfg_sensor_cmd("s3r", s3r);
} else if (strcmp(command, "cfg_s4f") == 0) {
} else if (strcmp(actualCommand, "cfg_s4f") == 0) {
int s4f = params["value"].as<int>();
handle_cfg_sensor_cmd("s4f", s4f);
} else if (strcmp(command, "cfg_s4r") == 0) {
} else if (strcmp(actualCommand, "cfg_s4r") == 0) {
int s4r = params["value"].as<int>();
handle_cfg_sensor_cmd("s4r", s4r);
} else if (strcmp(command, "cfg_s5f") == 0) {
} else if (strcmp(actualCommand, "cfg_s5f") == 0) {
int s5f = params["value"].as<int>();
handle_cfg_sensor_cmd("s5f", s5f);
} else if (strcmp(command, "cfg_s5r") == 0) {
} else if (strcmp(actualCommand, "cfg_s5r") == 0) {
int s5r = params["value"].as<int>();
handle_cfg_sensor_cmd("s5r", s5r);
} else if (strcmp(command, "cfg_s6f") == 0) {
} else if (strcmp(actualCommand, "cfg_s6f") == 0) {
int s6f = params["value"].as<int>();
handle_cfg_sensor_cmd("s6f", s6f);
} else if (strcmp(command, "cfg_s6r") == 0) {
} else if (strcmp(actualCommand, "cfg_s6r") == 0) {
int s6r = params["value"].as<int>();
handle_cfg_sensor_cmd("s6r", s6r);
// ***************************S3-S6传感器工作模式配置参数范围0-1**********************/
} else if (strcmp(command, "cfg_s3") == 0) {
} else if (strcmp(actualCommand, "cfg_s3") == 0) {
int s3 = params["value"].as<int>();
handle_cfg_sensor_cmd("s3", s3);
} else if (strcmp(command, "cfg_s4") == 0) {
} else if (strcmp(actualCommand, "cfg_s4") == 0) {
int s4 = params["value"].as<int>();
handle_cfg_sensor_cmd("s4", s4);
} else if (strcmp(command, "cfg_s5") == 0) {
} else if (strcmp(actualCommand, "cfg_s5") == 0) {
int s5 = params["value"].as<int>();
handle_cfg_sensor_cmd("s5", s5);
} else if (strcmp(command, "cfg_s6") == 0) {
} else if (strcmp(actualCommand, "cfg_s6") == 0) {
int s6 = params["value"].as<int>();
handle_cfg_sensor_cmd("s6", s6);
//**************************************************************** */
} else if (strcmp(command, "cfg_zmd") == 0) {
} else if (strcmp(actualCommand, "cfg_zmd") == 0) {
//设置归零功能
int zmd = params["value"].as<int>();
handle_cfg_zmd_cmd(zmd);
} else if (strcmp(command, "cfg_snr") == 0) {
} else if (strcmp(actualCommand, "cfg_snr") == 0) {
//设置归零用传感器
int snr = params["value"].as<int>();
handle_cfg_snr_cmd(snr);
} else if (strcmp(command, "cfg_osv") == 0) {
} else if (strcmp(actualCommand, "cfg_osv") == 0) {
//设置归零传感器OPEN时电平
int osv = params["value"].as<int>();
handle_cfg_osv_cmd(osv);
} else if (strcmp(command, "cfg_zsd") == 0) {
} else if (strcmp(actualCommand, "cfg_zsd") == 0) {
//设置归零速度
int zsd = params["value"].as<int>();
handle_cfg_zsd_cmd(zsd);
} else if (strcmp(command, "cfg_zsp") == 0) {
} else if (strcmp(actualCommand, "cfg_zsp") == 0) {
//设置归零后的安全位置
int zsp = params["value"].as<int>();
handle_cfg_zsp_cmd(zsp);
} else if (strcmp(command, "cfg_dmd") == 0) {
} else if (strcmp(actualCommand, "cfg_dmd") == 0) {
//设置离线运行模式
int dmd = params["value"].as<int>();
handle_cfg_dmd_cmd(dmd);
} else if (strcmp(command, "cfg_dar") == 0) {
} else if (strcmp(actualCommand, "cfg_dar") == 0) {
//设置无握手启动时间
int dar = params["value"].as<int>();
handle_cfg_dar_cmd(dar);
} else if (strcmp(command, "cfg_msr") == 0) {
} else if (strcmp(actualCommand, "cfg_msr") == 0) {
//设置负极限传感器
int msr = params["value"].as<int>();
handle_cfg_msr_cmd(msr);
} else if (strcmp(command, "cfg_msv") == 0) {
} else if (strcmp(actualCommand, "cfg_msv") == 0) {
//设置负极限触发电平
int msv = params["value"].as<int>();
handle_cfg_msv_cmd(msv);
} else if (strcmp(command, "cfg_psr") == 0) {
} else if (strcmp(actualCommand, "cfg_psr") == 0) {
//设置正极限传感器
int psr = params["value"].as<int>();
handle_cfg_psr_cmd(psr);
} else if (strcmp(command, "cfg_psv") == 0) {
} else if (strcmp(actualCommand, "cfg_psv") == 0) {
//设置正极限触发电平
int psv = params["value"].as<int>();
handle_cfg_psv_cmd(psv);
} else if (strcmp(command, "cfg_pae") == 0) {
} else if (strcmp(actualCommand, "cfg_pae") == 0) {
//设置上电使能
int pae = params["value"].as<int>();
handle_cfg_pae_cmd(pae);
} else if (strcmp(command, "cfg_emod") == 0) {
} else if (strcmp(actualCommand, "cfg_emod") == 0) {
//设置编码器模式
int emod = params["value"].as<int>();
handle_cfg_emod_cmd(emod);
} else if (strcmp(command, "cfg_elns") == 0) {
} else if (strcmp(actualCommand, "cfg_elns") == 0) {
//设置编码器线数
int elns = params["value"].as<int>();
handle_cfg_elns_cmd(elns);
} else if (strcmp(command, "cfg_estp") == 0) {
} else if (strcmp(actualCommand, "cfg_estp") == 0) {
//设置电机每圈整步数
int estp = params["value"].as<int>();
handle_cfg_estp_cmd(estp);
} else if (strcmp(command, "cfg_erty") == 0) {
} else if (strcmp(actualCommand, "cfg_erty") == 0) {
//设置堵转后重试次数
int erty = params["value"].as<int>();
handle_cfg_erty_cmd(erty);
} else if (strcmp(command, "cfg_edir") == 0) {
} else if (strcmp(actualCommand, "cfg_edir") == 0) {
//设置编码器方向
int edir = params["value"].as<int>();
handle_cfg_edir_cmd(edir);
} else if (strcmp(command, "cfg_ez") == 0) {
} else if (strcmp(actualCommand, "cfg_ez") == 0) {
//设置编码器灵敏度
int ez = params["value"].as<int>();
handle_cfg_ez_cmd(ez);
} else if (strcmp(command, "cfg_ewr") == 0) {
} else if (strcmp(actualCommand, "cfg_ewr") == 0) {
//设置堵转后动作
int ewr = params["value"].as<int>();
handle_cfg_ewr_cmd(ewr);
} else if (strcmp(command, "sav") == 0) {
} else if (strcmp(actualCommand, "sav") == 0) {
handle_sav_cmd();
// ***************************S3-S6端口输出控制**********************/
} else if (strcmp(command, "s3_on") == 0) {
} else if (strcmp(actualCommand, "s3_on") == 0) {
handle_port_output_cmd("s3", "on");
} else if (strcmp(command, "s3_off") == 0) {
} else if (strcmp(actualCommand, "s3_off") == 0) {
handle_port_output_cmd("s3", "off");
} else if (strcmp(command, "s4_on") == 0) {
} else if (strcmp(actualCommand, "s4_on") == 0) {
handle_port_output_cmd("s4", "on");
} else if (strcmp(command, "s4_off") == 0) {
} else if (strcmp(actualCommand, "s4_off") == 0) {
handle_port_output_cmd("s4", "off");
} else if (strcmp(command, "s5_on") == 0) {
} else if (strcmp(actualCommand, "s5_on") == 0) {
handle_port_output_cmd("s5", "on");
} else if (strcmp(command, "s5_off") == 0) {
} else if (strcmp(actualCommand, "s5_off") == 0) {
handle_port_output_cmd("s5", "off");
} else if (strcmp(command, "s6_on") == 0) {
} else if (strcmp(actualCommand, "s6_on") == 0) {
handle_port_output_cmd("s6", "on");
} else if (strcmp(command, "s6_off") == 0) {
} else if (strcmp(actualCommand, "s6_off") == 0) {
handle_port_output_cmd("s6", "off");
//************************************************************* */
}
else {
sendJsonResponse(command, "UNKNOWN_COMMAND");
sendJsonResponse(actualCommand, "UNKNOWN_COMMAND");
}
// // 存储当前使用的CID供命令处理函数使用
// if (isRS485) {
// // 可以在这里设置全局变量或传递给处理函数
// DebugSerial.print("Command will be sent to device CID: ");
// DebugSerial.println(cid);
// }
}
void processStringCommand(const char* stringData) {
@ -283,7 +313,55 @@ void processStringCommand(const char* stringData) {
sendStringResponse(response.c_str());
}
// 解析包含CID的命令字符串
bool parse_command_with_cid(const char* command, uint8_t* cid, char* actualCommand) {
// 检查命令是否以数字开头CID
if (isdigit(command[0])) {
// 解析CID
char* endPtr;
long parsedCID = strtol(command, &endPtr, 10);
// 检查CID范围和格式
if (parsedCID >= 0 && parsedCID <= 32 && *endPtr == ' ') {
*cid = (uint8_t)parsedCID;
// 跳过CID和空格获取实际命令
strcpy(actualCommand, endPtr + 1);
return true; // RS485模式
}
}
// 没有CID前缀直接复制命令
*cid = 0; // 默认CID
strcpy(actualCommand, command);
return false; // RS232模式
}
// 带CID的命令发送函数
void send_vsmd_cmd_with_cid(uint8_t cid, const char* cmd, int value) {
// 发送CID前缀
Serial.print(cid);
Serial.print(" ");
// 发送命令
int len = strlen(cmd);
for (int i = 0; i < len; i++) {
Serial.print(cmd[i]);
}
// 如果有参数值,则添加参数
if (value != -1) {
Serial.print(" ");
Serial.print(value);
}
Serial.println();
delay(100);
}
void send_vsmd_cmd(const char* cmd, int value) {
if (isCurrentRS485Mode) {
send_vsmd_cmd_with_cid(currentTargetCID, cmd, value);
} else {
// 原有RS232模式
int len = strlen(cmd);
for (int i = 0; i < len; i++) {
Serial.print(cmd[i]);
@ -294,9 +372,9 @@ void send_vsmd_cmd(const char* cmd, int value) {
Serial.print(value);
}
Serial.println();
delay(100);
}
}
void printSerialRawData(const uint8_t* buffer, int bytesRead) {
// 打印Serial串口收到的原始数据

View File

@ -16,6 +16,9 @@ void send_vsmd_cmd(const char* cmd, int value = -1);
// send_vsmd_cmd("dev"); // 不带参数,使用默认值-1
// send_vsmd_cmd("pos", value); // 带参数
// RS485通信函数
void send_vsmd_cmd_with_cid(uint8_t cid, const char* cmd, int value = -1);
bool parse_command_with_cid(const char* command, uint8_t* cid, char* actualCommand);
// 打印Serial串口收到的原始数据
void printSerialRawData(const uint8_t* buffer, int bytesRead);
//VSMD串口数据解析

View File

@ -200,7 +200,7 @@ void initBluetooth() {
btAdvertising->setMinPreferred(0x0);
BLEDevice::startAdvertising();
DebugSerial.println("VSMD_Ble_Controller initialized");
DebugSerial.println("Ble Initialized");
// 初始化包接收状态
resetPacketReceiving();

View File

@ -6,6 +6,11 @@
VSMDParser parser;
#define USE_RS232 // 注释掉这行表示使用 RS-485取消注释表示使用 RS-232
//#define USE_RS485
#define PWR_232CTL 5 // 232电源控制引脚
#define PWR_485CTL 15 // 485电源控制引脚
#define DEBUG_TX_PIN 17 // TX
#define DEBUG_RX_PIN 16 // RX
#define BUFFER_SIZE 1024
@ -29,27 +34,48 @@ int32_t pulsePerSecond;
void printDeviceStatus();
void handleSerialData();
bool Dev_Mode = false;
void printDeviceStatus() {
DebugSerial.println("\n=== Device Status ===");
DebugSerial.print("Enabled: ");
DebugSerial.print("Device Enabled: ");
DebugSerial.println(deviceEnabled ? "Yes" : "No");
DebugSerial.print("Bluetooth: ");
DebugSerial.println(isBluetoothConnected() ? "Connected" : "Disconnected");
DebugSerial.println("==================\n");
DebugSerial.print("Ble Connected: ");
DebugSerial.println(isBluetoothConnected() ? "Yes" : "No");
DebugSerial.print("Dev Mode: ");
DebugSerial.println(Dev_Mode ? "RS232" : "RS485");
}
void Power_Enable()
{
pinMode(PWR_232CTL, OUTPUT);
pinMode(PWR_485CTL, OUTPUT);
#ifdef USE_RS232
digitalWrite(PWR_232CTL, HIGH);
digitalWrite(PWR_485CTL, LOW);
Dev_Mode = true;
#elif defined(USE_RS485)
digitalWrite(PWR_485CTL, HIGH);
digitalWrite(PWR_232CTL, LOW);
Dev_Mode = false;
#endif
}
void setup() {
// 调试串口
DebugSerial.begin(9600, SERIAL_8N1, DEBUG_RX_PIN, DEBUG_TX_PIN);
DebugSerial.setTimeout(1);
DebugSerial.setTimeout(100);
// 电机数据通信串口
Serial.begin(9600);
Serial.setTimeout(100);
DebugSerial.println("VSMD INIT");
DebugSerial.println("CMD: dev, sts, cfg, ena, off, mov, pos, rmv, pps, org, stp, zero, sav");
DebugSerial.println("cfg CMD: bdr, mcs, spd, acc, dec, cra, crn, crh, s1f, s1r, s2f, s2r, zmd, snr, osv, zsd, zsp, dmd, dar, msr, msv, psr, psv");
// DebugSerial.println("VSMD INIT");
// DebugSerial.println("CMD: dev, sts, cfg, ena, off, mov, pos, rmv, pps, org, stp, zero, sav");
// DebugSerial.println("cfg CMD: bdr, mcs, spd, acc, dec, cra, crn, crh, s1f, s1r, s2f, s2r, zmd, snr, osv, zsd, zsp, dmd, dar, msr, msv, psr, psv");
//初始化电源控制引脚
Power_Enable();
// 初始化蓝牙
initBluetooth();

View File

@ -1,23 +0,0 @@
{
"limit": {
"cfg msr": 1, //设置负极限传感器
"cfg msv": 0, //设置负极限触发电平
"cfg psr": 2, //设置正极限传感器
"cfg psv": 0 //设置正极限触发电平
},
"other": {
"cfg acc": 20000, //设置加速度
"cfg cra": 4, //设置加速时电流
"cfg crh": 1, //设置HOLD电流
"cfg crn": 4, //设置匀速时电流
"cfg dec": 20000, //设置减速度
"cfg mcs": 7 //设置微步细分
},
"zero start": {
"cfg osv": 0, //设置归零传感器OPEN时电平
"cfg snr": 0, //设置归零用传感器
"cfg zmd": 2, //设置归零功能
"cfg zsd": 3000, //设置归零速度(正负代表方向)
"cfg zsp": 2400 //设置归零后的安全位置
}
}

287
vsmd_IRIS.txt Normal file
View File

@ -0,0 +1,287 @@
***********RS485模式下的JSON命令*********
JSON: {"command": "1 dev"}
HEX: 55 AA 00 00 13 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 31 20 64 65 76 22 7D EE EE
****************************************
// 使能设备
JSON: {"command": "ena"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 65 6E 61 22 7D EE EE
// 关闭设备
JSON: {"command": "off"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 6F 66 66 22 7D EE EE
// 开始运行
JSON: {"command": "mov"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 6D 6F 76 22 7D EE EE
// 停止运行(减速停止)
JSON: {"command": "stp", "value": 0}
HEX: 55 AA 00 00 1B 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 74 70 22 2C 22 76 61 6C 75 65 22 3A 30 7D EE EE
// 停止运行(立即停止)
JSON: {"command": "stp", "value": 1}
HEX: 55 AA 00 00 1B 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 74 70 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 绝对位置移动
JSON: {"command": "pos", "value": 1000}
HEX: 55 AA 00 00 1E 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 70 6F 73 22 2C 22 76 61 6C 75 65 22 3A 31 30 30 30 7D EE EE
// 相对位置移动
JSON: {"command": "rmv", "value": 500}
HEX: 55 AA 00 00 1D 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 72 6D 76 22 2C 22 76 61 6C 75 65 22 3A 35 30 30 7D EE EE
// 脉冲频率设置
JSON: {"command": "pps", "value": 2000}
HEX: 55 AA 00 00 1E 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 70 70 73 22 2C 22 76 61 6C 75 65 22 3A 32 30 30 30 7D EE EE
// 查询脉冲频率
JSON: {"command": "pps"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 70 70 73 22 7D EE EE
// 原点归零
JSON: {"command": "org"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 6F 72 67 22 7D EE EE
// 开始归零
JSON: {"command": "zero_start"}
HEX: 55 AA 00 00 18 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 7A 65 72 6F 5F 73 74 61 72 74 22 7D EE EE
// 停止归零
JSON: {"command": "zero_stop"}
HEX: 55 AA 00 00 17 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 7A 65 72 6F 5F 73 74 6F 70 22 7D EE EE
// 设备信息查询
JSON: {"command": "dev"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 64 65 76 22 7D EE EE
// 状态查询
JSON: {"command": "sts"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 74 73 22 7D EE EE
// 配置查询
JSON: {"command": "cfg"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 22 7D EE EE
// 波特率配置
JSON: {"command": "cfg_bdr", "value": 9600}
HEX: 55 AA 00 00 22 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 62 64 72 22 2C 22 76 61 6C 75 65 22 3A 39 36 30 30 7D EE EE
// 微步细分配置
JSON: {"command": "cfg_mcs", "value": 8}
HEX: 55 AA 00 00 1F 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 6D 63 73 22 2C 22 76 61 6C 75 65 22 3A 38 7D EE EE
// 运行速度配置
JSON: {"command": "cfg_spd", "value": 1000}
HEX: 55 AA 00 00 22 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 70 64 22 2C 22 76 61 6C 75 65 22 3A 31 30 30 30 7D EE EE
// 加速度配置
JSON: {"command": "cfg_acc", "value": 500}
HEX: 55 AA 00 00 21 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 61 63 63 22 2C 22 76 61 6C 75 65 22 3A 35 30 30 7D EE EE
// 减速度配置
JSON: {"command": "cfg_dec", "value": 500}
HEX: 55 AA 00 00 21 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 64 65 63 22 2C 22 76 61 6C 75 65 22 3A 35 30 30 7D EE EE
// 加速电流配置
JSON: {"command": "cfg_cra", "value": 80}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 63 72 61 22 2C 22 76 61 6C 75 65 22 3A 38 30 7D EE EE
// 匀速电流配置
JSON: {"command": "cfg_crn", "value": 60}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 63 72 6E 22 2C 22 76 61 6C 75 65 22 3A 36 30 7D EE EE
// HOLD电流配置
JSON: {"command": "cfg_crh", "value": 40}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 63 72 68 22 2C 22 76 61 6C 75 65 22 3A 34 30 7D EE EE
// 传感器S3触发事件配置
JSON: {"command": "cfg_s3f", "value": 1}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 33 66 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 传感器S4触发事件配置
JSON: {"command": "cfg_s4f", "value": 2}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 34 66 22 2C 22 76 61 6C 75 65 22 3A 32 7D EE EE
// 传感器S5触发事件配置
JSON: {"command": "cfg_s5f", "value": 3}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 35 66 22 2C 22 76 61 6C 75 65 22 3A 33 7D EE EE
// 传感器S6触发事件配置
JSON: {"command": "cfg_s6f", "value": 4}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 36 66 22 2C 22 76 61 6C 75 65 22 3A 34 7D EE EE
// 传感器S3工作模式配置
JSON: {"command": "cfg_s3", "value": 1}
HEX: 55 AA 00 00 1F 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 33 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 传感器S4工作模式配置
JSON: {"command": "cfg_s4", "value": 0}
HEX: 55 AA 00 00 1F 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 34 22 2C 22 76 61 6C 75 65 22 3A 30 7D EE EE
// 传感器S5工作模式配置
JSON: {"command": "cfg_s5", "value": 1}
HEX: 55 AA 00 00 1F 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 35 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 传感器S6工作模式配置
JSON: {"command": "cfg_s6", "value": 0}
HEX: 55 AA 00 00 1F 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 36 22 2C 22 76 61 6C 75 65 22 3A 30 7D EE EE
// S3端口输出开启
JSON: {"command": "s3_on"}
HEX: 55 AA 00 00 13 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 33 5F 6F 6E 22 7D EE EE
// S3端口输出关闭
JSON: {"command": "s3_off"}
HEX: 55 AA 00 00 14 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 33 5F 6F 66 66 22 7D EE EE
// S4端口输出开启
JSON: {"command": "s4_on"}
HEX: 55 AA 00 00 13 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 34 5F 6F 6E 22 7D EE EE
// S4端口输出关闭
JSON: {"command": "s4_off"}
HEX: 55 AA 00 00 14 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 34 5F 6F 66 66 22 7D EE EE
// S5端口输出开启
JSON: {"command": "s5_on"}
HEX: 55 AA 00 00 13 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 35 5F 6F 6E 22 7D EE EE
// S5端口输出关闭
JSON: {"command": "s5_off"}
HEX: 55 AA 00 00 14 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 35 5F 6F 66 66 22 7D EE EE
// S6端口输出开启
JSON: {"command": "s6_on"}
HEX: 55 AA 00 00 13 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 36 5F 6F 6E 22 7D EE EE
// S6端口输出关闭
JSON: {"command": "s6_off"}
HEX: 55 AA 00 00 14 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 36 5F 6F 66 66 22 7D EE EE
// 归零功能配置
JSON: {"command": "cfg_zmd", "value": 1}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 7A 6D 64 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 归零用传感器配置
JSON: {"command": "cfg_snr", "value": 3}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 73 6E 72 22 2C 22 76 61 6C 75 65 22 3A 33 7D EE EE
// 归零传感器OPEN时电平配置
JSON: {"command": "cfg_osv", "value": 0}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 6F 73 76 22 2C 22 76 61 6C 75 65 22 3A 30 7D EE EE
// 归零速度配置
JSON: {"command": "cfg_zsd", "value": 200}
HEX: 55 AA 00 00 21 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 7A 73 64 22 2C 22 76 61 6C 75 65 22 3A 32 30 30 7D EE EE
// 归零后安全位置配置
JSON: {"command": "cfg_zsp", "value": 100}
HEX: 55 AA 00 00 21 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 7A 73 70 22 2C 22 76 61 6C 75 65 22 3A 31 30 30 7D EE EE
// 离线运行模式配置
JSON: {"command": "cfg_dmd", "value": 1}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 64 6D 64 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 无握手启动时间配置
JSON: {"command": "cfg_dar", "value": 1000}
HEX: 55 AA 00 00 22 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 64 61 72 22 2C 22 76 61 6C 75 65 22 3A 31 30 30 30 7D EE EE
// 负极限传感器配置
JSON: {"command": "cfg_msr", "value": 3}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 6D 73 72 22 2C 22 76 61 6C 75 65 22 3A 33 7D EE EE
// 负极限触发电平配置
JSON: {"command": "cfg_msv", "value": 0}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 6D 73 76 22 2C 22 76 61 6C 75 65 22 3A 30 7D EE EE
// 正极限传感器配置
JSON: {"command": "cfg_psr", "value": 4}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 70 73 72 22 2C 22 76 61 6C 75 65 22 3A 34 7D EE EE
// 正极限触发电平配置
JSON: {"command": "cfg_psv", "value": 1}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 70 73 76 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 上电使能配置
JSON: {"command": "cfg_pae", "value": 1}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 70 61 65 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 编码器模式配置
JSON: {"command": "cfg_emod", "value": 1}
HEX: 55 AA 00 00 21 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 65 6D 6F 64 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 编码器线数配置
JSON: {"command": "cfg_elns", "value": 1000}
HEX: 55 AA 00 00 22 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 65 6C 6E 73 22 2C 22 76 61 6C 75 65 22 3A 31 30 30 30 7D EE EE
// 电机每圈整步数配置
JSON: {"command": "cfg_estp", "value": 200}
HEX: 55 AA 00 00 22 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 65 73 74 70 22 2C 22 76 61 6C 75 65 22 3A 32 30 30 7D EE EE
// 堵转后重试次数配置
JSON: {"command": "cfg_erty", "value": 3}
HEX: 55 AA 00 00 21 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 65 72 74 79 22 2C 22 76 61 6C 75 65 22 3A 33 7D EE EE
// 编码器方向配置
JSON: {"command": "cfg_edir", "value": 0}
HEX: 55 AA 00 00 21 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 65 64 69 72 22 2C 22 76 61 6C 75 65 22 3A 30 7D EE EE
// 编码器灵敏度配置
JSON: {"command": "cfg_ez", "value": 5}
HEX: 55 AA 00 00 1F 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 65 7A 22 2C 22 76 61 6C 75 65 22 3A 35 7D EE EE
// 堵转后动作配置
JSON: {"command": "cfg_ewr", "value": 1}
HEX: 55 AA 00 00 20 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 63 66 67 5F 65 77 72 22 2C 22 76 61 6C 75 65 22 3A 31 7D EE EE
// 保存配置
JSON: {"command": "sav"}
HEX: 55 AA 00 00 11 7B 22 63 6F 6D 6D 61 6E 64 22 3A 22 73 61 76 22 7D EE EE