【发布时间】:2013-12-09 17:44:09
【问题描述】:
我目前正在开发一个 Windows Phone 8 应用程序,它(希望)能够使用蓝牙 OBD-II 适配器通过蓝牙连接到车辆。我对 WP8 编程相当陌生,虽然我试图不尝试寻求帮助,但我有点想不通,也不知道去哪里或做什么。
此外,如果有人想知道我正在测试连接到汽车的设备,那就是这个人here
编辑:: 到目前为止,我已经设置了我的代码来检测蓝牙适配器是否已启用,我目前正在研究(或试图了解)如何向用户显示配对的设备,以便他们可以选择一个。但我现在的主要脑块是,如何从 OBD-II 适配器读取(或提取)数据?它在软件文档中说:
为了表示 Kiwi Wifi 或 Kiwi 蓝牙已准备好处理命令,设备将输出一个大于号 (>)。
所以如果我理解正确的话,我需要检查 > ,对吗?但是怎么做?我已经检查了大量来源,但没有一个真正解释如何。我遇到过 IBuffer 之类的东西,但我完全不了解。
如果我说的没有意义,那就简单地说。
- 从 OBD 适配器读取数据
- 向 OBD 适配器写入数据(软件文档说我需要发送 ASCII 码,我有这些)
如果我能理解如何读取/写入它,那么我认为我应该能够将数据操作回给用户;我希望。
编辑 2::
private async void checkBluetooth()
{
SolidColorBrush statuscolor = new SolidColorBrush();
try
{
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = "";
var devices = await PeerFinder.FindAllPeersAsync();
bluetoothStatus.Text = "Online";
statuscolor.Color = Colors.Green;
bluetoothStatus.Foreground = statuscolor;
if (devices.Count == 0)
{
MessageBox.Show("No paired bluetooth devices have been found, please pair your OBD adapter first!");
await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-bluetooth:"));
}
PeerInformation peerInfo = devices.FirstOrDefault(c => c.DisplayName.Contains("PLX"));
if (peerInfo == null)
{
MessageBox.Show("No paired PLX adapter found, please pair the PLX OBD adapter!");
await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-bluetooth:"));
}
StreamSocket socket = new StreamSocket();
await socket.ConnectAsync(peerInfo.HostName, "1");
await socket.ConnectAsync(peerInfo.HostName, peerInfo.ServiceName);
}
catch (Exception ex)
{
if ((uint)ex.HResult == 0x8007048F)
{
bluetoothStatus.Text = "Offline";
statuscolor.Color = Colors.Red;
bluetoothStatus.Foreground = statuscolor;
}
}
}
【问题讨论】:
-
要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是题外话,因为它们往往会吸引固执己见的答案和垃圾邮件。相反,请描述问题以及迄今为止为解决该问题所做的工作。
-
谢谢,我已经编辑了我的原始帖子。我希望它有所帮助。
-
您到底想知道什么?我相信有蓝牙通信的样本,所以你可以试试。几个月来我都有同样的想法,但没有 WP8 手机来测试它。我有 OBD 的知识,但你真正想知道什么?
-
我希望我编辑的帖子能净化一些空气,我想我还没有让它变得可以理解。我想知道如何向蓝牙 OBD 适配器读取/写入数据,以便读取车辆状态等。
-
我将在今天晚些时候有时间的时候在答案中解释它。
标签: c# windows-phone-8 bluetooth obd-ii