I am using (1)Azure Sphere MT3620 Starter Kit and (2)RS485 CLICK 5V and (3)Geovan Board
Here is the setup (I don't have latest picture, so #2 is swapped to first slot in the MT3620)
My MT3620 is registered all good with Azure IoTHub and pushing all telemetry data to cloud. Now I am trying to sent some HEX commands from MT3620 to Geovan Board via RS485 CLICK 5V
Here is my Calling code
//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
when data is passed to SendUartMessage
both arrays (updateAllChannelData
and readAllChannel
) breaks at 0x00
so final command being passed to Geovan Board is incomplete and no response is received.
Here is SendUartMessage method
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);
}
FYI: I have tested these commands as below
- Connect Geovan directly to PC
- using Hercules SETUP utility open com port on which Geovan is connected
- send HEX command "
0x01, 0x06, 0x00, 0x19, 0x00, 0x01, 0x99, 0xCD
" wait 10 seconds - send HEX command "
0x01, 0x03, 0x00, 0x01, 0x00, 0x10, 0x15, 0xC6
" wait 10 seconds - received expected response
This confirms from Geovan these commands as sent and responded correctly. So the challenge is sending same commands from MT3620 through RS485 CLICK 5V to Geovan Board.
Can someone point out the what am I missing over here?
Update: Before stepping in to function, this is how my array looks
After stepping in to the function, this is what it looks like