This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

RFID reader integration over RS-232
#1
The example below shows how to integrate Idesco Access 7 C RFID reader over RS-232 port. The script below will read all RFID cards and log IDs. The script is easy adjustable if there is a necessity to trigger specific KNX, Bacnet etc. objects.

Add the following resident script with sleep-time = 0:


Code:
-- init
if not port then
 require('serial')

 port = serial.open('/dev/RS232', { baudrate = 9600 })

 function readid(port)
   local char, byte, line, id, csum, val

   -- wait for start byte
   char = port:read(1, 1)
   if not char then
     return nil, 'timeout'
   end

   -- start byte must be STX
   byte = char:byte(1)
   if byte ~= 2 then
     return nil, 'wrong start byte'
   end

   -- read remaining line
   line = port:read(15, 1)
   if not line then
     return nil, 'failed to read data'
   end

   -- calculate checksum
   csum = 0
   for i = 1, 11 do
     val = tonumber(line:sub(i, i), 16)
     csum = bit.bxor(csum, val)
   end

   -- verify checksum
   if csum ~= tonumber(line:sub(12, 12), 16) then
     return nil, 'invalid checksum'
   end

   -- return ID
   return line:sub(1, 10)
 end
end

id = readid(port)
if id then
 log(id)
end
Reply


Messages In This Thread
RFID reader integration over RS-232 - by edgars - 31.03.2016, 10:33

Forum Jump: