writeReg method

Future<bool> writeReg(
  1. NfcTag tag,
  2. int address,
  3. int bit,
  4. int value,
)

Implementation

Future<bool> writeReg(NfcTag tag, int address, int bit, int value) async {
  Uint8List? receive;
  String flag;

  try {
    receive = await readReg(tag, address);

    int position = receive![1] & (~bit & 0xFF);
    int data = value & bit;
    int newRegData = (position | data);

    try {
      receive = await sendCommand(
          tag, Uint8List.fromList([0xB6, address, newRegData]));
      flag = await Sic431XFlag().checkFlag(receive!);
    } catch (e) {
      if (Platform.isIOS) {
        NfcManager.instance
            .stopSession(errorMessage: 'Read Register error !!!');
      }
      return false;
    }
  } catch (e) {
    if (Platform.isIOS) {
      NfcManager.instance
          .stopSession(errorMessage: 'Read Register error !!!');
    }
    return false;
  }

  if (flag.isEmpty) {
    if (Platform.isIOS) {
      NfcManager.instance
          .stopSession(errorMessage: 'Read Register error !!!');
    }
    return false;
  }

  return true;
}