Example #1
0
        /// <summary>
        /// 블루투스 서비스를 체크한다
        /// </summary>
        private void DoCheckBlueToothService()
        {
            try
            {
                // 파싱한 주소를 가져온다
                bluetoothAddressString = BluetoothAddress.Parse(MacAddress);

                // 컴퓨터에 블루투스가 연결되어있는지 여부를 확인 한다
                // 블루투스 장치가 켜져있지 않다면 블루투스 설정 화면을 사용자에게 안내한다
                if (!BluetoothRadio.IsSupported)
                {
                    MessageBox.Show(Device.bluetoothOffMsg, "GreenLock", MessageBoxButtons.OK);
                    Process.Start("bthprops.cpl");
                }
                // 블루투스 제어장치가 확인된다면
                else
                {
                    // 블루투스 제어장비를 초기화한다
                    bluetoothDeviceInfo = new BluetoothDeviceInfo(bluetoothAddressString);
                }

                // 모바일 기기와 연결여부를 지속적으로 체크한다
                while (true)
                {
                    // 콜백 메서드로 이동
                    IAsyncResult iAsyncResult = bluetoothDeviceInfo.BeginGetServiceRecords(uuid, Service_AsyncCallback, bluetoothDeviceInfo);

                    //이벤트 전달
                    if (OnData != null)
                    {
                        OnData(this, "");
                    }

                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                log.write("==== 통신 예외 발생 ====");
                log.write(ex.Message);
                Console.WriteLine(ex.Message + " Thread Exception!!! 1");
            }
        }
Example #2
0
        /// <summary>
        /// 블루투스 테스트를 진행한다
        /// </summary>
        private static void BlueToothTest()
        {
            try
            {
                bluetoothAddress = BluetoothAddress.Parse(MacAddress);

                // 블루투스 장치가 켜져있는지 확인한다
                while (true)
                {
                    // 장치가 켜져있지 않는경우
                    if (!BluetoothRadio.IsSupported)
                    {
                        Process.Start("bthprops.cpl");
                    }
                    // 장치가 켜져 있는 경우
                    else
                    {
                        if (bluetoothDeviceInfo == null)
                        {
                            bluetoothDeviceInfo = new BluetoothDeviceInfo(bluetoothAddress);
                        }

                        break;
                    }
                }

                // 기기가 범위안에 있는지 테스트한다 켜져있다면 블루투스 신호를 제대로 주고 받는지 테스트한다
                if (IsInRange())
                {
                    // 블루투스 신호 설정
                    iasyncResult = bluetoothDeviceInfo.BeginGetServiceRecords(uuid, ServiceAsyncCallBack, bluetoothDeviceInfo);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Example #3
0
        /// <summary>
        /// 블루투스 서비스를 체크한다
        /// </summary>
        private void DoCheckBlueToothService()
        {
            try
            {
                // 파싱한 주소를 가져온다
                bluetoothAddressString = BluetoothAddress.Parse(MacAddress);

                // 컴퓨터에 블루투스가 연결되어있는지 여부를 확인 한다
                while (true)
                {
                    // 블루투스 장치가 켜져있지 않다면 블루투스 설정 화면을 사용자에게 안내한다
                    if (!BluetoothRadio.IsSupported)
                    {
                        Process.Start("bthprops.cpl");
                        if (MessageBox.Show(Device.bluetoothOffMsg, "SSES", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                        {
                            break;
                        }
                    }
                    // 블루투스 제어장치가 확인돈다면
                    else
                    {
                        // 블루투스 제어장비를 초기화한다
                        bluetoothDeviceInfo = new BluetoothDeviceInfo(bluetoothAddressString);
                        break;
                    }
                }


                // 모바일 기기와 연결여부를 지속적으로 체크한다
                while (true)
                {
                    // 블루투스 라디오 신호가 범위안에 잡히는지 확인한다
                    if (IsInRange())
                    {
                        // 콜백 메서드로 이동
                        IAsyncResult iAsyncResult = bluetoothDeviceInfo.BeginGetServiceRecords(uuid, Service_AsyncCallback, bluetoothDeviceInfo);
                    }
                    // 잡히지 않는다면 Count 를 증가시킨다
                    else
                    {
                        log.write("==== 블루투스 라디오 범위가 넘어갔습니다 ====");
                        LockCount++;

                        // 아이폰의 경우 락카운트가 1 이상인경우 서비스 통신실패로 간주
                        if (EnumMobileModel.IOS == mobileModel)
                        {
                            int iosLockCount = 3;

                            log.write($"==== IOS 락 카운트가 {iosLockCount} 이상인 경우 서비스 통신 실패로 간주 ====");
                            if (LockCount > iosLockCount)
                            {
                                IsServiced = false;
                            }
                        }
                        // 안드로이드의 경우
                        else
                        {
                            log.write("==== 안드로이드 락 카운트가 3 이상인 경우 서비스 통신 실패로 간주 ====");
                            // 락 카운트가 3 이상인 경우 서비스 통신 실패로 간주
                            if (LockCount > 3)
                            {
                                IsServiced = false;
                            }
                        }
                    }

                    //이벤트 전달
                    if (OnData != null)
                    {
                        OnData(this, "");
                    }

                    Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                log.write("==== 통신 예외 발생 ====");
                log.write(ex.Message);
                Console.WriteLine(ex.Message + " Thread Exception!!! 1");
            }
        }