コード例 #1
0
        public bool DiscoverServices()
        {
            Services = null;
            bool UEIServiceFound = false;

            int Res = Client.ReadServices(wclGattOperationFlag.goReadFromDevice, out Services);

            if (Res != wclErrors.WCL_E_SUCCESS || Services == null)
            {
                return(false);
            }

            stage = 3;
            foreach (wclGattService Service in Services)
            {
                String s;
                if (Service.Uuid.IsShortUuid)
                {
                    s = Service.Uuid.ShortUuid.ToString("X4");
                }
                else
                {
                    s = Service.Uuid.LongUuid.ToString();
                }
                if (s.Equals("FFE0"))
                {
                    UEIservice      = Service;
                    UEIServiceFound = true;
                }
            }
            return(UEIServiceFound);
        }
コード例 #2
0
        private Int32 ReadCharacteristics(wclGattService Service)
        {
            // Did we already read the characteristics for given service?
            if (FCharacteristics != null)
            {
                return(wclErrors.WCL_E_SUCCESS);
            }

            Int32 Res = FClient.ReadCharacteristics(Service, wclGattOperationFlag.goNone, out FCharacteristics);

            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                return(Res);
            }
            if (FCharacteristics == null)
            {
                return(wclBluetoothErrors.WCL_E_BLUETOOTH_LE_ATTRIBUTE_NOT_FOUND);
            }

            return(wclErrors.WCL_E_SUCCESS);
        }
コード例 #3
0
ファイル: CodeFileBLE.cs プロジェクト: zuize47/rfid-demo
        void Client_OnConnect(object Sender, int Error)
        {
            CSLibrary.Debug.WriteLine("Connected");


            int Res;

            // Get Services
            FServices = null;
            Res       = Client.ReadServices(wclGattOperationFlag.goNone, out FServices);
            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                CSLibrary.Debug.WriteLine("ReadServices Error: 0x" + Res.ToString("X8"));
                return;
            }

            if (FServices == null)
            {
                return;
            }

            //CS108Service = null;
            foreach (wclGattService Service in FServices)
            {
                if (Service.Uuid.IsShortUuid)
                {
                    if (Service.Uuid.ShortUuid == 0x9800)
                    {
                        CS108Service = Service;
                    }
                }
            }

            //if (CS108Service == null)
            //    return;

            // Get Chatacteristics

            Res = Client.ReadCharacteristics(CS108Service, wclGattOperationFlag.goReadFromDevice, out FCharacteristics);
            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                CSLibrary.Debug.WriteLine("ReadCharacteristics Error: 0x" + Res.ToString("X8"));
                return;
            }

            if (FCharacteristics == null)
            {
                return;
            }

            foreach (wclGattCharacteristic Character in FCharacteristics)
            {
                String s;
                if (Character.Uuid.IsShortUuid)
                {
                    if (Character.Uuid.ShortUuid == 0x9900)
                    {
                        WriteCharacteristic = Character;
                    }
                    else if (Character.Uuid.ShortUuid == 0x9901)
                    {
                        UpdateCharacteristic = Character;
                    }
                }
            }


            Res = Client.Subscribe(UpdateCharacteristic);
            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                CSLibrary.Debug.WriteLine("Subscribe Error: 0x" + Res.ToString("X8"));
            }

            Res = Client.WriteClientConfiguration(UpdateCharacteristic, true, wclGattOperationFlag.goNone); // for library 7.3.9.0 above
            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                CSLibrary.Debug.WriteLine("WriteClientConfiguration Error: 0x" + Res.ToString("X8"));
            }

            _readerState = READERSTATE.IDLE;
            BTTimer      = new Timer(TimerFunc, this, 0, 1000);

            HardwareInit();
        }