韦根 RFID 阅读器 VS USB RFID 阅读器 Raspberry PI [英] Wiegand RFID reader VS USB RFID reader Raspberry PI

查看:19
本文介绍了韦根 RFID 阅读器 VS USB RFID 阅读器 Raspberry PI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个运行 python 代码的树莓派来检索 RFID 标签的序列号.一个有一个 RFID 阅读器,其 Wiegand 接口连接到 GPIO 引脚,另一个有一个 RFID 阅读器,其行为类似于通过 USB 连接的键盘.但是,在扫描同一个 RFID 标签时,我从两个阅读器中得到了不同的数字.

I have two Raspberry Pis running python code to retrieve the serial number of an RFID tag. One has an RFID reader with a Wiegand interface hooked to GPIO pins and other has an RFID reader that behaves like a keyboard connected over USB. However, I get different numbers from the two reader when scanning the same RFID tag.

例如,对于一个标签,我从带有 Wiegand 阅读器的 Raspberry Pi 得到 57924897,从带有 USB 键盘阅读器的 Raspberry Pi 得到 0004591983.

For example, for one tag, I get 57924897 from the Raspberry Pi with the Wiegand reader and 0004591983 from the Raspberry Pi with the USB keyboard reader.

有人能解释一下区别吗?两个读者阅读的内容相同吗?或者他们只是在读取一些不同的参数?

Can sombody explain the difference? Are both readers reading the same? Or are they just reading some different parameter?

推荐答案

看这两个值,你似乎没有正确读取和转换 Wiegand 接口中的值.

Looking at those two values, it seems that you do not properly read and convert the value from the Wiegand interface.

USB 键盘阅读器读取 10 位十进制形式的序列号.韦根阅读器通常将序列号转换为 26 位值(1 个奇偶校验位 + 8 位站点代码 + 16 位标签 ID + 1 个奇偶校验位).

The USB keyboard reader reads the serial number in 10 digit decimal form. A Wiegand reader typically trunkaes the serial number into a 26 bit value (1 parity bit + 8 bit site code + 16 bit tag ID + 1 parity bit).

那么让我们看看你得到的两个值:

So let's look at the two values that you get:

+--------------+------------+-------------+-----------------------------------------+
| READER       | DECIMAL    | HEXADECIMAL | BINARY                                  |
+--------------+------------+-------------+-----------------------------------------+
| USB keyboard | 0004591983 | 0046116F    | 0000 0000 0100 0110 0001 0001 0110 1111 |
| Wiegand      |   57924897 | 373DD21     | 1 1011 1001 1110 1110 1001 0000 1       |
+--------------+------------+-------------+-----------------------------------------+

当您仔细查看这两个值的二进制表示时,您会发现它们相互关联:

When you take a close look at the binary representation of those two values, you will see that they correlate with each other:

USB keyboard: 0000 0000 0100 0110 0001 0001 0110 1111
Wiegand:              1 1011 1001 1110 1110 1001 0000 1

因此似乎韦根值与从 USB 键盘读取器获得的反转值相匹配:

So it seems as if the Wiegand value matches the inverted value obtained from the USB keyboard reader:

USB keyboard: 0000 0000 0100 0110 0001 0001 0110 1111
NOT(Wiegand):         0 0100 0110 0001 0001 0110 1111 0

因此来自韦根接口的反转值(逻辑非)与 USB 读取器读取的值匹配.

So the inverted value (logical NOT) from the Wiegand interface matches the value read by the USB reader.

接下来,让我们看看两个奇偶校验位.Wiegand 接口上的数据通常如下所示:

Next, let's look at the two parity bits. The data over the Wiegand interface typically looks like:

b0  b1  b2  b3  b4  b5  b6  b7  b8  b9  b10 b11 b12 b13 b14 b15 b16 b17 b18 b19 b20 b21 b22 b23 b24 b25
PE  D23 D22 D21 D20 D19 D18 D17 D16 D15 D14 D13 D12 D11 D10 D9  D8  D7  D6  D5  D4  D3  D2  D1  D0  PO

第一行是通过韦根电线到达时编号的位.第二行与接收器需要解释的位相同,其中 PE (b0) 是 D23..D12<上的偶校验位/code> (b1..b12), PO (b25) 是 D11..D0 上的奇校验位code> (b13..b24) 和 D23..D0 是表示无符号整数的数据位.

The first line being the bits numbered as they arrive over the Wiegand wires. The second line being the same bits as they need to be interpreted by the receiver, where PE (b0) is an even parity bit over D23..D12 (b1..b12), PO (b25) is an odd parity bit over D11..D0 (b13..b24), and D23..D0 are the data bits representing an unsigned integer number.

所以看看你的号码,你会收到:

So looking at your number, you would have received:

PE  D23 D22 D21 D20 D19 D18 D17 D16 D15 D14 D13 D12 D11 D10 D9  D8  D7  D6  D5  D4  D3  D2  D1  D0  PO
0   0   1   0   0   0   1   1   0   0   0   0   1   0   0   0   1   0   1   1   0   1   1   1   1   0

如果我们检查奇偶校验位PEPO,我们得到:

If we check the parity bits PE and PO, we get:

PE D23........D12
0  0100 0110 0001

包含 4 个 (1),因此满足偶校验.

contains 4 ones (1), hence even parity is met.

D21.........D0 PO
0001 0110 1111 0

包含 7 个 (1),因此满足奇校验.

contains 7 ones (1), hence odd parity is met.

因此,总结以上内容,您从 Wiegand 接口读取的代码无法正确处理 Wiegand 数据格式.首先,它不会修整奇偶校验位,其次,它读取极性错误的位(零是一,一是零).

So, to summarize the above, your code reading from the Wiegand interface does not properly handle the Wiegand data format. First, it does not trim the parity bits and second, it reads the bits with wrong polarity (zeros are ones and ones are zeros).

为了从韦根读取器获得正确的数字,您要么必须修复从韦根接口读取的代码(修复极性,跳过数据值的第一位和最后一位,并可能检查奇偶校验位).或者您可以取当前获得的值,反转该值,然后去除低位和高位.在 C 中,这看起来像这样:

In order to get the correct number from the Wiegand reader, you either have to fix you code for reading from the Wiegand interface (to fix polarity, to skip the first and the last bit from the data value, and to possibly check the parity bits). Or you can take the value that you currently get, invert that value, and strip the lower and upper bits. In C, that would look something like this:

int unsigned currentWiegandValue = ...;
int unsigned newWiegandValue = ((~currentWiegandValue) >> 1) & 0x0FFFFFF;

这篇关于韦根 RFID 阅读器 VS USB RFID 阅读器 Raspberry PI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