无法使用Windows 7和C#建立连接

时间:2015-04-14 19:03:46

标签: c# bluetooth

简介

我收到以下错误: System.ArgumentException未处理

的HResult = -2147024809

Message =未从此类的相应异步方法返回IAsyncResult对象。

参数名称:asyncResult

来源=系统

PARAMNAME = asyncResult

堆栈跟踪:

at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.EndConnect(IAsyncResult asyncResult)
   at InTheHand.Net.Sockets.BluetoothClient.EndConnect(IAsyncResult asyncResult)
   at myApp_1.frmMT.ConnectMethod(IAsyncResult BalanceAsyncResult) in c:\xxx\Source\Workspaces\MT\MT_1\MTx_1\MTy_1\Form1.cs:line 194
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Net.ContextAwareResult.CompleteCallback(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
   at System.Net.Sockets.Socket.ConnectCallback()
   at System.Net.Sockets.Socket.RegisteredWaitCallback(Object state, Boolean timedOut)
   at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

连接:

 BluetoothClient myClient = new BluetoothClient();

char[] pinchar = new char[] { 'M', 'y', 'P', 'i', 'n' };
String pinstring = new string(pinchar);
Comments.AppendText("Device Address: " + device.DeviceAddress + NewLine);
isPaired = BluetoothSecurity.PairRequest(device.DeviceAddress, pinstring);
Comments.AppendText("isPaired?: " + isPaired.ToString() + NewLine);  // This is true!
Comments.AppendText("isAuthenticated?: " + device.Authenticated + NewLine);  // This is true!
if (isPaired)
{
     if (device.Authenticated)
     {
        //asyncconnection method
        btClient.BeginConnect(device.DeviceAddress, BluetoothService.SerialPort, new AsyncCallback(ConnectMethod), device);
        Comments.AppendText("Balance Connected? : " + btClient.Connected + NewLine); // This is false!
     }
}
            else
            {
                // pairing failed
                Comments.AppendText("Balance Pairing Failed :( (" + pinstring + ")" + NewLine);  // never get here!
            }

***就像一个FYI - 我也尝试使用mac地址和guid通过EndPoint进行连接。

Asynch方法:

private void ConnectMethod(IAsyncResult myAsyncResult)
{
    MessageBox.Show(myAsyncResult.ToString());  // This show off the method

    if (myAsyncResult.IsCompleted)  // This is true!
    {
        //  This where the error is thrown
        myClient.EndConnect(BalanceAsyncResult);  // Error here on line 194
        // Stream myStream = myClient.GetStream();  // This also fails with same error
        MessageBox.Show("Connected? : " + myClient.Connected);  // Never get here or if I do myClient.Connected is always false!
     }
}

可能的相关信息:

制造商说:

蓝牙版本:1.2

协议:L2CAP,SDP,RFCOMM

蓝牙配置文件:通用访问,服务发现,串行端口配置文件(SPP)

BT选项的作用:所有外围设备的客户端或服务器

任何帮助都非常感谢!

0 个答案:

没有答案