我正在做一个需要同时读取六个 ID-12LA RFID 阅读器的项目。
我尝试通过 Sparkfun 模拟/数字 MUX 分线板 (CD74HC4067) 设置六个通道的读数,但没有运气。我不知道它是否能够进行串行通信,尽管我在 Bildr.org 上看到过。
但是,我现在正在尝试通过 SoftwareSerial 库模拟从多个串行端口读取。我读过它不能同时阅读,但也许一个循环可以模拟同时收听。我试图通过监听第一个序列,然后初始化readTag()
,然后在该函数完成后,开始监听第二个序列,然后初始化第二个函数。
当仅连接RFID阅读器时,该readTag()
功能能够自行阅读,所以这不是问题。
下面是代码。
通过循环功能进行和模拟同时阅读的正确方法是什么?
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
}