31.03.2016, 10:33
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:
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