【问题标题】:Communicating with a Bluetooth OBDII dongle (I think it's an ELM327)与蓝牙 OBDII 加密狗通信(我认为它是 ELM327)
【发布时间】:2016-12-04 18:45:39
【问题描述】:

我的汽车有一个蓝牙 OBDII 加密狗(品牌是 Veepeak),我正在尝试编写一个可以与之通信的 Windows 应用程序。到目前为止,我似乎能够从我的笔记本电脑连接到设备、发送命令并接收某种响应,但我收到的响应并不是我所期望的。我正在使用 32feet 通信库来处理蓝牙的东西。

这是我用来连接的代码以及我用来发送消息的函数:

BluetoothClient client;
Stream stream;
client = new BluetoothClient();
Guid uuid = new Guid("00001101-0000-1000-8000-00805f9b34fb");
client.BeginConnect(SelectedDevice.DeviceAddress, uuid, bluetoothClientConnectCallback, client);

private void bluetoothClientConnectCallback(IAsyncResult result)
{
        client = (BluetoothClient)result.AsyncState;
        client.EndConnect(result);
        clientConnected = true;
        stream = client.GetStream();
        UIWriteLine("Client connected");
}

private string sendMessage(string message)
{
        byte[] encodedMessage = Encoding.ASCII.GetBytes(message);
        stream.Write(encodedMessage, 0, encodedMessage.Length);
        Thread.Sleep(100);
        int count = 0;
        byte[] buffer = new byte[1024];
        string retVal = string.Empty;
        count = stream.Read(buffer, 0, buffer.Length);
        retVal += Encoding.ASCII.GetString(buffer, 0, count);
        return retVal.Replace("\n", "");
}

private string getValue(string pid)
{
        byte[] encodedMessage = Encoding.ASCII.GetBytes(pid + "\r");
        stream.Write(encodedMessage, 0, encodedMessage.Length);
        Thread.Sleep(100);
        bool cont = true;
        int count = 0;
        byte[] buffer = new byte[1024];
        string retVal = string.Empty;
        while (cont)
        {
            count = stream.Read(buffer, 0, buffer.Length);
            retVal += Encoding.ASCII.GetString(buffer, 0, count);
            if (retVal.Contains(">"))
            {
                cont = false;
            }
        }
        return retVal.Replace("\n", "");
}

我使用 sendMessage 方法发送 AT 命令,使用 getValue 方法获取特定 PID(这些方法是从我找到的一个 OBDII 库中借用代码 here)。

当我发送 AT 命令时,我似乎只会收到我发送的任何内容的回声,而当我发送 PID 时,我会收到一个问号的响应,据我了解,这意味着该命令无效。

我的加密狗可能没有 ELM327 吗?我的蓝牙通信有问题还是我的 UUID 有问题?谢谢。

【问题讨论】:

  • 我建议您在您的 PC 上使用诸如 realterm(或任何其他 com 端口终端)之类的工具来首先验证设备是否正常运行。并验证您的设备是什么。有elm327命令查询设备描述AT@1
  • 谢谢,我现在使用 com 终端来确定我拥有的是 ELM327v1.5,它似乎工作正常。可以直接通过蓝牙流发送消息还是必须打开串口才能通信?

标签: c# obd-ii 32feet elm327


【解决方案1】:

我也有一个 Veepeak。在相关评论中强烈推荐它,并且与可用的试用应用程序和我的安卓手机配合得很好。但是,我在自己的 python 应用程序中努力初始化。

在我正在 raspi 上开发的基于 python 的应用程序上,我必须打开一个“虚拟”串行端口,该端口通过它的 mac 地址映射到之前配对的设备。 mac 地址的配对和记录是在操作系统级别使用通用蓝牙工具完成的。

【讨论】:

  • 这并没有提供问题的答案。一旦您有足够的声誉,您就可以对任何帖子发表评论;相反,提供不需要提问者澄清的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
  • 2016-10-16
  • 2014-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多