I have an Arduino that I've put between a computer and an RS485 device. The job of the Arduino now is just to transmit data but will eventually do data logging and have a small user interface as time goes by.
So far, this serial read code has worked for me to communicate to the Arduino from the computer:
void serialEvent()
{
while(Serial.available())
{
// get new byte
char inChar = (char)Serial.read();
if (inChar == '\n')
{
stringComplete = true;
}
else
{
inputstring += inChar;
}
}
}
The downside here is that I cannot send the '\n' char to my RS485 unit. Is there a way I can refine the code so I can send an arbitrary string of chars while still having a termination [thing] to turn on the stringComplete flag?
EDIT To clarify this the process by how my message string is being created:
Input: U16 Address, U16 Data, U8 Function Code
U16 Address -> U8 Address Split High, U8 Address Split Low
U16 Data -> U8 Data Split High, U8 Data Split Low
U8 Array of [U8 Address Split High, U8 Address Split Low, U8 Data Split High, U8 Data Split Low, U8 Function Code]
U8 Array -> Message String
Output: Write Message String
\n
) that you want to send? – Majenko♦ May 5 '17 at 14:08\024\075\216\030\777\000\123
etc? – Majenko♦ May 5 '17 at 15:46