I am building an access control project which uses two SoftwareSerial ports. One will be used for communication with an RFID reader and another one to receive serial messages via an Xbee (e.g. remote commands). The hardware serial port is used for a cabled serial connection to another remote "server"-Arduino, which then actuates the relays.
According to the Arduino website, the SoftwareSerial Library has, amongst others, the following limitation: - "If using multiple software serial ports, only one can receive data at a time."
My plan is to poll constantly / on regular intervals both SoftwareSerial ports, e.g. by checking RFID_Serial.available() and XBeeSerial.available(), and if it turns out that data is available, to read it out and parse it accordingly. This obviouosly has to be done in an alternating fashion, i.e. one after the other. My questions are the following.
(1) Can I initialise the ports in void setup()
RFID_Serial.begin(..); XBeeSerial.begin(..);
... and are they then both actually active simultaneously (i.e. ready for commans like xxxxSerial.available(), or xxxxSerial.read(), or is in this case only the XBeeSerial active, because I it was the last one to be initialised?
(2) If I want to poll one after the other, do I have to "close" one SoftwareSerial port, e.g. by RFID_Serial.end(); and open the other (XbeeSerial.begin(..)) before I can do XBeeSerial.available() or read out by XBeeSerial.read()?
- Take a gamble. Hope they won't occure on the same time (bad idea)
- Manage the flow. Make the other device not send data while one is sending. (Maybe impossible)
- Check the priorities, make the XBee's priority vector lower as the RFID, and when you do not get a full/known RFID key, give feedback (with a light/buzzer) so the person will try his RFID key again.
– aaa Apr 09 '15 at 14:26