private void btnReadAll_Click(object sender, EventArgs e) { if (!connActive) { return; } string tmpStr = string.Empty; int startBlock = 4, endBlock = 0, dataLength = 0, dataAllLength; int dataPageIndex = 0; byte[] recvData = new byte[6]; recvData = ReadDataFromCard(startBlock, 4); dataLength = recvData[1]; dataAllLength = dataLength + 3; if (dataLength > 0) { byte[] effectiveData = new byte[dataLength]; effectiveData[0] = recvData[2]; effectiveData[1] = recvData[3]; endBlock = dataAllLength % 4 == 0 ? dataAllLength / 4 + startBlock : dataAllLength / 4 + startBlock + 1; for (int iBlock = startBlock + 1; iBlock < endBlock; iBlock++) { recvData = ReadDataFromCard(iBlock, 4); for (int iBit = 0; iBit < 4; iBit++) { if ((dataPageIndex * 4 + iBit + 2) < effectiveData.Length) { effectiveData[dataPageIndex * 4 + iBit + 2] = recvData[iBit]; } } dataPageIndex++; } try { NdefMessage message = NdefMessage.FromByteArray(effectiveData); NdefRecord record = message[0]; if (record.CheckSpecializedType(false) == typeof(NdefTextRecord)) { //Convert and extract Smart Poster info var textRecord = new NdefTextRecord(record); WriteLog(3, 0, textRecord.Text); } } catch { } } }
public static String ProcessNFCRecord(NdefRecord record) { //Define the tag content we want to return. String tagContent = null; //Make sure we have a record. if (record != null) { //Check if the record is a URL. if (record.CheckSpecializedType(true) == typeof(NdefUriRecord)) { //The content is a URL. tagContent = new NdefUriRecord(record).Uri; } else if (record.CheckSpecializedType(true) == typeof(NdefMailtoRecord)) { //The content is a mailto record. tagContent = new NdefMailtoRecord(record).Uri; } else if (record.CheckSpecializedType(true) == typeof(NdefTelRecord)) { //The content is a tel record. tagContent = new NdefTelRecord(record).Uri; } else if (record.CheckSpecializedType(true) == typeof(NdefSmsRecord)) { //The content is a sms record. tagContent = new NdefSmsRecord(record).Uri; } else if (record.CheckSpecializedType(true) == typeof(NdefTextRecord)) { //The content is a text record. tagContent = new NdefTextRecord(record).Text; } else { //Try and force a pure text conversion. tagContent = Encoding.UTF8.GetString(record.Payload); } } //Return the tag content. return(tagContent); }