0

I am working on a project that requires reading from six ID-12LA RFID readers simultaneously.

I’ve tried setting up readings from six channels through the Sparkfun Analog/Digital MUX Breakout board (CD74HC4067), but without luck. I don’t know if it is capable of serial communication, even though I read that on Bildr.org.

However, I am now trying to emulate reading from multiple serial ports through the SoftwareSerial library. I have read that it is not capable of reading simultaneously, but maybe a loop can simulate simultaneous listening. I have tried to do so by listening to the the first serial, then initializing readTag(), and then after that function has finished, begin listening to the second serial and then initialize the second function.

The readTag() function is capable of reading on its own, when only on RFID reader is connected, so that is not the problem.

Below is the code.

What would be the correct way to go about and simulate simultaneous reading through the loop function?

void setup() {
  Serial.begin(9600);
  ourSerial1.begin(9600);
  ourSerial2.begin(9600);

  pinMode(RFIDResetPin, OUTPUT);
  digitalWrite(RFIDResetPin, HIGH);
}

void loop() {

  ourSerial1.listen();
  readTag1();
  ourSerial2.listen(); 
  readTag2(); // Only this function works right now, because it is the last serial that was initiated in setup.

}

void readTag1() {

  char tagString[13];
  int index = 0;
  boolean reading = false;

  while (ourSerial1.available()) {

    int readByte = ourSerial1.read();

    if (readByte == 2) reading = true; // Beginning of tag
    if (readByte == 3) reading = false; // End of tag

    if (reading && readByte != 2 && readByte != 10 && readByte != 13) {
      //store the tag
      tagString[index] = readByte;
      index ++;
    }
  }

  checkTag(tagString); // Check if it is a match
  clearTag(tagString); // Clear the char of all value
  resetReader(); // Reset the RFID reader
}

void readTag2() {

  char tagString[13];
  int index = 0;
  boolean reading = false;

  while (ourSerial2.available()) {

    int readByte = ourSerial2.read();

    if (readByte == 2) reading = true; // Beginning of tag
    if (readByte == 3) reading = false; // End of tag

    if (reading && readByte != 2 && readByte != 10 && readByte != 13) {
      //store the tag
      tagString[index] = readByte;
      index ++;
    }
  }

  checkTag2(tagString); // Check if it is a match
  clearTag(tagString); // Clear the char of all value
  resetReader(); // Reset the RFID reader
}
gre_gor
  • 6,669
  • 9
  • 47
  • 52

1 Answers1

0

Am I correct that you just want to mock/mimic communication from RFID? You want to have simultaneous reads to 2-6 serial RFID readers?

What you should do is not use the ourSerial1.listen(); routine. This can indeed not listen on 2 ports at the same time. Make your own subroutines, that poll the individual ports (if needed, switch your MUX inbetween):

  • create a for loop that checks xx times (depending your setup, during 100ms?)

    for (int i = 0, i < 1000, i++) //first part of loop
    {
        if (Serial.available())
        {
          // do your decoding of port 1 here
        } 
    }
    for (int i = 0, i < 1000, i++) //second part of loop
    {
        if (Serial1.available()) //other port
        {
          // do your decoding of port 1 here
        } 
    }