I wrote a wrapper for RadioRemotePair and GetRemotePair. I run RadioRemotePair only if the device is not already paired.
It seems like the pairing is working, but when I afterwards run "connect", the device successfully connects, but then instantly responds with "0X00030008 WCL_E_CONNECTION_CLOSED".
I realize it is probably difficult to say what could cause this without knowing more about the device, but do you have any ideas?
I am using WCL-for-unity from 2019-11-18.
See some code snippets from below.
__declspec(dllexport) int __stdcall RadioRemotePair(CwclBluetoothRadio* Radio, __int64 Address)
{
if (Radio == NULL)
return WCL_E_INVALID_ARGUMENT;
return Radio->RemotePair(Address);
}
__declspec(dllexport) bool __stdcall GetRemotePaired(CwclBluetoothRadio* Radio, __int64 Address)
{
if (Radio == NULL)
return WCL_E_INVALID_ARGUMENT;
bool paired = false;
Radio->GetRemotePaired(Address, paired);
return paired;
}
private void FManager_OnDeviceFound(System.Object sender, IntPtr Radio, long Address)
{
try
{
if (MyGameConfigs.getAvaialablePoXAdresses().Contains(Address))
{
UnityEngine.Debug.Log("Checking is pox paired " + Address.ToString("X12"));
if (FManager.IsRemotePaired(Radio, Address) == false)
{
UnityEngine.Debug.Log("Pairing to pox " + Address.ToString("X12"));
Int32 Res1 = FManager.RemotePair(Radio, Address);
if (Res1 != BluetoothErrors.WCL_E_SUCCESS)
{
UnityEngine.Debug.Log("Failed to pair: 0x" + Res1.ToString("X8"));
} else
{
UnityEngine.Debug.Log("Pox successfully paired " + Address.ToString("X12"));
}
} else
{
UnityEngine.Debug.Log("Pox is already paired " + Address.ToString("X12"));
}
UnityEngine.Debug.Log("Connecting to pox " + Address.ToString("X12"));
Int32 Res = FClientPox.Connect(Radio, Address);
if (Res != BluetoothErrors.WCL_E_SUCCESS)
{
UnityEngine.Debug.Log("Failed to connect: 0x" + Res.ToString("X8"));
}
}
}
catch (Exception ex)
{
UnityEngine.Debug.Log("Something went wrong with connecting to the device!");
UnityEngine.Debug.LogError(ex.Message);
}
}