亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專(zhuān)輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? gps.cs

?? GPSmobile2005開(kāi)發(fā)的例子,串口讀取GPS數(shù)據(jù)
?? CS
字號(hào):
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
using System;
using System.Runtime.InteropServices;
using System.Collections;
using System.Text;


namespace Microsoft.WindowsMobile.Samples.Location
{
    public delegate void LocationChangedEventHandler(object sender, LocationChangedEventArgs args);
    public delegate void DeviceStateChangedEventHandler(object sender, DeviceStateChangedEventArgs args);

    /// <summary>
    /// Summary description for GPS.
    /// </summary>
    public class Gps
    {
        // handle to the gps device
        IntPtr gpsHandle = IntPtr.Zero;

        // handle to the native event that is signalled when the GPS
        // devices gets a new location
        IntPtr newLocationHandle = IntPtr.Zero;

        // handle to the native event that is signalled when the GPS
        // device state changes
        IntPtr deviceStateChangedHandle = IntPtr.Zero;

        // handle to the native event that we use to stop our event
        // thread
        IntPtr stopHandle = IntPtr.Zero;

        // holds our event thread instance
        System.Threading.Thread gpsEventThread = null;


        event LocationChangedEventHandler locationChanged;

        /// <summary>
        /// Event that is raised when the GPS locaction data changes
        /// </summary>
        public event LocationChangedEventHandler LocationChanged
        {
            add
            {
                locationChanged += value;

                // create our event thread only if the user decides to listen
                CreateGpsEventThread();
            }
            remove
            {
                locationChanged -= value;
            }
        }


        event DeviceStateChangedEventHandler deviceStateChanged;

        /// <summary>
        /// Event that is raised when the GPS device state changes
        /// </summary>
        public event DeviceStateChangedEventHandler DeviceStateChanged
        {
            add
            {
                deviceStateChanged += value;

                // create our event thread only if the user decides to listen
                CreateGpsEventThread();
            }
            remove
            {
                deviceStateChanged -= value;
            }
        }

        /// <summary>
        /// True: The GPS device has been opened. False: It has not been opened
        /// </summary>
        public bool Opened
        {
            get { return gpsHandle != IntPtr.Zero; }
        }

        public Gps()
        {
        }

        ~Gps()
        {
            // make sure that the GPS was closed.
            Close();
        }

        /// <summary>
        /// Opens the GPS device and prepares to receive data from it.
        /// </summary>
        public void Open()
        {
            if (!Opened)
            {
                // create handles for GPS events
                newLocationHandle = CreateEvent(IntPtr.Zero, 0, 0, null);
                deviceStateChangedHandle = CreateEvent(IntPtr.Zero, 0, 0, null);
                stopHandle = CreateEvent(IntPtr.Zero, 0, 0, null);

                gpsHandle = GPSOpenDevice(newLocationHandle, deviceStateChangedHandle, null, 0);

                // if events were hooked up before the device was opened, we'll need
                // to create the gps event thread.
                if (locationChanged != null || deviceStateChanged != null)
                {
                    CreateGpsEventThread();
                }
            }
        }

        /// <summary>
        /// Closes the gps device.
        /// </summary>
        public void Close()
        {
            if (gpsHandle != IntPtr.Zero)
            {
                GPSCloseDevice(gpsHandle);
                gpsHandle = IntPtr.Zero;
            }

            // Set our native stop event so we can exit our event thread.
            if (stopHandle != IntPtr.Zero)
            {
                EventModify(stopHandle, eventSet);
            }

            // block until our event thread is finished before
            // we close our native event handles
            lock (this)
            {
                if (newLocationHandle != IntPtr.Zero)
                {
                    CloseHandle(newLocationHandle);
                    newLocationHandle = IntPtr.Zero;
                }

                if (deviceStateChangedHandle != IntPtr.Zero)
                {
                    CloseHandle(deviceStateChangedHandle);
                    deviceStateChangedHandle = IntPtr.Zero;
                }

                if (stopHandle != IntPtr.Zero)
                {
                    CloseHandle(stopHandle);
                    stopHandle = IntPtr.Zero;
                }
            }
        }

        /// <summary>
        /// Get the position reported by the GPS receiver
        /// </summary>
        /// <returns>GpsPosition class with all the position details</returns>
        public GpsPosition GetPosition()
        {
            return GetPosition(TimeSpan.Zero);
        }


