Create a NfcV Write Lock Block instruction

Seeking to make data on a NXP ICODE SLIX SL2S2002 tag type 5 (ISO 15693) read-only by utilizing the WRITE SINGLE BLOCKS command through the NfcV object in an app based on Ionic:

    private readonly cmdISO15693 = {
    READ_SINGLE_BLOCK: 0x20,
    WRITE_SINGLE_BLOCK: 0x21,
    LOCK_BLOCK: 0x22
};

this.nfc.connect('android.nfc.tech.NfcV', 500)
      .then(
        (data) => {
            console.log('connected to', this.nfc.bytesToHexString(tag.id.reverse()).toUpperCase());
            console.log('maxTransceiveLength: ', data);

            const offset = 0; // offset of first block to read
            const blocks = 8; // number of blocks to read
            const bytesOfText: number[] = this.nfc.stringToBytes(text);
            console.log('bytesOfText: ', bytesOfText);
            console.log('hex string: ', this.nfc.bytesToHexString(bytesOfText));

            let cmd = new Int8Array([
                0x60, // 0: flags: addressed (= UID field present) or 0x90 0x60 0x40 0x20??
                this.cmdISO15693.READ_SINGLE_BLOCK, // 1: command
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // 2-9 placeholder for tag UID
                0x00  // 10: block number
                // 0x00, 0x00, 0x00, 0x00  // 11- DATA
                // ((blocks - 1) & 0x0ff)  // number of blocks (-1 as 0x00 means one block)
            ]);
            console.log('cmd: ', [...cmd]);

            // tag uid in which direction
            cmd = arrayCopy(tag.id.reverse(), 0, cmd, 2, 8);
            console.log('cmd new: ', [...cmd]);
            console.log('cmd buffer: ', cmd.buffer);
            // arrayCopy(bytesOfText, 0, cmd, 11, 4);

            this.nfc.transceive(cmd.buffer)
              .then((res: ArrayBuffer) => {
                  console.log('transceive result:', res);
                  try {
                      console.log(Utf8ArrayToStr(res));
                  } catch (e) {
                      console.log('Utf8ArrayToStr not possible', e);
                  }

                  this.nfc.close().then(() => console.log('closed connection'))
                    .catch((err) => console.log('error closing', err));
              })
              .catch((err) => {
                  console.log('error while transceive', err);
                  this.displayToast('Error to write the RFID-Chips.', 'warning');
              });

I'm unsure about the correct byte values to pass for each block. Using the phoneGap-NFC plugin for Ionic. When attempting to set it as read-only, the response 'Tag was lost' is returned, even with the READ_SINGLE_BLOCK command. The method makeReadOnly() in Ionic does not function due to tag restrictions. Setting it using bytes seems necessary. Uncertain whether to use Int8Array or Unit8Array, if applying reverse() on the tagId due to mirrored hex, or simply passing the UID bytestring instead of the hexstring.

Answer №1

     this.nfc.connect('android.nfc.tech.NfcV', 500)
      .then(
        async () => {
          const numberOfBlocks = 28; // The app can read 28 blocks with each block having 4 bytes in TagInfo memory
          const lockCommand = this.cmdISO15693.OPTION_FLAG  // 0 flag addressed
            + ' ' + this.cmdISO15693.LOCK_BLOCK        // 1 command
            + ' ' + this.tagIdHexArr.join(' ');         // 2-9 tag uid

          let blockError = false;
          let responseTransceive: ArrayBuffer;
          for (let i = 0; i < numberOfBlocks; i++) {
            const block = this.nfc.bytesToHexString([i]).toUpperCase();
            const cmd = lockCommand + ' ' + block;

            try {
              responseTransceive = await this.nfc.transceive(cmd);
              try {
                const view = new Uint8Array(responseTransceive);
                const hexResponse = this.nfc.bytesToHexString([...view]);
                console.log(hexResponse);
              } catch (e) {
                console.log(e);
              }
            } catch (e) {
              blockError = true;
              return;
            }
            if (blockError) {
              return;
            }
          }
          if (blockError) {
            this.notification.push(new Notification(NotificationType.ERROR, 'Error setting write protection.'));
          }
          this.nfc.close().then(() => console.log('Closed connection'))
            .catch((err) => console.log('Error closing: ', err));
        });

Solved the issue!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Loading Google Books JSON data into a ListView

Currently, I am utilizing the Google Books API to search for books. However, I am encountering an issue when trying to populate my ListView with the searched books as it is throwing an error specifically in the onPostExecute method, but I am unable to iden ...

Is there a way for me to add a clickable link within a tooltip?

In my title, I want to insert a clickable link like 'Link' or 'a'. The title is ready for any string you input. <MaterialSwitch title={CLICKABLE STRING HERE} /> ...

Ways to effectively implement a function type specified in an interface

Consider the following interface: interface MyProps { onEvent: (name: string, data: any) => void; } Is there a way to utilize the function type in order to avoid unused parameter errors during compilation? eventHandler = (name: string, data: any) = ...

Mobile compatibility in ECMAScript 5.1 is essential for creating seamless user

Is there a reliable source for information on ECMAScript 5.1 compatibility with mobile browser devices? ...

Error in React Native Navigation: Passing parameters is not functioning properly

Within my React Native application, I have meticulously established the following routes in my app.js: export default class App extends Component { render() { return ( <NavigationContainer> <Stack.Navigator initialRouteName=&qu ...

Issue: Module not found; Typescript error encountered in a react application

I have a load_routes.js file in the node_express folder that is responsible for loading all the routes for my project. Everything was working smoothly until I decided to change the file extension from .js to .ts. Suddenly, I started encountering the follow ...

Can you explain the significance of the semi-colon at the start of this loop?

During my review of an open source code, I stumbled upon a semi-colon. At first glance, I assumed it was a mistake, however, further investigation revealed otherwise. What is the purpose of the semicolon immediately following the opening brackets in the f ...

Tips for syncing the state data stored in local storage across all tabs with Ngxs state management

After converting the state data to base64 format using the Ngxs state management library, I am saving it. While I can retrieve all data across different tabs, any changes made in one tab do not automatically sync with other tabs. A tab refresh is required ...

What are the best practices for transpiling code using Parcel-bundler?

Currently, I am attempting to transpile both .ts (TYPESCRIPT) and .scss (SASS) files. However, I am encountering two main issues: 1) Instead of generating my file in the designated dist directory, it is creating a dist directory within the build folder. ...

Aligning validation schema with file type for synchronization

Below is the code snippet in question: type FormValues = { files: File[]; notify: string[]; }; const validationSchema = yup.object({ files: yup .array<File[]>() .of( yup .mixed<File>() .required() .t ...

Exploring the methods of connecting with data-checked and data-unchecked attributes in Angular

Utilizing a toggle switch, I am able to determine what text to display in the div by utilizing html attributes such as data-checked and data-unchecked. In addition, I have an Angular pipe that translates all texts on the website based on the selected lang ...

When working with the "agora-rtc-sdk-ng" package, an error may be thrown by Next.js stating that "window is not defined"

Currently, I am in the process of incorporating the "agora-rtc-sdk-ng" package for live streaming with next.js and typescript. import AgoraRTC from 'agora-rtc-sdk-ng'; However, when I try to import it, an error is thrown as shown below: https:/ ...

Mastering communication between Android devices and handling complex data structures through socket programming

Recently, I've been exploring Android and I have a task at hand to establish a TCP socket connection and listen on a specific port. The client application will be sending me 2 images along with a related string. Instead of transmitting each piece of d ...

Implementing conditional where clauses in Firestore queries with dynamic parameters

Consider this scenario: I have a dynamic filter list for my product list, and I want to send an HTTPS request to a cloud function based on the selected filters. However, when trying to set multiple conditional where clauses from that request... The multip ...

Excluding certain source files in Typescript's tsconfig is a common practice to

My attempt to configure Typescript to exclude specific files during compilation is not working as expected. Despite setting exclusions in my tsconfig.json file, the code from one of the excluded files (subClassA.ts) is still being included in the compiled ...

Help needed: I am attempting to convert a Java code that retrieves an int value from a MYSQL database into a string using Shared Preferences in Android Studio

I am facing a challenge with my database that returns 2 integer-type values (1 = USD and 3 = GHS). After writing an API PHP code to retrieve these integer values, I now need to convert them into their corresponding String representations (USD and GHS) in J ...

Posting an array as form data in Angular Typescript: A step-by-step guide

Hello there, I'm currently developing an application using Angular 8 and integrating web.api within .net core 2.2. One of the challenges I encountered is dealing with multi-selectable checkboxes in a form that also includes "regular" inputs and file ...

Convert parameterized lambdas for success and failure into an observable using RxJS

There is a function exported by a library that I am currently using: export function read( urlOrRequest: any, success?: (data: any, response: any) => void, error?: (error: Object) => void, handler?: Handler, httpClient?: Object, ...

Troubleshooting React TypeScript in Visual Studio Code

I've recently set up an ASP Core project with the React TypeScript template, but I'm encountering difficulties when it comes to debugging. The transition between the TypeScript code and the corresponding generated JavaScript code is proving to be ...

Steps for resolving the error message: "An appropriate loader is required to handle this file type, but there are no loaders currently configured to process it."

I am encountering an issue when working with next.js and trying to export a type in a file called index.ts within a third-party package. Module parse failed: Unexpected token (23:7) You may need an appropriate loader to handle this file type, current ...