I am currently working on a Windows Phone 8 application, which will (hopefully) have the capabilities to connect to a vehicle via bluetooth using a bluetooth OBD-II adapter. I'm reasonably new to programming for WP8, although I'm attempting to not try and to ask for help but I've sort of hit a part where I just can't think nor understand where to go or what to do.
Additionally, if anyone wants to know the device I'm testing with to connect to the car it's this guy here
EDIT:: So far I have set my code to detect if the Bluetooth adapter is enabled, I'm currently looking into (or trying to understand) how can I display to the user the paired devices so they can select one. But my main brain block at the moment is, how I can read (or pull) data from the OBD-II adapter? It says in the software documentation this:
To signify that the Kiwi Wifi or Kiwi Bluetooth is ready to process commands, the device will output a greater-than sign (>).
So if I've understood this correctly, I would need to check for > , right? But how? I've checked loads of sources but none really explain how. I came across stuff like IBuffer, but I have no understanding of that at all.
If what I've said makes no sense, then simply put.
- Read data from OBD addapter
- Write data to OBD adapter (The software documentation says I need to send ASCII code, I've got those)
If I can understand how to read/write to it, then I think I should be capable of manipulating the data back to the user; I hope.
EDIT 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;
}
}
}