        /// <summary>
        /// Get the position reported by the GPS receiver that is no older than
        /// the maxAge passed in
        /// </summary>
        /// <param name="maxAge">Max age of the gps position data that you want back. 
        /// If there is no data within the required age, null is returned.  
        /// if maxAge == TimeSpan.Zero, then the age of the data is ignored</param>
        /// <returns>GpsPosition class with all the position details</returns>
        public GpsPosition GetPosition(TimeSpan maxAge)
        {
            GpsPosition gpsPosition = null;
            if (Opened)
            {
                // allocate the necessary memory on the native side.  We have a class (GpsPosition) that 
                // has the same memory layout as its native counterpart
                IntPtr ptr = Utils.LocalAlloc(Marshal.SizeOf(typeof(GpsPosition)));

                // fill in the required fields 
                gpsPosition = new GpsPosition();
                gpsPosition.dwVersion = 1;
                gpsPosition.dwSize = Marshal.SizeOf(typeof(GpsPosition));

                // Marshal our data to the native pointer we allocated.
                Marshal.StructureToPtr(gpsPosition, ptr, false);

                // call native method passing in our native buffer
                int result = GPSGetPosition(gpsHandle, ptr, 500000, 0);
                if (result == 0)
                {
                    // native call succeeded, marshal native data to our managed data
                    gpsPosition = (GpsPosition)Marshal.PtrToStructure(ptr, typeof(GpsPosition));

                    if (maxAge != TimeSpan.Zero)
                    {
                        // check to see if the data is recent enough.
                        if (!gpsPosition.TimeValid || DateTime.Now - maxAge > gpsPosition.Time)
                        {
                            gpsPosition = null;
                        }
                    }
                }

                // free our native memory
                Utils.LocalFree(ptr);
            }

            return gpsPosition;            
        }

        /// <summary>
        /// Queries the device state.
        /// </summary>
        /// <returns>Device state information</returns>
        public GpsDeviceState GetDeviceState()
        {
            GpsDeviceState device = null;

            // allocate a buffer on the native side.  Since the
            IntPtr pGpsDevice = Utils.LocalAlloc(GpsDeviceState.GpsDeviceStructureSize);
            
            // GPS_DEVICE structure has arrays of characters, it's easier to just
            // write directly into memory rather than create a managed structure with
            // the same layout.
            Marshal.WriteInt32(pGpsDevice, 1);	// write out GPS version of 1
            Marshal.WriteInt32(pGpsDevice, 4, GpsDeviceState.GpsDeviceStructureSize);	// write out dwSize of structure

            int result = GPSGetDeviceState(pGpsDevice);

            if (result == 0)
            {
                // instantiate the GpsDeviceState class passing in the native pointer
                device = new GpsDeviceState(pGpsDevice);
            }

            // free our native memory
            Utils.LocalFree(pGpsDevice);

            return device;
        }

        /// <summary>
        /// Creates our event thread that will receive native events
        /// </summary>
        private void CreateGpsEventThread()
        {
            // we only want to create the thread if we don't have one created already 
            // and we have opened the gps device
            if (gpsEventThread == null && gpsHandle != IntPtr.Zero)
            {
                // Create and start thread to listen for GPS events
                gpsEventThread = new System.Threading.Thread(new System.Threading.ThreadStart(WaitForGpsEvents));
                gpsEventThread.Start();
            }
        }

        /// <summary>
        /// Method used to listen for native events from the GPS. 
        /// </summary>
        private void WaitForGpsEvents()
        {
            lock (this)
            {
                bool listening = true;
                // allocate 3 handles worth of memory to pass to WaitForMultipleObjects
                IntPtr handles = Utils.LocalAlloc(12);

                // write the three handles we are listening for.
                Marshal.WriteInt32(handles, 0, stopHandle.ToInt32());
                Marshal.WriteInt32(handles, 4, deviceStateChangedHandle.ToInt32());
                Marshal.WriteInt32(handles, 8, newLocationHandle.ToInt32());

                while (listening)
                {
                    int obj = WaitForMultipleObjects(3, handles, 0, -1);
                    if (obj != waitFailed)
                    {
                        switch (obj)
                        {
                            case 0:
                                // we've been signalled to stop
                                listening = false;
                                break;
                            case 1:
                                // device state has changed
                                if (deviceStateChanged != null)
                                {
                                    deviceStateChanged(this, new DeviceStateChangedEventArgs(GetDeviceState()));
                                }
                                break;
                            case 2:
                                // location has changed
                                if (locationChanged != null)
                                {
                                    locationChanged(this, new LocationChangedEventArgs(GetPosition()));
                                }
                                break;
                        }
                    }
                }

                // free the memory we allocated for the native handles
                Utils.LocalFree(handles);

                // clear our gpsEventThread so that we can recreate this thread again
                // if the events are hooked up again.
                gpsEventThread = null;
            }
        }

