Преглед изворни кода

修改PSG—HD发送命令时的命令构造函数!

lwk пре 2 недеља
родитељ
комит
4e5f4a68ee

+ 15 - 8
Generator/PSG/CCOS.Dev.Generator.PSG_HD/CCOS.Dev.Generator.PSG_HD.cpp

@@ -693,26 +693,33 @@ RET_STATUS nsGEN::PSGHDDevice::HWSend(const char* strCommand, int length, bool r
 		FINFO("Failed - Device not connected");
 		return RET_STATUS::RET_FAILED;
 	}
-	// 构造新协议格式:<Command><Data><ETX><Checksum>
+	// 构造协议格式:<STX>CMD<SP>ARG;<CS><CR><LF>
 	char strSendCommand[100] = { 0 };
 	int len = 0;
+	strSendCommand[len++] = 0x02; // STX
 
 	// 复制命令部分
 	memcpy(strSendCommand + len, strCommand, length);
 	len += length;
 
-	// 添加ETX结束符(0x03)
-	strSendCommand[len++] = 0x03;
+	// 添加分号
+	strSendCommand[len++] = ';';
 
-	// 计算校验和:Command + Data + ETX的累加和取低位
-	uint8_t checksum = 0;
-	for (int i = 0; i < len; i++) {  // 从首字节到ETX全部参与计算
-		checksum += (uint8_t)strSendCommand[i];
+	// 计算校验和(从STX后开始到分号';')
+	uint16_t sum = 0;
+	for (int i = 1; i < len; i++)
+	{
+		sum += (uint8_t)strSendCommand[i];
 	}
-	checksum &= 0xFF;  // 取累加和的低8位
+	uint8_t checksum = (uint8_t)(sum & 0xFF);
+	checksum = 0x100 - checksum;
+	checksum &= 0x7F;
+	checksum |= 0x40;
 
 	// 添加校验和
 	strSendCommand[len++] = checksum;
+	strSendCommand[len++] = 0x0D; // CR
+	strSendCommand[len++] = 0x0A; // LF
 
 
 	// 打印数据包前16字节的十六进制(含控制字符)便于调试

+ 1 - 1
Generator/PSG/CCOS.Dev.Generator.PSG_HD/CCOS.Dev.Generator.PSG_HD.h

@@ -260,7 +260,7 @@ namespace CCOS::Dev::Detail::Generator
 		const std::chrono::seconds RETRY_INTERVAL{ 5 };
 
 		// 串口相关(固定支持的端口,可从配置扩展)
-		std::vector<std::string> m_serialPorts{ "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB3", "/dev/ttyUSB4" };
+		std::vector<std::string> m_serialPorts{ "/dev/ttyUSB0", "/dev/ttyUSB1", "/dev/ttyUSB2", "/dev/ttyUSB3", "/dev/ttyUSB4" };
 		int m_currentSerialPortIndex{ 0 };  // 当前尝试的串口端口索引
 		ConnectionType m_currentConnType{ ConnectionType::Serial };