I've always had a problem with the concept of char pointers, strings, Strings and most things pointer related. Maybe I'm too old for this ;-)
declared globally:
char * message;
the serialOut
is a very short 8 character string, an identifier (X10D
) and then the data (nnn
), and null terminator. I am finding the data sent via serial to be trimmed at the front, missing the idetifier. On the first pass through, it would be full and correct, but on subsequent pass through, only the three digits were received.
message
is a debug message which outputs to the screen for debugging.
device
and onOff
populate correctly.
function causing problems:
byte device = btag-X10_TAG_OFFSET;
byte onOff;
char serialOut[8];
memset (serialOut, 0, 8);
if(x10[device - 1]==1){
onOff = 0;
} else {
onOff = 1;
}
x10[device-1]=-2;
sprintf(serialOut, "X10D%02i%i", device, onOff);
Serial.println(serialOut);
strcpy(message, serialOut); // this line appears to 'modify' the previous line
if I remove the last line and swap it with:
message = serialOut;
the preceeding Serial communications is complete!
If I have neither, then the data at the other end is garbage (not yet deciphered, but appear as unprintable characters—which is why I setup the debug).
I'm thinking this can't be related, but the equality seems to 'fix' the problem.