RFID Read When the Card Touch

3 views (last 30 days)
Khalid
Khalid on 14 May 2014
Commented: Walter Roberson on 14 May 2014
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 Comments
Khalid
Khalid on 14 May 2014
Edited: Walter Roberson on 14 May 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 on 14 May 2014
Is there a line terminator? Is the string width fixed per sample?

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 14 May 2014
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 Comment
Walter Roberson
Walter Roberson on 14 May 2014
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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!