Hello everyone.
The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
Options
HoloLens Arduino Bluetooth
Hi guys,
I want to connect an Arduino using a BlueSMiRF Bluetooth module to my HoloLens.
For that puspose I found an UWP example:
https://developer.microsoft.com/en-us/windows/iot/samples/btserial
Unfortunately, it is not working, not even on the PC. The returned RfcommDeviceService is always null.
Any idea how to fix this is greatly appreciated.
jschnettker
0
Answers
I started a Unity project, to test the logic behind my app: just a sphere, and I want to manipulate it's width via Bluetooth. This example gave me another lead for finding Bluetooth devices:
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DeviceEnumerationAndPairing
In scenario two, it this sample my RN41 under Bluetooth.
Also, my custom GetDevicesAsync() function retrieves three devices, that have the same name, I gave the Bluetooth module. But it retrieves none of them, when I use a AQS, that lists all serial port rfcomm services. Therefore, I'm almost sure, that one of these devices has any type of rfcomm service, no matter, which. According to this, I implementet error handling, that when the connection to one device fails (because it has no rfcomm service), it continues with the next one.
But it seems, that this is not enough, every time I run it, I get the following output:
14 devices found
Trying to cennect with Bluetooth module
Executing TryConnectAsync
Selected device is not null.
Exception thrown: 'System.Exception' in mscorlib.ni.dll
Couldn't return RfcommService
False
Didn't break
Exception thrown: 'System.InvalidOperationException' in mscorlib.ni.dll
The program '[5608] serialinput.exe' has exited with code -1073741189 (0xc000027b).
How could I handle this error, to make it continue trying to connect to other devices? This is the code I'm currently using:
`using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
if UNITY_EDITOR
using System.IO.Ports;
elif NETFX_CORE
using Windows.Devices.Enumeration;
using System.Threading.Tasks;
using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.Rfcomm;
using Windows.Networking.Sockets;
using Windows.Storage.Streams;
using Windows.Foundation;
using System.Collections.ObjectModel;
endif
public class SizeManipulator : MonoBehaviour
{
if UNITY_EDITOR
elif NETFX_CORE
endif
if UNITY_EDITOR
elif NETFX_CORE
endif
if UNITY_EDITOR
elif NETFX_CORE
endif
if UNITY_EDITOR
elif NETFX_CORE
` deviceWatcher.Updated += handlerUpdated;
handlerRemoved = new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>((watcher, deviceInfoUpdate) =>
{
endif
if UNITY_EDITOR
elif NETFX_CORE
endif
}`
I have no idea, how to catch this errors or how to continue.
The code I use is partially form the following examples:
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DeviceEnumerationAndPairing
https://github.com/ms-iot/samples/tree/develop/BTSerial
https://code.msdn.microsoft.com/windowsapps/Bluetooth-Rfcomm-Chat-afcee559
Any help about fixing this is greatly appreciated.
Thank you in advance,
jschnettker
Hi...in my case I have been able to get this to work when my Build Platform is PC Standalone, because I am able to use the System.IO.Ports namespace and it is easy to just read the data that is sent to the SerialPort.Unfortunately, the WSA platform does not allow the use of the System.IO.Ports namespace (among many other limitations).How do I get this string of data to be sent to the game when the target platform is WSA?
You have to use RfcommDeviceService, as this is the only way to open a serial port on the Hololens.
The most important trick is to make sure, that your app has the user consent to open the Bluetooth device. This can be the user consents dialog (I had some problems there too: https://forums.hololens.com/discussion/comment/19578#Comment_19578 )
or do it manually every time you deploy your app in the "Settings->Privacy->Other devices", where you have to enable your app.
I'm not sure if you are having exactly the same problem as I was, but I found that for some reason the RfCommDeviceService would always return null when it was executed on a thread other than the UI. I managed to fix this in Unity by invoking the method where I have "RfcommDeviceService.FromIdAsync(device.Id)" on the UI thread.