Hello , I'm new in Arduino.
I have some medical devices that send and receive data using RS232 (DB9) serial port communication to and from the computer. Some other devices send and receive data between each other. However , some devices from different manufacturers need some formatting modification for data before being received from other devices. I used to do this through the computer to receive data from device 1 then modify formatting then resend to device 2 and this did the job, but this requires one computer between 2 devices. I'm asking if Arduino is able to do the job by connecting to 2 devices at the same time using serial port (DB9) so it can receive data from first device and resend it to another device after little modification in formatting using code. I know it is not straightforward but if it is possible even in a hard way , i would appreciate if somebody guided me how to do that. Thank you
Yes, it can be done.
I would buy the Arduino Mega since it has 4 serial ports.
You will also need serial to RS232 voltage converter boards such as SparkFun RS232 Shifter - SMD - PRT-00449 - SparkFun Electronics
Use this example... I have just written this without making sure it works... but you get the idea.
/*
Created example for Arduino forums. May 2, 2020
Auther: Edgar Wideman
This software is an example only, not intended for use. Debugging is the end users job.
*/
String Data = ""; // Use a String or a char array for your data storage.
void setup() {
Serial.begin(9600); // Start serial port A
Serial1.begin(9600);// Start serial port B
}
void loop() {
while (Serial.available() > 0) { // Collect data from Serial port A
char a = Serial.read();
Data += a;
delay(5); // delay for stability.
}
if(Data > "0"){ // Do this only if there is data in the String.
//Do a little modification in formatting using code.
Serial1.print(Data); // Sent out the data on Serial B
Data = ""; // empty the String in prep for next incoming data streem.
}
}
Thanks a lot.
I would avoid using the String class with Arduino boards, especially the 8 bit ones. Here is why.