当前位置: 首页>>代码示例>>C#>>正文


C# DataReader.ReadDouble方法代码示例

本文整理汇总了C#中Windows.Storage.Streams.DataReader.ReadDouble方法的典型用法代码示例。如果您正苦于以下问题:C# DataReader.ReadDouble方法的具体用法?C# DataReader.ReadDouble怎么用?C# DataReader.ReadDouble使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Storage.Streams.DataReader的用法示例。


在下文中一共展示了DataReader.ReadDouble方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CollectTelemetryData

        /// <summary>
        /// Method used for the "Collection Thread"
        /// </summary>
        /// <param name="operation"></param>
        private async void CollectTelemetryData(IAsyncAction operation)
        {
            DataReader reader;
            uint unconsumedBufferLength = 0;
            lock (m_pConnectedSocket)
            {
                reader = new DataReader(m_pConnectedSocket.InputStream);
            }

            while (IsClientConnected | (unconsumedBufferLength > 0))
            {
                await m_pTelemetryReaderSemaphoreSlim.WaitAsync();
                try
                {
                    await reader.LoadAsync(sizeof (byte));
                    unconsumedBufferLength = reader.UnconsumedBufferLength;
                }
                finally
                {
                    m_pTelemetryReaderSemaphoreSlim.Release();
                }
                if (reader.UnconsumedBufferLength <= 0) continue;
                await m_pTelemetryReaderSemaphoreSlim.WaitAsync();
                try
                {
                    byte b;
                    var e = new OnTelemetryDataReceivedEventArgs();
                    b = reader.ReadByte();
                    var commandInformation = (CommandInformation) b;
                    switch (commandInformation)
                    {
                        case CommandInformation.Information:
                            await reader.LoadAsync(sizeof (uint));
                            var n = reader.ReadUInt32();
                            await reader.LoadAsync(n*sizeof (char));
                            e.CommandData = reader.ReadString(n);
                            e.CommandType = CommandInformation.Information;
                            break;
                        case CommandInformation.Gyroscope:
                            float angleX, angleY, angleZ;
                            long gyroTime;
                            await reader.LoadAsync(3*sizeof (double));
                            await reader.LoadAsync(sizeof (long));
                            angleX = Convert.ToSingle(reader.ReadDouble());
                            angleY = Convert.ToSingle(reader.ReadDouble());
                            angleZ = Convert.ToSingle(reader.ReadDouble());
                            gyroTime = reader.ReadInt64();
                            e.CommandData = new GyroscopeData()
                            {
                                Angle = new Vector3(angleX, angleY, angleZ),
                                TimeStamp = new DateTime(gyroTime)
                            };
                            e.CommandType = CommandInformation.Gyroscope;
                            break;
                        case CommandInformation.Accelerometer:
                            float accX, accY, accZ;
                            long accTime;
                            await reader.LoadAsync(3*sizeof (double));
                            await reader.LoadAsync(sizeof (long));
                            accX = Convert.ToSingle(reader.ReadDouble());
                            accY = Convert.ToSingle(reader.ReadDouble());
                            accZ = Convert.ToSingle(reader.ReadDouble());
                            accTime = reader.ReadInt64();
                            e.CommandData = new AccelerometerData()
                            {
                                Acceleration = new Vector3(accX, accY, accZ),
                                TimeStamp = new DateTime(accTime)
                            };
                            e.CommandType = CommandInformation.Accelerometer;
                            break;
                        case CommandInformation.Servo:
                            byte id, velocity;
                            long servoTime;
                            await reader.LoadAsync(2*sizeof (byte));
                            await reader.LoadAsync(sizeof (long));
                            id = reader.ReadByte();
                            velocity = reader.ReadByte();
                            servoTime = reader.ReadInt64();
                            e.CommandData = new ServoControllerData() {ServoId = id, VelocityValue = velocity, TimeStamp = new DateTime(servoTime)};
                            e.CommandType = CommandInformation.Servo;
                            break;
                    }
                    var handler = OnTelemetryDataReceived;
                    handler?.Invoke(this, e);
                }
                finally
                {
                    m_pTelemetryReaderSemaphoreSlim.Release();
                }
            }
        }
开发者ID:Hannsen94,项目名称:RaspberryCopter,代码行数:95,代码来源:Server.cs

示例2: connect

        public static async void connect()
        {
			HostName hostname = new HostName("myaustin.iptime.org");
            String servicename = "21122";
            Debug.WriteLine("Connecting");

            try
            {
                // Connect to the server (in our case the listener we created in previous step).
                await socket.ConnectAsync(hostname, servicename);

                Debug.WriteLine("Connected");

                Debug.WriteLine("onconnection start");
                DataReader reader = new DataReader(socket.InputStream);
                try
                {
                    String data = "";
                    uint stringLength = 1;
                    while (true)
                    { 
                        uint actualStringLength = await reader.LoadAsync(stringLength);
                            
                        data = reader.ReadString(actualStringLength);
                        if (data.Equals("S"))
                        {
                            uint actualdataLength = await reader.LoadAsync(4);
                            byte[] color_array = new byte[4];
                            reader.ReadBytes(color_array);
                            Color temp_color = new Color();
                            temp_color.A = color_array[0];
                            temp_color.R = color_array[1];
                            temp_color.G = color_array[2];
                            temp_color.B = color_array[3];
                            SolidColorBrush color = new SolidColorBrush(temp_color);
                            double x1,x2,y1,y2,thick;
                            var list = new List<Windows.UI.Xaml.UIElement>();
                            while (true)
                            {
                                actualStringLength = await reader.LoadAsync(1);
                                data = reader.ReadString(actualStringLength);
                                if (data.Equals("P"))
                                {
                                    actualStringLength = await reader.LoadAsync(sizeof(double) * 5);
                                    x1 = reader.ReadDouble();
                                    y1 = reader.ReadDouble();
                                    x2 = reader.ReadDouble();
                                    y2 = reader.ReadDouble();
                                    thick = reader.ReadDouble();

                                    Line l = new Line()
                                    {
                                        X1 = x1,
                                        Y1 = y1,
                                        X2 = x2,
                                        Y2 = y2,
                                        StrokeThickness = thick,
                                        Stroke = color,
                                        StrokeStartLineCap = PenLineCap.Round,
                                        StrokeEndLineCap = PenLineCap.Round,
                                        StrokeLineJoin = PenLineJoin.Round,
                                    };

                                    list.Add(l);
                                }
                                else if (data.Equals("E"))
                                {
                                    OnNetworkRecieved(list);
                                    Debug.WriteLine("Get one stroke");
                                    break;
                                }
                                else
                                    Debug.WriteLine("Expected P or E, {0} ,Network Error!!",data);
                            }
                        }
                        else
                            Debug.WriteLine("Expected S, {0} , Network Error!!",data);
                        
                    }
                }
                catch (Exception exception)
                {
                    // If this is an unknown status it means that the error is fatal and retry will likely fail.
                    if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                    {
                        throw;
                    }
                    Debug.WriteLine("Read stream failed with error: " + exception.Message);
                }

                // Mark the socket as connected. Set the value to null, as we care only about the fact that the property is set.
                //CoreApplication.Properties.Add("connected", null);
            }
            catch (Exception exception)
            {
                // If this is an unknown status it means that the error is fatal and retry will likely fail.
                if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown)
                {
                    throw;
                }
//.........这里部分代码省略.........
开发者ID:swmaestro2012,项目名称:somap312_2,代码行数:101,代码来源:Network.cs


注:本文中的Windows.Storage.Streams.DataReader.ReadDouble方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。