        #region PInvokes to gpsapi.dll
        [DllImport("gpsapi.dll")]
        static extern IntPtr GPSOpenDevice(IntPtr hNewLocationData, IntPtr hDeviceStateChange, string szDeviceName, int dwFlags);

        [DllImport("gpsapi.dll")]
        static extern int  GPSCloseDevice(IntPtr hGPSDevice);

        [DllImport("gpsapi.dll")]
        static extern int  GPSGetPosition(IntPtr hGPSDevice, IntPtr pGPSPosition, int dwMaximumAge, int dwFlags);

        [DllImport("gpsapi.dll")]
        static extern int  GPSGetDeviceState(IntPtr pGPSDevice);
        #endregion

        #region PInvokes to coredll.dll
        [DllImport("coredll.dll")]
        static extern IntPtr CreateEvent(IntPtr lpEventAttributes, int bManualReset, int bInitialState, StringBuilder lpName);

        [DllImport("coredll.dll")]
        static extern int CloseHandle(IntPtr hObject);

        const int waitFailed = -1;
        [DllImport("coredll.dll")]
        static extern int WaitForMultipleObjects(int nCount, IntPtr lpHandles, int fWaitAll, int dwMilliseconds);

        const int eventSet = 3;
        [DllImport("coredll.dll")]
        static extern int EventModify(IntPtr hHandle, int dwFunc);
        
#endregion

    }
}

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩中文字幕1| 日韩精品一二区| 欧美日本一道本| 国产精品综合二区| 亚洲一区二区三区四区在线| 欧美xxxx老人做受| 色综合久久久久久久| 国模冰冰炮一区二区| 亚洲综合网站在线观看| 国产色产综合色产在线视频| 欧美精品18+| 91在线精品秘密一区二区| 国产真实精品久久二三区| 亚洲韩国一区二区三区| 国产精品电影一区二区三区| 欧美va亚洲va在线观看蝴蝶网| 欧美主播一区二区三区| 国产成都精品91一区二区三| 色欧美88888久久久久久影院| 国产激情精品久久久第一区二区| 日日夜夜免费精品| 一区二区三区在线播| 中文字幕一区二区三区av| 精品国产一区二区精华| 88在线观看91蜜桃国自产| 色中色一区二区| 成人成人成人在线视频| 国产综合色在线| 久久国产夜色精品鲁鲁99| 亚洲一级在线观看| 一级日本不卡的影视| 综合久久给合久久狠狠狠97色 | 精品亚洲成a人在线观看| 亚洲少妇最新在线视频| 在线国产亚洲欧美| 99国产欧美另类久久久精品 | 97se亚洲国产综合自在线观| 国产久卡久卡久卡久卡视频精品| 另类小说综合欧美亚洲| 美女网站色91| 精品一区二区久久| 久久成人av少妇免费| 乱一区二区av| 极品少妇xxxx精品少妇| 国内精品久久久久影院色| 激情文学综合丁香| 国产电影一区二区三区| 国产xxx精品视频大全| 成人综合在线观看| 成人av免费在线播放| 大白屁股一区二区视频| 成人黄色片在线观看| 99re在线精品| 91精品福利视频| 欧美日韩国产a| 日韩一级大片在线| 久久综合九色欧美综合狠狠| 国产亚洲短视频| 国产精品电影院| 亚洲激情男女视频| 婷婷丁香激情综合| 久久99精品国产.久久久久久| 美国欧美日韩国产在线播放| 国产一区久久久| 一本在线高清不卡dvd| 欧美日韩成人高清| 精品国产一区二区三区忘忧草| 久久精品一区二区三区av| 中文字幕一区二区三区乱码在线| 亚洲一区二区三区精品在线| 日本va欧美va精品| 国产成人午夜视频| 在线看国产一区| 日韩小视频在线观看专区| 国产欧美一区二区三区沐欲| 1000部国产精品成人观看| 午夜视频在线观看一区二区三区| 理论片日本一区| 99久久婷婷国产| 4hu四虎永久在线影院成人| 国产日韩欧美不卡在线| 亚洲激情自拍偷拍| 久久精品国产精品亚洲精品| 成人综合激情网| 欧美日韩一区二区三区不卡| 久久综合一区二区| 夜夜嗨av一区二区三区网页| 久久成人av少妇免费| 日本黄色一区二区| 欧美精品一区二区三区很污很色的 | 久久久久久久精| 一区二区欧美国产| 国产精品白丝av| 欧美日本在线观看| 国产精品久久久久一区二区三区共| 性欧美疯狂xxxxbbbb| 国产99精品视频| 日韩一区二区三区在线| 亚洲欧美激情在线| 国产精品系列在线播放| 911国产精品| 亚洲精品欧美在线| 国产99久久久国产精品免费看| 538在线一区二区精品国产| 亚洲欧洲精品一区二区精品久久久| 毛片一区二区三区| 欧美在线|欧美| 国产精品人妖ts系列视频| 久久精品国产成人一区二区三区| 91国模大尺度私拍在线视频| 中文字幕av免费专区久久| 久久99深爱久久99精品| 欧美丰满少妇xxxxx高潮对白| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 亚洲成人综合在线| 成人免费毛片嘿嘿连载视频| 日韩午夜在线观看视频| 亚洲成人免费av| 在线精品国精品国产尤物884a| 国产精品色婷婷| 国产精品香蕉一区二区三区| 精品国产亚洲一区二区三区在线观看| 亚洲国产成人91porn| 色88888久久久久久影院野外| 国产精品免费久久| 国产福利精品一区| 久久久777精品电影网影网| 蜜桃一区二区三区在线| 欧美一区二区视频观看视频| 午夜电影网亚洲视频| 欧美无砖专区一中文字| 亚洲国产va精品久久久不卡综合 | 欧美草草影院在线视频| 日韩精品一卡二卡三卡四卡无卡| 欧美性一二三区| 亚洲一区在线观看免费| 日本电影欧美片| 一个色综合av| 欧美日韩国产免费一区二区| 亚洲小说欧美激情另类| 欧美日韩在线播放| 天堂av在线一区| 91精品国产色综合久久| 卡一卡二国产精品| 久久亚洲二区三区| 国产69精品久久777的优势| 欧美韩日一区二区三区| 99久久er热在这里只有精品15| 成人免费在线播放视频| 在线视频中文字幕一区二区| 亚洲电影一区二区三区| 欧美一区二区三区在线观看 | 高清在线成人网| 一色屋精品亚洲香蕉网站| 91福利在线播放| 婷婷中文字幕一区三区| 精品国精品国产| 国产+成+人+亚洲欧洲自线| 国产精品久久久久精k8| 欧美天堂一区二区三区| 日本美女一区二区三区视频| 久久蜜桃av一区精品变态类天堂| 成熟亚洲日本毛茸茸凸凹| 一区二区三区中文在线| 91精品国产aⅴ一区二区| 国产曰批免费观看久久久| 国产精品美女久久久久aⅴ| 在线观看成人小视频| 美女视频免费一区| 国产精品国产馆在线真实露脸| 91成人免费在线| 久久精品国产99久久6| 中文字幕亚洲不卡| 91精品国产黑色紧身裤美女| 国产福利91精品一区二区三区| 亚洲激情校园春色| 久久这里只有精品首页| 99久久99精品久久久久久| 日韩av一区二区三区| 国产精品色呦呦| 日韩一区二区三区电影| av电影在线观看一区| 青青草97国产精品免费观看无弹窗版| 国产午夜亚洲精品理论片色戒| 在线观看免费视频综合| 韩国欧美国产1区| 亚洲国产综合人成综合网站| 久久综合狠狠综合久久激情| 在线观看成人免费视频| 国产91丝袜在线播放0| 亚洲一本大道在线| 国产精品久久久99| 精品少妇一区二区三区在线视频| 91小视频在线| 国产在线麻豆精品观看| 亚洲成a人v欧美综合天堂下载 | 国产精品国产三级国产普通话三级| 欧美精品1区2区| 91高清在线观看| 成人精品免费网站|