使用Micropython,JRD-100和Raspberry Pi Pico的RFID读取器的输出不一致
我正在尝试阅读这些 rfid标签使用来自
我的代码:
from machine import UART, Pin
import utime
RFID_cmdnub = *OMITTED FOR BREVITY. SEE BLOG POST*
class Main:
def __init__(self):
self.uart2 = UART(1, baudrate=115200, rx=Pin(5), tx=Pin(4), timeout=10)
print("UHF-Reader")
#self.Sendcommand(37)
def Sendcommand(self, com_nub):
self.uart2.write(bytes(RFID_cmdnub[com_nub]))
#self.uart2.write("\n\r")
def Readcallback(self):
while self.uart2.any():
#utime.sleep_ms(2)
temp = self.uart2.read()
if temp == b'\xbb\x01\xff\x00\x01\x15\x16~':
print(None)
else:
print(temp)
def loop(self):
#print("Polling...")
self.Sendcommand(3)
#print("Recieving:")
self.Readcallback()
utime.sleep_ms(100)
#print()
M = Main()
while True:
M.loop()
以下代码包括示例标签在“ RS”列表中读取(每条读数一行),其中我在读者上方握住了两个标签,持续几秒钟。在此之后的代码与读取的第一个标签进行比较,该标签要突出显示什么正在发生变化,并且在哪里:
rs = [
b'\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~\xbb\x02"\x00\x11\xcf4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e.~',
b'\xbb\x02"\x00\x11\xce4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e-~\xbb\x02"\x00\x11\xc34\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e"~',
b'\xbb\x02"\x00\x11\xcc4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e+~\xbb\x02"\x00\x11\xc44\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e#~',
b'\xbb\x02"\x00\x11\xc44\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e#~',
b'\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~\xbb\x02"\x00\x11\xcc4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e+~',
b'\xbb\x02"\x00\x11\xcb4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e*~',
b'\xbb\x02"\x00\x11\xcb4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e*~\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~\xbb\x02"\x00\x11\xc04\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e\x1f~',
b'\xbb\x02"\x00\x11\xcb4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e*~',
b'\xbb\x02"\x00\x11\xc94\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e(~\xbb\x02"\x00\x11\xc14\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e ~',
b'\xbb\x02"\x00\x11\xc94\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e(~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~\xbb\x02"\x00\x11\xc44\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e#~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~',
b'\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~',
b'\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~\xbb\x02"\x00\x11\xc94\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e(~'
]
R1 = [[[hex(val) for val in temp] for temp in r.split(b'~')] for r in rs]
base = R1[0][0]
for rset in R1:
print('-')
for r in rset:
if len(r) > 0:
print([f'{idx}: {v}' for idx, v in enumerate(r) if v != base[idx]])
打印以下内容,这表明每个读数的相同值都在变化,并用“ []'表示完美匹配到第一个标签那是读的。
-
[]
['5: 0xcf', '22: 0x2e']
-
['5: 0xce', '22: 0x2d']
['5: 0xc3', '22: 0x22']
-
['5: 0xcc', '22: 0x2b']
['5: 0xc4', '22: 0x23']
-
['5: 0xc4', '22: 0x23']
-
[]
['5: 0xcc', '22: 0x2b']
-
['5: 0xcb', '22: 0x2a']
-
['5: 0xcb', '22: 0x2a']
[]
-
['5: 0xca', '22: 0x29']
-
['5: 0xca', '22: 0x29']
-
['5: 0xca', '22: 0x29']
['5: 0xc0', '22: 0x1f']
-
['5: 0xcb', '22: 0x2a']
-
['5: 0xc9', '22: 0x28']
['5: 0xc1', '22: 0x20']
-
['5: 0xc9', '22: 0x28']
-
['5: 0xca', '22: 0x29']
['5: 0xc4', '22: 0x23']
-
['5: 0xca', '22: 0x29']
-
[]
['5: 0xca', '22: 0x29']
-
[]
['5: 0xc9', '22: 0x28']
显然,这里不正确,因为我不希望相同两个标签会这样变化。谁能阐明这里发生的事情?
编辑:将命令从:从:
{0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E,} //3. Single polling instruction
返回
{0xBB, 0x00, 0x39, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x08, 0x4D, 0x7E} //9. Read label data storage area
值更加一致之后,但我仍然得到每个标签的〜4值。我还尝试了其他标签,两种类型的行为相同。
I'm trying to read these RFID tags from a JRD-100 using a Raspberry Pi Pico running MicroPython (thonny as IDE) using code adapted from this blog post, which was originally written for Arduino. So far it appears to be working (I can request and get responses) except for the strangely inconsistent outputs returned by the program.
My code:
from machine import UART, Pin
import utime
RFID_cmdnub = *OMITTED FOR BREVITY. SEE BLOG POST*
class Main:
def __init__(self):
self.uart2 = UART(1, baudrate=115200, rx=Pin(5), tx=Pin(4), timeout=10)
print("UHF-Reader")
#self.Sendcommand(37)
def Sendcommand(self, com_nub):
self.uart2.write(bytes(RFID_cmdnub[com_nub]))
#self.uart2.write("\n\r")
def Readcallback(self):
while self.uart2.any():
#utime.sleep_ms(2)
temp = self.uart2.read()
if temp == b'\xbb\x01\xff\x00\x01\x15\x16~':
print(None)
else:
print(temp)
def loop(self):
#print("Polling...")
self.Sendcommand(3)
#print("Recieving:")
self.Readcallback()
utime.sleep_ms(100)
#print()
M = Main()
while True:
M.loop()
The following code includes example tag reads in the "rs" list (one line per read) where I held two tags above the reader for a few seconds. The code after that compares to the first tag that was read to highlight what is changing and where:
rs = [
b'\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~\xbb\x02"\x00\x11\xcf4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e.~',
b'\xbb\x02"\x00\x11\xce4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e-~\xbb\x02"\x00\x11\xc34\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e"~',
b'\xbb\x02"\x00\x11\xcc4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e+~\xbb\x02"\x00\x11\xc44\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e#~',
b'\xbb\x02"\x00\x11\xc44\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e#~',
b'\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~\xbb\x02"\x00\x11\xcc4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e+~',
b'\xbb\x02"\x00\x11\xcb4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e*~',
b'\xbb\x02"\x00\x11\xcb4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e*~\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~\xbb\x02"\x00\x11\xc04\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e\x1f~',
b'\xbb\x02"\x00\x11\xcb4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e*~',
b'\xbb\x02"\x00\x11\xc94\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e(~\xbb\x02"\x00\x11\xc14\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e ~',
b'\xbb\x02"\x00\x11\xc94\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e(~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~\xbb\x02"\x00\x11\xc44\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e#~',
b'\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~',
b'\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~\xbb\x02"\x00\x11\xca4\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e)~',
b'\xbb\x02"\x00\x11\xc24\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e!~\xbb\x02"\x00\x11\xc94\x000\x083\xb2\xdd\xd9\x01@\x00\x00\x00\x00\xc4\x1e(~'
]
R1 = [[[hex(val) for val in temp] for temp in r.split(b'~')] for r in rs]
base = R1[0][0]
for rset in R1:
print('-')
for r in rset:
if len(r) > 0:
print([f'{idx}: {v}' for idx, v in enumerate(r) if v != base[idx]])
This prints the following, which shows that the same values are varying for each reading, with the '[]' denoting perfect matches to the first tag that was read.
-
[]
['5: 0xcf', '22: 0x2e']
-
['5: 0xce', '22: 0x2d']
['5: 0xc3', '22: 0x22']
-
['5: 0xcc', '22: 0x2b']
['5: 0xc4', '22: 0x23']
-
['5: 0xc4', '22: 0x23']
-
[]
['5: 0xcc', '22: 0x2b']
-
['5: 0xcb', '22: 0x2a']
-
['5: 0xcb', '22: 0x2a']
[]
-
['5: 0xca', '22: 0x29']
-
['5: 0xca', '22: 0x29']
-
['5: 0xca', '22: 0x29']
['5: 0xc0', '22: 0x1f']
-
['5: 0xcb', '22: 0x2a']
-
['5: 0xc9', '22: 0x28']
['5: 0xc1', '22: 0x20']
-
['5: 0xc9', '22: 0x28']
-
['5: 0xca', '22: 0x29']
['5: 0xc4', '22: 0x23']
-
['5: 0xca', '22: 0x29']
-
[]
['5: 0xca', '22: 0x29']
-
[]
['5: 0xc9', '22: 0x28']
Clearly, something is not right here since I would not expect the values to vary like this for the same two tags. Can anyone shed light on what's happening here?
Edit: after changing the command from:
{0xBB, 0x00, 0x22, 0x00, 0x00, 0x22, 0x7E,} //3. Single polling instruction
to
{0xBB, 0x00, 0x39, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x08, 0x4D, 0x7E} //9. Read label data storage area
The returned values are more consistent, but I still get ~4 values per tag. I have also tried this with other tags and both types behave the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论