Skip to content
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

How to read user memory from tag? #10

Open
ehtasham89 opened this issue Feb 8, 2020 · 2 comments
Open

How to read user memory from tag? #10

ehtasham89 opened this issue Feb 8, 2020 · 2 comments

Comments

@ehtasham89
Copy link

How to read user memory from Tag in IOS?
There is no example code in this repository also not available in sample publish in the iTunes app store.

There is any support for user memory?

@nullfx
Copy link

nullfx commented Feb 10, 2020

I opened an issue over a year ago here: #6 with no reply. I've emailed their support with no response.

I've managed to get their device to perform inventory and read user data (but for some reason the identical operation to read TID instead of user data fails). as well as independently read user and TID outside of inventory by just calling the NurApi*** function and having it populate the data array.

though all this has been done for our company's internal code, it's my intention to fork their code base and add it in since they obviously don't care about doing it themselves.

unlike the normal (non user memory) method that uses NurApiStartInventoryStream the user data method uses NurApiInventoryRead followed by NurApiStartInventoryEx with the params and filters (which seem a bit redundant to me... but) to start inventory. this ends up producing an NUR_NOTIFICATION_INVENTORYEX instead of NUR_NOTIFICATION_INVENTORYSTREAM in your notificationReceived function and your data structure is an array of NUR_TAG_DATA_EX rather than NUR_TAG_DATA so you get a count of how many tags were found like you do with inventory stream but copy the tag data to the individual tag using NurApiGetTagDataEx instead of NurApiGetTagData like you would with inventory stream (which is included in the iTunes sample).

to read user data outside of an inventory session (say you know the EPC and just want to read the tag's user data bank) you can call NurApiReadTagByEPC and pass the EPC you wish to read (and epc length), specify the NUR_BANK_USER (because with the API you can obviously read from other banks on the tag), the starting address you want to read from in the user bank, length, and buffer you want it read into.

If I get time this upcoming week I'll try to post a sample / gist on it.

@TimvdGaag
Copy link

TimvdGaag commented Feb 10, 2020

I've did this a few years ago so i don't know if it is still up to date. it's in swift but the idea should be the same for objective-c

You'll create a component that extends the BluetoothDelegate from the NURAPI.
then you register the component as event handler

Bluetooth.sharedInstance().register( self )

then you'll start a inventory stream

var nurInvexParams = NUR_INVEX_PARAMS()
var nurInvexFilter = NUR_INVEX_FILTER()

let error = NurApiStartInventoryEx(Bluetooth.sharedInstance().nurapiHandle, &nurInvexParams, &nurInvexFilter, 0)

Because you've registerd the component as event handler you'll recieve a callback to
func notificationReceived(_ timestamp: DWORD, type: Int32, data: LPVOID!, length: Int32)

in the component i've created a dispatch queue called var tagReadDispatch: DispatchQueue = DispatchQueue(label: "tagRead", qos: DispatchQoS.userInitiated)

func notificationReceived(_ timestamp: DWORD, type: Int32, data: LPVOID!, length: Int32) {
        let x = NUR_NOTIFICATION(UInt32(type))

        self.tagReadDispatch.async {
            switch (x) {
                case NUR_NOTIFICATION_INVENTORYEX, NUR_NOTIFICATION_INVENTORYSTREAM:
                    let u = data.load(as: NUR_INVENTORYSTREAM_DATA.self)
                    var count: Int32 = 0
                    NurApiGetTagCount(Bluetooth.sharedInstance().nurapiHandle, &count)
                    if count > 0  {
                        for index in 0...(count - 1) {
                            var tagData = NUR_TAG_DATA_EX();
        					let szEntry:DWORD = 148
        					let error = NurApiGetTagDataEx(Bluetooth.sharedInstance().nurapiHandle, index, &tagData, szEntry)
        					if NUR_NO_ERROR !=  NUR_ERRORCODES(UInt32(error))  {
            					print("xxx: \(error)")
           	 					continue
        					}
        
        					let epcData = NSData(bytes: [tagData.epc], length: Int(tagData.epcLen))
        					let ddata = NSData(bytes: [tagData.data], length: Int(tagData.dataLen))
        					let tag = Tag(epc: epcData as Data, data: ddata as Data,frequency: tagData.freq, rssi: tagData.rssi, scaledRssi: tagData.scaledRssi, timestamp: tagData.timestamp, channel: tagData.channel, antennaId: tagData.antennaId)
                            NotificationCenter.default.post(name: Notification.Name(rawValue: "tagDectected"), object:tag )
                        }
                    }
                    if u.stopped.boolValue {
                       // stream hased stopped automatically should i trigger restart?
                    }
                    break
                case NUR_NOTIFICATION_TRACETAG:
                    print("Tracinggg.....")
                break;
                case NUR_NOTIFICATION_IOCHANGE:
                    print("BUTTON PRESSED")
                    break;
                default:
                    break;
                }
            }
        }
    }

These are a few 'edited' examples from my project maybe it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@nullfx @TimvdGaag @ehtasham89 and others