RFID Read When the Card Touch

Hello, I wrote a program where fscanf() should run in continuous, for the sake of getting data & storing into my database from RFID, which is connected with serial cable, two callback are there, when I'm running first callback the code contain while(1), run infinite and take the data from RFID reader and storing it. When the callback is running in which while (1) is present the program cant move on any other function or callback. How can I control it ? or what is the shortest way to read data from RFID ? Is it possible to read data only when the RFID Card/Tag touch to RFID Reader ?

2 commentaires

Khalid
Khalid le 14 Mai 2014
Modifié(e) : Walter Roberson le 14 Mai 2014
some code of my program:
s=serial('COM1');
s.BaudRate=9600;
s.Timeout=.001;
s.InputBufferSize=12;
function tog1_Callback(hObject, eventdata, handles)
% hObject handle to tog1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global s col conn
set(handles.tog1,'string','Reading Started...');
fopen(s);
while(1)
out=fscanf(s);
if ~isempty(out)
db=cellstr(out);
fastinsert(conn,'RFID_FINAL',col,db);
end
if get(handles.tog1,'value')==0
break;
end
end
Walter Roberson
Walter Roberson le 14 Mai 2014
Is there a line terminator? Is the string width fixed per sample?

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 14 Mai 2014

0 votes

Set the serial port up with a BytesAvailableFcn that runs when the RFID information is detected as having been presented to the serial device. In that callback, fread() or fgetl() from the serial port to transfer from the buffer into your program.
You can check the BytesAvailable property of the serial port to determine whether anything has been received and transferred into the buffer.

1 commentaire

s.BytesAvailableFcn = @(src, evt) fastinsert(conn, 'RFID_FINAL', col, {fgetl(s)});
and then no loop will be needed: the callback will be triggered when data is available.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Tags

Question posée :

le 14 Mai 2014

Commenté :

le 14 Mai 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by