我正在撰寫一個 macOS 應用程式,該應用程式將提供使用 ACR122u usb 閱讀器讀取和寫入資料到 nfc 標簽的功能。我很難找到如何在這種環境中向設備發送命令的示例。我遇到了這個問題,但似乎無法使其適應 Swift 或 Objective C。任何幫助將不勝感激。
這是我到目前為止所擁有的,但我似乎無法理解如何發送位元組陣列。
func _getSerialNumber(device: USBDevice) throws -> String {
// get device interface from our pointer
guard let deviceInterface = device.deviceInterfacePtrPtr?.pointee?.pointee else {
throw NSError(domain: domain, code: 404, userInfo: [NSLocalizedDescriptionKey: "device not found"])
}
// create usb device request
let length: Int = 5
var requestPtr: [UInt8] = [UInt8](repeating: 0, count: Int(length))
let type = USBmakebmRequestType(direction: kUSBIn, type: kUSBStandard, recipient: kUSBDevice)
var request = IOUSBDevRequest(bmRequestType: type,
bRequest: UInt8(kUSBRqGetDescriptor),
wValue: 0,
wIndex: 0,
wLength: UInt16(length),
pData: &requestPtr,
wLenDone: 255)
let kr: Int32 = deviceInterface.DeviceRequest(device.deviceInterfacePtrPtr, &request)
if kr == -536870163 {
throw NSError(domain: domain, code: Int(kr), userInfo: [NSLocalizedDescriptionKey: "unable to send request"])
}
if kr != kIOReturnSuccess {
throw NSError(domain: domain, code: Int(kr), userInfo: [NSLocalizedDescriptionKey: "unknown error occurred"])
}
guard let string = String(bytes: requestPtr, encoding: .utf8) else {
throw NSError(domain: domain, code: 500, userInfo: [NSLocalizedDescriptionKey: "unable to decode device response"])
}
return string
}
uj5u.com熱心網友回復:
事實證明,使用 CryptoTokenKit 比我之前發現的更合適。您將讀卡器初始化為 TKSmartCardSlot,將卡初始化為 TKSmartCard。然后通過傳輸函式將位元組陣列傳輸到 TKSmartCard。如果有人需要有關此作業流程的更多資訊,請發送 dm。
https://developer.apple.com/documentation/cryptotokenkit/tksmartcardslot
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/430145.html
上一篇:在Objective-C中為UIButton使用iOS15的新ConfigurationUpdateHandler的示例
下一篇:SwiftIAP訂閱處理所有交易
