Hi guys,
I have written this code that communicates with an inverter and sends a command to the inverter to get parameters. The command itself is constructed using commandkeyword+Data(yyyymmdd)+CRC+CR. The command is built every time the day changes and then this command is sent every minute to the inverter to get the updated parameter value. my problem is with this bit of code:
if (strcmp(cmdCode, "^D011") == 0)
{
strncpy(EDData, &receivedChars[5], 8);
EDData[8] = '\0';
dailySolar = atoi(EDData);
Serial.print("Current Energy/ day = ");
Serial.println(dailySolar);
}
if this portion of the code executes, it clears the command during the first pass through this routine. If this code doesn't get executed, the command just keeps on going until the day changes and then a new command is built using the new date and it continues for the next day. These lines of code have nothing to do with the variable in which the command is stored. yet somehow it clears the variable. The command is built using the following code:
if (day != prevDay)
{
prevDay = day;
Serial.println("just before memset");
memset(command, 0, sizeof(command));
Serial.println("Cmd build routine");
strftime(date, 9, "%Y%m%d",timeinfo);
strcat(command, ED);
strcat(command, date);
CRCC = crcFast(command, strlen(command));
Serial.println(CRCC, HEX);
CRC[0] = (CRCC >> 8) & 0xFF;
if (CRC[0] == 0x28 || CRC[0] == 0x0D || CRC[0] == 0x0A)
{
CRC[0]++;
}
CRC[1] = CRCC & 0xFF;
if (CRC[1] == 0x28 || CRC[1] == 0x0D || CRC[1] == 0x0A)
{
CRC[1]++;
}
CRC[2] = 0x0D;
CRC[3] = 0x00;
Serial.println(CRC);
strcat(command, CRC);
Serial.println(command);
}
if (min != prevMin)
{
Serial.println("min Change");
sendInverterCmd(command);
prevMin = min;
}
i have tried replacing the code with a Serial.print and it executes every time without any problem.
I cant seem to find anything wrong with this code (limited knowledge).
I would appreciate it if anyone can point me in the right direction.
Thanks.
Usman....