티스토리 뷰

C#

블루투스 동글을 이용한 PC Lock

David_Kim 2016. 10. 26. 23:47
반응형
https://32feet.codeplex.com/

이 사이트가 C#에서 블루투스에 관한 라이브러리를 제공해줌.

Nuget패키지에 32feet로 참조하거나 위의 사이트에서 zip파일을 다운받아서 참조하면 된다.(3.5가 표준인데 밑의 코드는 3.7버전을 씀)

Peer장치의 정보와 Local장치의 정보, RSSI(Received Signal Strength Indication)등등 여러가지 정보를 가져올 수 있다.


이 라이브러리를 이용해서 PC에 블루투스 동글을 꽂아 핸드폰을 키로 사용하는 프로그램을 짜볼까한다.


라이브러리 라이센스에 관한 내용은 하단 URL참고!

https://32feet.codeplex.com/license


using InTheHand.Net.Bluetooth;

using InTheHand.Net.Sockets;

using System;

 

namespace 테스트3

{

    class Program

    {

        static void Main(string[] args)

        {

            BluetoothClient bluetoothClient = new BluetoothClient();

            var devices = bluetoothClient.DiscoverDevices();

 

            Console.WriteLine("Bluetooth devices");

            /*Local devices Infomation*/

            foreach (var device in devices)

            {

                var blueToothInfo = string.Format("- DeviceName: {0}{1}  Connected: {2}{1}  Address: {3:C}{1}  Last seen: {4}{1}  Last used: {5}{1}",

                          device.DeviceName, Environment.NewLine, device.Connected, device.DeviceAddress, device.LastSeen.ToLocalTime(),

                        device.LastUsed);

                blueToothInfo += string.Format("- Class of device{0}   Device: {1}{0}   Major Device: {2}{0}   Service: {3}",

                       Environment.NewLine, device.ClassOfDevice.Device, device.ClassOfDevice.MajorDevice,

                       device.ClassOfDevice.Service);

                int rssi = device.Rssi;

                Console.WriteLine(blueToothInfo);

                Console.WriteLine("-------------------------");

                Console.WriteLine("RSSI : {0}", rssi);

                Console.WriteLine("-------------------------");

                DisplayBluetoothRadio();

            }

            Console.ReadLine();

        }

        /// <summary>

        /// Peer devices Infomation

        /// </summary>

        static void DisplayBluetoothRadio()

        {

            BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio;

            if (myRadio == null)

            {

                Console.WriteLine("No radio hardware or unsupported software stack");

                return;

            }

            RadioMode mode = myRadio.Mode;

            // Warning: LocalAddress is null if the radio is powered-off.           

            Console.WriteLine("* Radio, address: {0:C}", myRadio.LocalAddress);

            Console.WriteLine("Mode: " + mode.ToString());

            Console.WriteLine("Name: " + myRadio.Name);

            Console.WriteLine("HCI Version: " + myRadio.HciVersion

                + ", Revision: " + myRadio.HciRevision);

            Console.WriteLine("LMP Version: " + myRadio.LmpVersion

                + ", Subversion: " + myRadio.LmpSubversion);

            Console.WriteLine("ClassOfDevice: " + myRadio.ClassOfDevice.ToString()

                + ", device: " + myRadio.ClassOfDevice.Device.ToString()

                + " / service: " + myRadio.ClassOfDevice.Service.ToString());

           

            // Enable discoverable mode

            Console.WriteLine();

            myRadio.Mode = RadioMode.Discoverable;

            Console.WriteLine("Radio Mode now: " + myRadio.Mode.ToString());

        }

    }

}



-70이하면 신호상태가 좋은 편이고, -100이상(-값이 커지면)이면 나쁜 편이다. 하지만 블루투스 자체가 간선의 영향을 많이 받아서 다소 실망스러운 값이 나올 수도 있다.

일단 값들 불러오는건 이렇게 하면 되고, 차차 인가받은 폰이 블루투스 동글과의 기준거리에서 벗어나면 락이 걸리는 것도 올리겠다.


실행화면




반응형

'C#' 카테고리의 다른 글

C#(.Net)에서Global Mouse Hook(전역 마우스 후크/후킹)  (1) 2016.07.06
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함