通过蓝牙从IEC62056协议获取电表数据 [英] Get data from electricity meter with IEC62056 protocol via bluetooth

查看:102
本文介绍了通过蓝牙从IEC62056协议获取电表数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序。我需要通过蓝牙光学探针从仪表获取数据。据我所知,我应该连接到蓝牙探测并发送一些请求以获取仪表值。如果有人知道怎么做,请帮助我。我使用了BluetoothSocket,Outputstream和inputstream但没有运气!



我尝试过:



I am developing an android application.I need to get data from meter by optical probe via bluetooth. As I know I should connect to probe with bluetooth and send some request to that for getting the meter values. Please if anybody knows about how to do it .. help me. I used BluetoothSocket,Outputstream and inputstream but no luck!

What I have tried:

bluetoothSocket = device.createRfcommSocketToServiceRecord(myUUID);




inputStearm = bluetoothSocket .getInputStream();
             outputStream = bluetoothSocket .getOutputStream();

推荐答案

首先,您是否使用正确的权限更新了清单?

需要包含以下权限:

First of all, did you update the manifest with the right permissions?
The following permissions needed to be included:
<manifest ... >
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  ...
</manifest>



在继续下一阶段之前,请确保设备已配对。

您只需检查配对状态:


Before continuing to the next phase, make sure the device is already paired up.
You can simply check the paired state with:

if(device.getBondState()==device.BOND_BONDED)



获取正确的UUID(示例):


Get the correct UUID(example):

private static final UUID MY_UUID = UUID.fromString("0000110E-0000-1000-8000-00805F9B34FB");



此时您必须能够获得套接字。


You must be able to get a socket at this point.

mSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);



阅读套接字:


Read the socket:

mSocket.connect();
InputStream input = mSocket.getInputStream();
DataInputStream dinput = new DataInputStream(input);



稍后您可以阅读:


You can read it later on with:

dinput.readFully(byteArray, 0, byteArray.length);


这篇关于通过蓝牙从IEC62056协议获取电表数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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