Esempio n. 1
0
 void HandleDeviceResponded(IntPtr bdAddr, IntPtr devClass, IntPtr deviceName, bool connected)
 {
     byte[] bdAddrArr;
     byte[] devClassArr;
     byte[] deviceNameArr;
     WidcommUtils.GetBluetoothCallbackValues(bdAddr, devClass, deviceName,
                                             out bdAddrArr, out devClassArr, out deviceNameArr);
     m_parent.HandleDeviceResponded(bdAddrArr, devClassArr, deviceNameArr, connected);
 }
Esempio n. 2
0
        void HandleClientStateChange(IntPtr bdAddr, IntPtr devClass,
                                     IntPtr deviceName, short com_port, SPP_STATE_CODE state)
        {
            try {
                Debug.WriteLine(string.Format(CultureInfo.InvariantCulture,
                                              "{0} HandleServerStateChange: state: {1} = 0x{2:X}, COM: {3}",
                                              DateTime.Now.TimeOfDay.ToString(),
                                              state, (int)state, com_port));
                WidcommUtils.GetBluetoothCallbackValues(bdAddr, devClass, deviceName,
                                                        out _statusBda, out _statusDevClass, out _statusName);
                _statusComPort = com_port;
                _statusState   = state;
                MemoryBarrier();
                if (state == SPP_STATE_CODE.CONNECTED)
                {
                    if (!IsSet(_waitConnect))
                    {
                        string comPort = MakePortName(_statusComPort.Value);
                        _comNum      = com_port;
                        _comPortName = comPort;
                        _waitConnect.Set();
                    }
                    else
                    {
                        Debug.WriteLine("_waitConnect already set!");
                    }
                }
                switch (state)
                {
                case SPP_STATE_CODE.CONNECTED:
                    break;

                case SPP_STATE_CODE.DISCONNECTED:
                    break;

                case SPP_STATE_CODE.RFCOMM_CONNECTION_FAILED:
                    break;

                case SPP_STATE_CODE.PORT_IN_USE:
                    break;

                case SPP_STATE_CODE.PORT_NOT_CONFIGURED:
                    break;

                case SPP_STATE_CODE.SERVICE_NOT_FOUND:
                    break;

                case SPP_STATE_CODE.ALLOC_SCN_FAILED:
                    break;

                case SPP_STATE_CODE.SDP_FULL:
                    break;

                default:
                    break;
                }
                // TODO SyncCtx.Post
                ThreadPool.QueueUserWorkItem(Event_Runner,
                                             new PortStatusChangedEventArgs(
                                                 state == SPP_STATE_CODE.CONNECTED, _comPortName, _addr));
            } catch (Exception ex) {  // Let's not kill a Widcomm thread!
                Utils.MiscUtils.Trace_WriteLine("HandleClientStateChange ex: " + ex);
            }
        }