如何使用Windows Phone 10从NFC获取Mac ID。

人气:868 发布:2022-09-22 标签: wpdcapp

问题描述

大家好,

我正在开发一个程序,它提取NFC标签的所有细节,尤其是"Mac ID",

我可以从我的Windows Phone 10上的设备上读取NFC标签,我可以获取设备名称,但我无法获取设备ID,请找到下面的代码。

无效NFCConnect()       {           device = ProximityDevice.GetDefault();           device.DeviceArrived + = Device_DeviceArrived;           device.SubscribeForMessage(" WindowsMime",messageReceived);

}

private void messageReceived(ProximityDevice sender,ProximityMessage message) &NBSP; &NBSP; &NBSP; { &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var buffer = message.Data.ToArray(); &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; int mimesize = 0; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //首先搜索'\0'charactere &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; for(mimesize = 0; mimesize< 256&& buffer [mimesize]!= 0; ++ mimesize) &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; { &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }; b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //提取mimetype &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var messageType = Encoding.UTF8.GetString(buffer,0,mimesize); &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //将数据转换为字符串。这取决于mimetype值。 &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var scans_message = Encoding.UTF8.GetString(buffer,256,buffer.Length - 256); &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }

OutPut:

application / vnd.bluetooth。 ep.oob\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ 0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\ \\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ 0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\ \\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ 0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ 0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\ \\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ 0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\ \\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\\0 ????\\\%\0\\\\tDX30-1693\\\\r\0\\\\0\\\\\\\\\\\\"

谢谢,

Praveen.N

解决方案

根据API参考,您可以获得 DeviceId

ProximityDevice class 具有以下属性:

DeviceId

只读 获取设备标识符。

MaxDistanceInMillimeters

只读 接近传感器可以检测到对象的最大距离。 < td style ="padding:10px 8px;颜色:#2a2a2a;垂直对齐:顶部;最小宽度:80px; border:1px solid rgb(187,187,187)">

MinDistanceInMillimeters

你可以找到Proximity的详细API参考 here 和可以找到UWP SDK示例 这里

Hi All,

I am developing a program which extracts all the details of the NFC tag, especially the "Mac ID",

I am able to read the NFC tag from a Device on my windows phone 10, i am able to get the device name but i am not able to get the device id, please find the code below.

void NFCConnect() { device = ProximityDevice.GetDefault(); device.DeviceArrived += Device_DeviceArrived; device.SubscribeForMessage("WindowsMime", messageReceived);

}

private void messageReceived(ProximityDevice sender, ProximityMessage message) { var buffer = message.Data.ToArray(); int mimesize = 0; //search first '\0' charactere for (mimesize = 0; mimesize < 256 && buffer[mimesize] != 0; ++mimesize) { }; //extract mimetype var messageType = Encoding.UTF8.GetString(buffer, 0, mimesize); //convert data to string. This depends on mimetype value. var scanned_message = Encoding.UTF8.GetString(buffer, 256, buffer.Length - 256); }

OutPut:

application/vnd.bluetooth.ep.oob\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\u001c\0?\u0016?%?\0\n\tDX30-1693\u0004\r\0\u001f\0\u0003\u0002\u0001\u0011"

Thanks,

Praveen.N

解决方案

As per the API reference, you can get theDeviceId

TheProximityDeviceclass has these properties:

DeviceId

Read-only Gets the device identifier.

MaxDistanceInMillimeters

Read-only The largest distance where the proximity sensor can detect an object.

MinDistanceInMillimeters

You can find detailed API reference for Proximity hereand UWP SDK Samples can be foundhere.

335