Mat*_*Von 4 c# bluetooth windows-phone-8 obd-ii
我目前正在开发一个Windows Phone 8应用程序,它将(希望)能够通过蓝牙使用蓝牙OBD-II适配器连接到车辆.虽然我试图不尝试并寻求帮助,但我对WP8的编程还是比较陌生的,但是我有点想到也不会想到也不知道去哪里或做什么.
此外,如果有人想知道我正在测试的设备连接到汽车那么这个人就在这里
编辑::到目前为止,我已设置我的代码来检测蓝牙适配器是否已启用,我正在调查(或试图了解)如何向用户显示配对设备,以便他们可以选择一个.但我目前的主要障碍是,我如何从OBD-II适配器读取(或拉取)数据?它在软件文档中说:
为了表示Kiwi Wifi或Kiwi蓝牙已准备好处理命令,设备将输出大于号(>).
所以如果我理解正确的话,我需要检查>,对吗?但是怎么样?我检查过很多来源,但没有一个真正解释如何.我遇到过像IBuffer这样的东西,但我完全不了解它.
如果我所说的没有意义,那么就简单地说.
如果我能理解如何读/写它,那么我认为我应该能够将数据操作回用户; 我希望.
编辑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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
Eri*_*ens 11
我只是解释了如何通过向OBD-II设备发送数据来从OBD-II设备中检索数据,因为据我所知,这是你正在努力解决的问题.
OBD-II永远不会自己发送数据,它会监听您发送的命令,并根据该命令发送答案.所以如果你有一个正在运行的连接,基本上你必须做两件事:
您已将ASCII命令转换为电压的ELM327-bluetooth-connector.所以你要做的就是发送一些ASCII命令,然后你得到ASCII值.
OBD协议知道几种模式和参数,但我会解释获取实时数据.这是模式1.
模式1发送
模式1为'01'.在那部分之后,你必须用它发送一个参数ID.0C表示RPM,0D表示速度.在每个命令之后你必须发送回车.(CR ='\ r')因此连接器知道请求何时完成.
所以基本上,为了速度,你必须发送:
'010D\r'
Run Code Online (Sandbox Code Playgroud)
接收模式1
您将从模式1查询中获得的答案以"41"开头.之后返回参数ID,然后返回值.该值大部分时间为十六进制.您将不得不进行一些转换以读取人类可读的值.有关更多信息,请参阅链接,因为也提供了要转换的公式.
例:
'410D17'
Run Code Online (Sandbox Code Playgroud)
所以17是你当前十六进制速度的值.17到十进制是23,所以你以23公里/小时的速度行驶.
这个维基百科页面有一些很好的信息:
OBD-II参数
而对于蓝牙部分:
第1步:通过RFCOMM连接到所需的设备
PeerFinder.AlternateIdentities["Bluetooth:PAIRED"] = "";
var available_devices = await PeerFinder.FindAllPeersAsync();
if (available_devices.Count == 0)
{
return false;
}
else
{
PeerInformation pi= // Get the required device using
// index or searching for the device name
}
StreamSocket socket = new StreamSocket();
await socket.ConnectAsync(pi.HostName, "1");
Run Code Online (Sandbox Code Playgroud)
第2步:直接winsock执行SPP查找
await socket.ConnectAsync(pi.HostName, pi.ServiceName);
Run Code Online (Sandbox Code Playgroud)
我希望这会帮助你,我对它感到兴奋.^^如果您需要帮助,请告诉我.
| 归档时间: |
|
| 查看次数: |
23208 次 |
| 最近记录: |