STUDENT STUDENT
Sending this line to serial-1.
other 4TEACHER-3
I am trying to send the line to serial-2.
No matter what I tried, it didn't work. When I sent these characters to ext String to Hex Code Converter x
I think the value is space, hex value is 20.
If I send it to serial -2, the value of 4 at the end is 34 in hex.
add it to the code
void loop()
{
// put your main code here, to run repeatedly:
receive_message(Serial);
if (strncmp(message, "20", 2) == 0) {
send_message(Serial1); }
else if (strncmp(message, "34", 2) == 0) {
send_message(Serial2); }}
it doesn't work at all`const char START_CHAR = '\x0F';
const char END_CHAR = '\x03';
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 = 0; 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);
Serial1.begin(9600);
Serial2.begin(9600);}
void loop(){
// put your main code here, to run repeatedly:
receive_message(Serial);
if (strncmp(message, "20", 2) == 0){
send_message(Serial1); }
else if (strncmp(message, "34", 2) == 0) {
send_message(Serial2); }}
`

