NFC温度记录器命令 [英] NFC Temperature Logger Commands

查看:192
本文介绍了NFC温度记录器命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写Android应用程序.我有一个SL13A温度数据记录器,我正在尝试从记录器中读取温度,但是我真的不知道如何.

I am coding an Android aplication. I have a SL13A Temperature Data Logger and I am trying to read temperature from the logger, but I don't really know how.

以下是数据表: http://www.mouser.com /ds/2/588/AMS_SL13A_Datasheet_EN_v4-371531.pdf

我正在使用获取温度命令"(命令代码0xAD).

I am using the Get Temperature Command (command code 0xAD).

我的代码是这样的:

                NfcV nfcvTag = NfcV.get(tag);

                try {
                    nfcvTag.connect();
                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "Could not open connection!", Toast.LENGTH_SHORT).show();
                    return;
                }

                try {

                    byte[] comReadTemp = new byte[]{
                            (byte) 0x00, // Flags
                            (byte) 0xAD, // Command: Get Temperature
                            (byte) 0xE0,(byte) 0x36,(byte) 0x04,(byte) 0xCA,(byte) 0x01,(byte) 0x3E,(byte) 0x12,(byte) 0x01, // UID - is this OK?
                    };


                    byte[] userdata = nfcvTag.transceive(comReadTemp);


                    tvText.setText("DATA: " + userdata.length);

                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "An error occurred while reading!", Toast.LENGTH_SHORT).show();
                    return;
                }

我不确定要设置哪些标志以及我是否在命令中正确放置了UID参数.

I am not sure what flags to set and if I put UID parameter in the command correctly.

还有我的问题是,如何从命令回复中获取温度位?在数据手册中,显示了命令应答的前8位是标志,后16位是温度,后16位是CRC.但似乎我只得到3个字节的回复(userdata.length等于3).

And also my question is, how do I get temperature bits from command reply? In datasheet it is shown that first 8 bits of command reply are flags, next 16 bits are temperature, and last 16 bits are CRC. But it seems that I only get 3 bytes in reply (userdata.length equals 3).

任何帮助将不胜感激.

推荐答案

首先(尽管无论如何您似乎都能获得正确的响应),当您要使用命令的寻址版本时(即包含命令的寻址版本)可选的UID字段),则需要在标志字节中设置被寻址的位.因此标记应为0x20.

First of all (though you seem to get the correct response anyways), when you want to use the addressed version of the command (i.e. the one that contains the optional UID field), you need to set the addressed bit in the flags byte. So flags should be 0x20.

通常,您将创建如下命令:

Typically, you would create the command like this:

byte[] comReadTemp = new byte[]{
        (byte) 0x20, // Flags
        (byte) 0xAD, // Command: Get Temperature
        (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,  // placeholder for tag UID
};
System.arraycopy(tag.getId(), 0, comReadTemp, 2, 8);

transceive()方法获得的响应将仅是ISO 15693帧的有效负载.这样,您将获得标志字节(1个字节)和温度值(2个字节). NFC堆栈会自动剥离SOF,CRC和EOF(就像在发送数据时自动添加它们一样).

The response that you get from the transceive() method will only be the payload of the ISO 15693 frame. Thus, you will get the flags byte (1 byte) and the temperature value (2 bytes). The SOF, CRC and EOF are automatically stripped by the NFC stack (just as they are automatically added when sending data).

所以userdata的字节1..2包含温度值:

So bytes 1..2 of userdata contain the temperature value:

int tempCode = ((0x003 & userdata[2]) << 8) |
               ((0x0FF & userdata[1]) << 0);
double tempValue = 0.169 * tempCode - 92.7 - 0.169 * 32;

假设偏移校准代码为32.该数据表不是很清楚,这是每个芯片的校准值还是该类型芯片的静态值.

Assuming that offset calibration code is 32. The datasheet is not very clear if that's a per chip calibration value or a static value for that type of chip.

这篇关于NFC温度记录器命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