void loop()
{
send_message(Serial3);
// put your main code here, to run it over and over:
{
if (strncmp(message, "1", 1) == 0)
{
send_message(Serial1);
}
else if (strncmp(message, "2", 1) == 0)
{
send_message(Serial2);
} } }
Apart from these conditions, I want to send all the data in Serial to Serial 3 without any rules.
I couldn't do it. const char START_CHAR = '\x02';
const char END_CHAR = '\x0A';
const int BUF_SIZE = 32;
char message[BUF_SIZE];
void receive_message(HardwareSerial &serial)
{
int rx_index = 0;
char rx_char = '\0';
while (rx_char != START_CHAR)
{
while (!serial.available()) {}
rx_char = serial.read();
}
// skip STX
while (!serial.available()) {}
rx_char = serial.read();
// read until END_CHAR
while (rx_char != END_CHAR)
{
if (rx_char != END_CHAR)
{
if (rx_index < BUF_SIZE - 1)
{
message[rx_index] = rx_char;
rx_index++;
}
}
while (!serial.available()) {}
rx_char = serial.read();
}
message[rx_index] = '\0';
}
void send_message(HardwareSerial &tx_serial)
{
tx_serial.write (START_CHAR);
for (int index = 2; index < strlen(message); index++)
{
tx_serial.write (message[index]);
}
tx_serial.write (END_CHAR);
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
Serial3.begin(9600);
Serial1.begin(2400);
Serial2.begin(2400);
}
void loop()
{
send_message(Serial3);
// put your main code here, to run repeatedly:
{
if (strncmp(message, "1", 1) == 0)
{
send_message(Serial1);
}
else if (strncmp(message, "2", 1) == 0)
{
send_message(Serial2);
} } }
``