-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Serialnumber/UID from reader? #130
Comments
Did you solve this ? I have the same issue. |
Might be a little late, but I found a way that seems to be reliable so far. I have two readers plugged into my Raspberry Pi 4. First I check what the addresses are with lsusb
# Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
# Bus 001 Device 010: ID 072f:2200 Advanced Card Systems, Ltd ACR122U
# Bus 001 Device 011: ID 072f:2200 Advanced Card Systems, Ltd ACR122U
# Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
# Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Then I use
With the info provided by the
Here's my code to do all that// usb.ts
import { execaCommand } from "execa"
const LSUSB_MATCHER = /^Bus (\d+) Device (\d+).+ACR122U/
const KERNEL_MATCHER = /KERNEL=="(.+)"$/m
const TIME_MATCHER = /ATTR{power\/active_duration}=="(.+)"$/m
const DEVICE_MATCHER = /ACS ACR122U PICC Interface (\d+) 00/m
const PORTS = {
"1-1.1": "upper",
"1-1.2": "lower",
} as const
type USBDevice = {
kernel: string
time: string
}
export const parseUSBData = async () => {
const output = await execaCommand("lsusb")
const devices: USBDevice[] = []
for (const line of output.stdout.split("\n")) {
const match = LSUSB_MATCHER.exec(line)
if (!match) continue
const [, bus, device] = match
const address = `/dev/bus/usb/${bus}/${device}`
const info = await execaCommand(`udevadm info -a -n ${address}`)
const kernelMatch = KERNEL_MATCHER.exec(info.stdout)
if (!kernelMatch) throw new Error("no kernel match")
const [, kernel] = kernelMatch
const timeMatcher = TIME_MATCHER.exec(info.stdout)
if (!timeMatcher) throw new Error("no time match")
const [, time] = timeMatcher
devices.push({ kernel, time })
}
return devices.sort((a, b) => Number.parseInt(b.time) - Number.parseInt(a.time))
}
export const getPort = async (deviceName: string) => {
const deviceIndexMatch = DEVICE_MATCHER.exec(deviceName)
if (!deviceIndexMatch) throw new Error("no device index match")
const [, deviceIndex] = deviceIndexMatch
const devices = await parseUSBData()
const device = devices[Number.parseInt(deviceIndex)]
if (!device) throw new Error("no device found")
const port = PORTS[device.kernel as keyof typeof PORTS]
if (!port) throw new Error("no port found")
return port as (typeof PORTS)[keyof typeof PORTS]
} With that I just get the port like this: import { NFC } from "nfc-pcsc"
import { getPort } from "./usb"
const nfc = new NFC()
nfc.on("reader", async reader => {
const port = await getPort(reader.reader.name)
console.log("connected reader", port)
}) |
I have four 1252u readers connected and it works great. However I need to know what card is read from what reader even after reboot or some usb-devices are plug out/in and the name is changed depending on the order they are booted.
Is there a way to solve this?
Cheers,
Stefan
The text was updated successfully, but these errors were encountered: