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

Writes become slower each time #153

Open
gavinheale opened this issue May 22, 2024 · 0 comments
Open

Writes become slower each time #153

gavinheale opened this issue May 22, 2024 · 0 comments

Comments

@gavinheale
Copy link

I am running the following code and its seems to get slower and slower each time. The first few tags go very fast but after 30 or so I am waiting several seconds for a write. This is on a Mac M3 so should be pretty fast.

Any idea why this is happening.

nfc.on('reader', reader => {
    console.log(`${reader.reader.name} device attached`);
    let sequence = 0;

    reader.on('card', async card => {
        console.log(`Card detected:`, card);
        
        try {
            const data = await reader.read(4, 31 * 4);
            console.log("Data read from tag:", toHexString(data));

            if (data[12] == 0) {
                console.log("Tag is empty, writing data...");
                await reader.write(4, kTagData);
                console.log("Data written to tag successfully.");
            } else {
                console.log("Tag is not empty.");
            }

            sequence++;  // Increment sequence only on success

            const tagInfo = { sequence: sequence, uid: card.uid };
            win.webContents.send('nfc-tag', tagInfo);
        } catch (error) {
            console.error("Failed to read or write tag:", error);
        } finally {
            await reader.disconnect();
        }
    });

    reader.on('error', err => {
        console.error('An error occurred with the NFC reader:', err);
    });

    reader.on('end', () => {
        console.log(`${reader.reader.name} device removed`);
    });
});
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

1 participant