rfid string look up on SD card (MIKROBASIC)

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
Collinsfarming13
Posts: 1
Joined: 09 May 2020 08:08

rfid string look up on SD card (MIKROBASIC)

#1 Post by Collinsfarming13 » 09 May 2020 09:01

Hi all,
I have a project that I am working on where there is rfid and an sd card.

When there has been an incoming rfid string, it will search for the rfid number in the sd card and return the filename it is under.

The procedure basics;
- Open each file calf001.txt to calf080.txt
- Read string in each file
- Split the rfid number out of the string
- Compare the incoming rfid string to the rfid string in each file
- If there is a match exit the loop.

I am interested in peoples thoughts around how I am doing this procedure. I find it slower than I would like and in the finished project there will be 500+ files to open and find/match the rfid number, which will take a very long time. Im hoping to get a result fairly instant to 5 seconds

Although it appears after calf040 it isn't working either for some reason....I have just noticed this as im posting this message.

I would really love to know suggestions of a better way of doing this as im only a cowboy programmer making it up as I go... :lol:

Thanks in advance

Code: Select all

SUB PROCEDURE CHECK_RFID

SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH)
IF Mmc_Fat_Init() = 0 then                      'IS THE SD CARD INSERT/NO ERRORS
   PORTC = 0xF0

   SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH)

FILENAME = "CALFxxx.TXT"

 FOR CHECK = 001 TO 080                                        'ideally 001 to 500  
 filename[4] = WORD(CHECK DIV 100 + 48)
 filename[5] = WORD((CHECK MOD 100)/10 + 48)
 filename[6] = WORD(CHECK mod 10 + 48)
                                                                                'filename[7]-[10]  = .TXT
 FILENAME[11] = 0     'NULL STRING
 
  Mmc_Fat_Assign(filename, 0)
  Mmc_Fat_Reset(size)                                              ' To read file, sub procedure returns size of file

    while size > 0
    FOR I = 0 TO 45                          
    Mmc_Fat_Read(character)
    CALF_DATA[I] = CHARACTER
    Dec(size)
    NEXT I
    CALF_DATA[46] = 0      						'NULL the string                   
    wend
    
   SPLIT(RFID_NUMBER, CALF_DATA, ",", 0)                 'FIND RFID NUMBER IN THE STRING

   RES = strstr(rfid_data,RFID_NUMBER)                      'COMPARE RFID DATA(SCANNED TAG WITH RFID NUMBER(SD CARD)
   
   If RES = 0 then                                                       'HAS THERE BEEN A MATCH?
   EXIT                                                                      'EXIT THE LOOP
   END IF
  
   NEXT CHECK
 
     ELSE
    ERROR_SD = 1                                                       ' FLAG PROGRAM THAT CARD NOT INSERTED 'ERROR'
   END IF
END SUB

Post Reply

Return to “User Projects”