代码拉取完成,页面将自动刷新
同步操作将从 Wendal/luat-rc522 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
----------------------------------------------------------------------
-- Main
----------------------------------------------------------------------
module(...,package.seeall)
--------------------------------------------------------
-- Converts a table of numbers into a HEX string
function appendHex(t)
strT = ""
for i,v in ipairs(t) do
strT = strT.." 0x"..string.format("%X", t[i])
end
return strT
end
---------------------------------------------------
-- Initialise the RC522
sys.taskInit(function()
sys.wait(3000)
RC522.setup()
sys.wait(100)
print("=================================================")
print("RC522 Firmware Version: 0x"..string.format("%X", RC522.getFirmwareVersion()))
while true do
sys.wait(1000)
isTagNear, cardType = RC522.request()
if isTagNear == true then
--tmr.stop(0)
err, serialNo = RC522.anticoll()
print("Tag Found: "..appendHex(serialNo).." of type: "..appendHex(cardType))
-- Selecting a tag, and the rest afterwards is only required if you want to read or write data to the card
err, sak = RC522.select_tag(serialNo)
if err == false then
print("Tag selected successfully. SAK: 0x"..string.format("%X", sak))
for i = 0,63 do
err = RC522.card_auth(auth_a, i, keyA, serialNo) -- Auth the "A" key. If this fails you can also auth the "B" key
if err then
print("ERROR Authenticating block "..i)
else
-- Write data to card, enable if you need it
--if (i == 2) then -- write to block 2
-- err = RC522.writeTag(i, { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 })
-- if err then print("ERROR Writing to the Tag") end
--end
-- Read card data
if not (i % 4 == 3) then -- Don't bother to read the Sector Trailers
err, tagData = RC522.readTag(i)
if not err then print("READ Block "..i..": "..appendHex(tagData)) end
end
end
end
else
print("ERROR Selecting tag")
end
print(" ")
-- halt tag and get ready to read another.
buf = {}
buf[1] = 0x50 --MF1_HALT
buf[2] = 0
crc = RC522.calculate_crc(buf)
table.insert(buf, crc[1])
table.insert(buf, crc[2])
err, back_data, back_length = RC522.card_write(mode_transrec, buf)
RC522.clear_bitmask(0x08, 0x08) -- Turn off encryption
--tmr.start(0)
else
print("NO TAG FOUND")
end
end
end)
--[[
tmr.alarm(0, 100, tmr.ALARM_AUTO, function()
end) -- timer
]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。