- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个应用程序,通过蓝牙向汽车诊断扫描仪(如 ELM327)请求信息。因此,我使用 obd-java-api ( https://github.com/eltonvs/java-obd-api ) 作为请求命令,但出现问题并且应用程序崩溃。我对java和蓝牙服务还很陌生,所以我根本不明白问题出在哪里。
一切都很顺利,直到我使用 OBD 命令。我的意思是,当我连接到套接字时它可以工作,但当我使用 de 命令时它不起作用。
有人有想法吗?
我已经验证了我的 OBD 设备是否可以使用蓝牙 AT 命令与 ELM327 终端正常工作。我以为这是 Echo 功能的问题,但是……我错了。
我也尝试了原始的 obd java api( https://github.com/pires/obd-java-api ) 并得到了相同的结果。
package com.example.obd2_bluetooth_communication;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelUuid;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.UUID;
import br.ufrn.imd.obd.commands.ObdCommandGroup;
import br.ufrn.imd.obd.commands.engine.RPMCommand;
import br.ufrn.imd.obd.commands.protocol.EchoOffCommand;
import br.ufrn.imd.obd.commands.protocol.LineFeedOffCommand;
import br.ufrn.imd.obd.commands.protocol.SelectProtocolCommand;
import br.ufrn.imd.obd.commands.protocol.TimeoutCommand;
import br.ufrn.imd.obd.enums.ObdProtocols;
import static android.graphics.Color.RED;
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{
TextView tvEstadoBT, tvRPM;
ImageView ivEstadoBT;
Button btnOnOff, btnPaired, btnEnviar;
BluetoothAdapter mBlueAdapter;
Set<BluetoothDevice> paired_devices;
String plist[];
ListView lvPairedDevices;
ArrayAdapter<String> mAdapter;
ArrayList<BluetoothDevice> mBTDevices = new ArrayList<>();
private static UUID myuuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
BluetoothSocket socket;
//UUID theuuid;
RPMCommand rpmCommand = new RPMCommand();
static final int STATE_CONFIG = 1;
static final int STATE_CONNECTED = 2;
static final int STATE_CONNECTION_FAILED = 3;
static final int STATE_ERROR = 4;
static final int STATE_INTERRUPT = 5;
static final int STATE_DATO_ENVIADO = 6;
private final BroadcastReceiver mBroadcastReceiver1 = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (action.equals(mBlueAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, mBlueAdapter.ERROR);
switch (state){
case BluetoothAdapter.STATE_OFF:
showToast("Bluetooth apagado");
btnOnOff.setText("Encender Bluetooth");
tvEstadoBT.setText("Bluetooth apagado");
tvEstadoBT.setTextColor(RED);
ivEstadoBT.setImageResource(R.drawable.ic_action_off);
btnEnviar.setEnabled(false);
break;
case BluetoothAdapter.STATE_TURNING_OFF:
showToast("Apagando...");
break;
case BluetoothAdapter.STATE_ON:
showToast("Bluetooth encendido");
btnOnOff.setText("Apagar Bluetooth");
tvEstadoBT.setText("Bluetooth encendido");
tvEstadoBT.setTextColor(Color.GREEN);
ivEstadoBT.setImageResource(R.drawable.ic_action_on);
break;
case BluetoothAdapter.STATE_TURNING_ON:
showToast("Encendiendo...");
break;
}
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(mBroadcastReceiver1);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvEstadoBT = findViewById(R.id.tvEstadoBT);
ivEstadoBT = findViewById(R.id.ivEstadoBT);
btnOnOff = findViewById(R.id.btnOnOff);
btnPaired = findViewById(R.id.btnPaired);
lvPairedDevices = findViewById(R.id.lvPairedDevices);
btnEnviar = findViewById(R.id.btnSend);
tvRPM = findViewById(R.id.tvRPM);
mBlueAdapter = BluetoothAdapter.getDefaultAdapter();
//Verificar si el dispositivo posee Bluetooth
if (mBlueAdapter == null) {
showToast("Tu dispositivo no soporta la opción de Bluetooth");
}
//Condiciones iniciales para el botón de encendido/apagado
if (!mBlueAdapter.isEnabled()) {
btnOnOff.setText("Encender Bluetooth");
tvEstadoBT.setText("Bluetooth apagado");
tvEstadoBT.setTextColor(RED);
ivEstadoBT.setImageResource(R.drawable.ic_action_off);
}
if (mBlueAdapter.isEnabled()) {
btnOnOff.setText("Apagar Bluetooth");
tvEstadoBT.setText("Bluetooth encendido");
tvEstadoBT.setTextColor(Color.GREEN);
ivEstadoBT.setImageResource(R.drawable.ic_action_on);
}
}
Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
switch(msg.what)
{
case STATE_CONFIG:
showToast("Configurado");
btnEnviar.setEnabled(true);
finish();
break;
case STATE_CONNECTED:
showToast("Conectado");
btnEnviar.setEnabled(true);
finish();
break;
case STATE_CONNECTION_FAILED:
showToast("Conexión falló");
finish();
break;
case STATE_ERROR:
showToast("Ocurrió un error");
;
break;
case STATE_INTERRUPT:
showToast("Función interrumpida");
break;
case STATE_DATO_ENVIADO:
tvRPM.setText(rpmCommand.getFormattedResult() + " rpm");
break;
}
return false;
}
});
private void showToast(String msg){
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
public void OnOffCLICK(View view) {
if(!mBlueAdapter.isEnabled()){
//showToast("Activando Bluetooth...");
Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableIntent);
IntentFilter BTIntent = new IntentFilter((BluetoothAdapter.ACTION_STATE_CHANGED));
registerReceiver(mBroadcastReceiver1, BTIntent);
}
if(mBlueAdapter.isEnabled()){
mBlueAdapter.disable();
IntentFilter BTIntent = new IntentFilter((BluetoothAdapter.ACTION_STATE_CHANGED));
registerReceiver(mBroadcastReceiver1, BTIntent);
}
}
public void PairedDevicesCLICK(View view) {
if(!mBlueAdapter.isEnabled()){
showToast("La función no está disponible porque el Bluettoth está apagado");
}
else{
paired_devices = mBlueAdapter.getBondedDevices();
mBTDevices = new ArrayList<>();
int count = paired_devices.size();
plist = new String[count];
int j = 0;
for(BluetoothDevice device : paired_devices)
{
mBTDevices.add(device);
plist[j] = device.getName();
j++;
}
mAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,plist);
lvPairedDevices.setAdapter(mAdapter);
lvPairedDevices.setOnItemClickListener(MainActivity.this);
}
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
/*String deviceName = mBTDevices.get(i).getName();
String deviceAddress = mBTDevices.get(i).getAddress();
showToast("Connecting to: " + deviceName);*/
/*ParcelUuid[] uuids = mBTDevices.get(i).getUuids();
theuuid = UUID.fromString(uuids[0].toString());
showToast(theuuid.toString());*/
ClientClass cliente = new ClientClass(mBTDevices.get(i));
cliente.start();
}
public void EnviarCLICK(View view) {
ObdCommandGroup obdCommands = new ObdCommandGroup();
obdCommands.add(new EchoOffCommand());
obdCommands.add(new LineFeedOffCommand());
obdCommands.add(new TimeoutCommand(255));
obdCommands.add(new SelectProtocolCommand(ObdProtocols.AUTO));
//obdCommands.add(new RPMCommand());
obdCommands.add(rpmCommand);
try {
obdCommands.run(socket.getInputStream(), socket.getOutputStream());
Message message = Message.obtain();
message.what = STATE_DATO_ENVIADO;
handler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
Message message = Message.obtain();
message.what = STATE_ERROR;
handler.sendMessage(message);
} catch (InterruptedException e) {
e.printStackTrace();
Message message = Message.obtain();
message.what = STATE_INTERRUPT;
handler.sendMessage(message);
}
}
private class ClientClass extends Thread{
private BluetoothDevice OBD2;
private BluetoothSocket socket;
public ClientClass (BluetoothDevice device1)
{
OBD2 = device1;
/*ParcelUuid[] uuids = OBD2.getUuids();
if (uuids != null)
{
theuuid = UUID.fromString(uuids[0].toString());
//showToast(theuuid.toString());
}*/
try {
//socket = OBD2.createInsecureRfcommSocketToServiceRecord(theuuid);
socket = OBD2.createInsecureRfcommSocketToServiceRecord(myuuid);
} catch (IOException e) {
e.printStackTrace();
Message message = Message.obtain();
message.what = STATE_ERROR;
handler.sendMessage(message);
}
}
public void run()
{
mBlueAdapter.cancelDiscovery();
try {
socket.connect();
Message message = Message.obtain();
message.what = STATE_CONNECTED;
handler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
try {
socket.close();
Message message = Message.obtain();
message.what = STATE_CONNECTION_FAILED;
handler.sendMessage(message);
} catch (IOException e1) {
e1.printStackTrace();
}
return;
}
}
}
}
我期望 RPM 命令结果,但当我请求该结果时应用程序崩溃。
最佳答案
我是您正在使用的库的创建者。首先,感谢您使用我的项目!
阅读您的错误日志后,我发现您的广播接收器有问题,而不是 OBD api 有问题。我认为您忘记在 onCreate
方法中注册接收器(因为您尝试在 onDestroy
中取消注册)。
关于java - 通过蓝牙将数据发送到 OBD-ii 设备时应用程序崩溃 (Android-Studio),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56877534/
当我查看 IIS 日志文件时,我可以在一天中的不同时间看到标题行被写入日志文件。我唯一一次看到这种情况发生是在 IIS 重置时;或启动。 例如下面的标题行; #Software: Microsoft
有谁知道为什么以下 web.conig 更改不起作用: 在我添加 javascript 文件后仍然没有被压缩(gzip)。我折腾了几天,因为一开始我真的不知道问题是
目前,我们所有的网络应用程序都将其应用程序池标识设置为 ApplicationPoolIdentity。现在,当一个应用程序需要访问某些服务器上的某些资源时,比如添加/读取某些文件,该应用程序会在代码
在 IIS(特别是 6.0)中,在“主目录”选项卡下,如果我更改本地路径,是否会导致 IIS 重新启动或应用程序池回收? 相关的,是否有概述 IIS 元数据库的哪些更改将触发重新启动或应用程序池回收的
只要更改了任何 web.config 文件,AFAIK IIS 就会重新启动。 我创建了自己的配置文件(my.config,层次结构略有不同)。是否有可能让 IIS 自动(自动神奇地 :))重新启动,
你好, 我正在寻找 IIS 日志中列出的浏览器条目列表,以帮助识别访问我们网站的不同版本的浏览器。也许没有一个列表,而是一个应该用来识别不同浏览器及其版本的算法。 请注意,我不是在寻找日志分析器,而是
我想知道上次重新启动 iis 是什么时候。 IIS 是否保留了此日志,我在哪里可以找到此日志? 谢谢 最佳答案 打开事件查看器,导航到“Windows 日志”->“系统” 在右侧的“操作” Pane
在全新安装的带有 IIS 7 的 Windows Server 2008 R2 上,它会在 C:\inetpub\wwwroot 中创建一个默认网站。 .我确信对于存储网站文件的好位置有很多主观意见,
我已按照 this question 中的说明在 IIS 中实现动态内容压缩。 . 当我发送请求时,我看不到响应被 gzip 压缩的任何证据: IIS版本为7.5 有什么明显的我应该检查以解决此问题吗
这是场景: 服务器 A 托管“主”应用程序 (www.example.com) 服务器 B 托管支持应用程序 (b.example.com) 它们通过 192.* 地址在内部相互连接,并且都可以通过
是否有任何替代 IIS 管理 UI 可用于从程序重置 IIS?.. 现在我们已经创建了一个批处理文件,如果 iis 重置并每小时安排一次...... 我只是想要一些东西,这样我们就不能重置 iis..
我的 Windows Server 在 IIS 7.5 上运行 Web 应用程序。 我想知道为什么 IIS 应用程序池使用大量内存。 请参阅我从服务器捕获的屏幕截图。 在名为 TEST 2.0(.NE
我在 IIS 7.5 上运行的 ASP Classic 站点上收到服务器错误。 我将“向浏览器发送错误”设置为 True ,但是我仍然收到以下错误屏幕: 最佳答案 IIS 正在劫持您的经典 ASP 应
我正在尝试通过IIS上的反向代理连接到websockets服务器(websockify)。 IIS和Websockets服务器位于同一台物理服务器上(Windows Server 2012 R2,II
我需要让我的开发机器从本地机器商店读取证书 为此,我需要运行winhttpcertcfg.exe并指定我要提升的帐户 该帐户用于IIS表示什么? (对于IIS,它将是IWAM_MachineName)
我正在阅读特定命令(SET-WEBCONFIGURATIONPROPERTY),但出现"is not recognized as a cmdlet"错误。给我的建议是,即使我使用的是SharePoin
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我已经从官方镜像(https://hub.docker.com/r/microsoft/iis/)运行了IIS 在Windows Server 2016上 有什么方法可以从IIS管理器连接到该IIS,
你好, 如果 iis 未运行,我想编写一个状态为的代码。 最佳答案 从命令行启动 IIS: iisreset /start 从命令行停止 IIS: iisreset /stop 重新启动(停止和启动)
我已经为 IIS8 安装了静态和动态压缩并启用了它。 当我的CPU性能100%时,我的GZIP IIS不工作,为什么? 我可以清楚地看到 GZIP 没有在 Live HTTP header 中运行。我
我是一名优秀的程序员,十分优秀!