我正在使用(1) Azure Sphere MT3620 Starter Kit和(2) RS485 CLICK 5V和(3) Geovan Board
这是设置(我没有最新的图片,所以#2 被交换到 MT3620 的第一个插槽)
我的MT3620已在 Azure IoTHub 中很好地注册,并将所有遥测数据推送到云端。现在我正在尝试通过RS485 CLICK 5V从MT3620向Geovan Board发送一些 HEX 命令
这是我的呼叫代码
//RS485 to Geovan to Update Registry values
unsigned char updateAllChannelData[] = { 0x01, 0x06, 0x00, 0x19, 0x00, 0x01, 0x99, 0xCD };
SendUartMessage(uartFd, updateAllChannelData, sizeof(updateAllChannelData));
delay(10);
//RS485 to Geovan to Read all channels
unsigned char readAllChannel[] = { 0x01, 0x03, 0x00, 0x01, 0x00, 0x10, 0x15, 0xC6 };
SendUartMessage(uartFd, readAllChannel, sizeof(readAllChannel));
delay(1.5); //20
当数据传递到SendUartMessage
两个数组 (updateAllChannelData
和readAllChannel
) 时会中断,因此传递给Geovan Board0x00
的最终命令是不完整的,并且没有收到任何响应。
这是SendUartMessage方法
static void SendUartMessage(int uartFd, const char* dataToSend, size_t totalBytesToSend)
{
// dataToSend breaks at 0x00 right here not after executing any lines below
// First command array becomes {0x01, 0x06}
// Second command array becomes {0x01, 0x03}
size_t totalBytesSent = 0;
int sendIterations = 0;
close(r1PinFd);
r1PinFd = GPIO_OpenAsOutput(MIKROE_PWM, GPIO_OutputMode_PushPull, GPIO_Value_High);
while (totalBytesSent < totalBytesToSend) {
sendIterations++;
// Send as much of the remaining data as possible
size_t bytesLeftToSend = totalBytesToSend - totalBytesSent;
const char* remainingMessageToSend = dataToSend + totalBytesSent;
ssize_t bytesSent = write(uartFd, remainingMessageToSend, bytesLeftToSend);
if (bytesSent == -1) {
Log_Debug("ERROR: Could not write to UART: %s (%d).\n", strerror(errno), errno);
exitCode = ExitCode_SendMessage_Write;
return;
}
totalBytesSent += (size_t)bytesSent;
}
int c, d;
sleep(5);
close(r1PinFd);
r1PinFd = GPIO_OpenAsOutput(MIKROE_PWM, GPIO_OutputMode_PushPull, GPIO_Value_Low);
Log_Debug("Sent %zu bytes over UART in %d calls.\n", totalBytesSent, sendIterations);
}
仅供参考:我已经测试了这些命令如下
- 将 Geovan 直接连接到 PC
- 使用Hercules SETUP 实用程序打开连接 Geovan 的 com 端口
- 发送 HEX 命令“
0x01, 0x06, 0x00, 0x19, 0x00, 0x01, 0x99, 0xCD
”等待 10 秒 - 发送 HEX 命令“
0x01, 0x03, 0x00, 0x01, 0x00, 0x10, 0x15, 0xC6
”等待 10 秒 - 收到预期的回应
这从 Geovan 确认了这些命令已正确发送和响应。因此,挑战是通过RS485 CLICK 5V从MT3620向Geovan Board发送相同的命令。
有人能指出我在这里错过了什么吗?