我很难转换两个字节的温度。
我有一个控制单元(温度传感器),我可以在其中获取两个字节的温度消息。
1)示例:
message: [ 40 ][ 25 ]
LSBYTE : [ 40 ]
MSBYTE : [ 25 ]
0.03125 C/bit
temperature: 25C° ( seen from the display of the control unit )
2)示例:
message: [ 40 ][ 26 ]
LSBYTE : [ 40 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 30C° ( seen from the display of the control unit )
3)示例:
message: [ 20 ][ 26 ]
LSBYTE : [ 20 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 32C° ( seen from the display of the control unit )
4)示例:
message: [ c0 ][ 25 ]
LSBYTE : [ c0 ]
MSBYTE : [ 26 ]
0.03125 C/bit
temperature: 29C° ( seen from the display of the control unit )
我不知道如何将消息转换为温度。
我请求您的支持。
谁能给我一个解决方案,它可以在我的项目中协作(创建一个应用程序android来接收来自控制单元的消息)
这简直就是小尾数法 http://en.wikipedia.org/wiki/Endianness字节顺序。最重要的字节是 MSB。看起来它本身就是摄氏度。所以只需像这样阅读(请原谅伪代码):
var msbyte = read() // whatever you need to get the value
var lsbyte = read() // whatever you need to get the value
var temperature = msbyte
temperature += (lsbyte / 100)
在你的情况下它只是 25.40C°
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)