I have a RFID reader that reads a keyfob and outputs the number in zeros and ones I then read these numbers and process them to get the proper ID number. The problem is there are two different types and they need to be processed differently. One is 26bits long and the other is 37bits long the problem is how do I created the condition to check which it is. there is a digitCount that counts how many bites it's received the problem is once it gets to 26 it will execute the code, but what if it's a 37 bit keyfob, I need a way to see if the number keeps going before it goes to the 26bit section of code is there a way to do this?
The best way would be if there is some unique bit pattern to identify the end of the stream. Have you read through the datasheet for your reader to see if there is any advice about this? Waiting to see if the number keeps going could be a problem if someone waves a 26 bit fob twice quickly.
How is the data coming into the Arduino? Like mem said, if there was a unique header or terminator on each type, you could key off of that.
Can you process the data as 37-bits, if it fails, truncate to 26-bits and process again?
No, the way the program works it wouldn't be able to detect a failure, what i'm going to do is create a timer and have it wait until the timer reaches a certain amount and then have it check to see what the digit count is. I will have the interrupts reset the timer every time a bit is received so that the timer threshold won't have to be very long.
I don't think you need the complication of interrupts and timers.
In your code, check if at least 26 characters are available on the serial port, if so, delay perhaps 100 milliseconds and see if at least 37 characters are available. Choose your decode logic based on this.
Its flawed because you may get 52 characters through a double wave of a 26 character tag, but something along these lines may be good enough if you really can determine the start or end of tag data. Did you check if the reader sends something like a carriage return at the end of a message?