Example #1
0
        public static NDEFRecordShort CreateNewForWrite(RecordType recordType, String type, String payload)
        {
            NDEFRecordShort record = new NDEFRecordShort();

            byte[] bytesType    = Encoding.ASCII.GetBytes(type);
            byte[] bytesPayload = Encoding.ASCII.GetBytes(payload);

            // Record Daten initialisieren
            record.Data = new byte[3 + bytesType.Length + bytesPayload.Length];             // 3 Bytes Versatz vom Header + Längenangaben

            // Header setzen
            record.Data[0]  = (byte)(HeaderMask.MessageBegin | HeaderMask.MessageEnd | HeaderMask.ShortRecord);
            record.Data[0] |= (byte)recordType;

            // Type Länge
            record.Data[1] = (byte)bytesType.Length;

            // Payload Länge
            record.Data[2] = (byte)bytesPayload.Length;

            for (int i = 0; i < bytesType.Length; i++)
            {
                record.Data[i + 3] = bytesType[i];                 // 3 Bytes Versatz vom Header + Längenangaben
            }

            for (int i = 0; i < bytesPayload.Length; i++)
            {
                record.Data[i + 3 + bytesType.Length] = bytesPayload[i];                 // 3 Bytes Versatz vom Header + Längenangaben zusätzlich der Offset der durch den Type entsteht
            }

            return(record);
        }
Example #2
0
 public void StartPublishing(NDEFRecordShort record, MessageTransmittedHandler handler)
 {
     this.record                = record;
     this.transmitHandler       = handler;
     this.device.DeviceArrived += Device_DeviceArrived;
     PublishingMode             = true;
 }
Example #3
0
        public void SubscribeForMessages()
        {
            this.subscriptionID = this.device.SubscribeForMessage("NDEF", (sender, message) => {
                byte[] rawMessage = message.Data.ToArray();

                NDEFRecordShort record = new NDEFRecordShort();
                record.Data            = rawMessage;

                lastMessage = record.Payload;
            });
        }
Example #4
0
        private void messageReceivedHandler(ProximityDevice sender, ProximityMessage message)
        {
            byte[] rawMessage = message.Data.ToArray();

            NDEFRecordShort record = new NDEFRecordShort();

            record.Data = rawMessage;

            if (this.ndefMessageHandler != null)
            {
                this.ndefMessageHandler(record);
            }
        }
Example #5
0
        private void PublishRecordToTag(NDEFRecordShort record, MessageTransmittedHandler handler)
        {
            if (record == null ||
                record.Data == null)
            {
                return;
            }

            IBuffer buffer = record.Data.AsBuffer();

            device.PublishBinaryMessage("NDEF:WriteTag", buffer, (sender, msgID) => {
                if (handler != null)
                {
                    handler(sender, msgID);
                }

                device.StopPublishingMessage(msgID);
            });
        }