當前位置: 首頁>>代碼示例>>C#>>正文


C# DataReader.ReadByte方法代碼示例

本文整理匯總了C#中Windows.Storage.Streams.DataReader.ReadByte方法的典型用法代碼示例。如果您正苦於以下問題:C# DataReader.ReadByte方法的具體用法?C# DataReader.ReadByte怎麽用?C# DataReader.ReadByte使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.Storage.Streams.DataReader的用法示例。


在下文中一共展示了DataReader.ReadByte方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: readUint16TI

        /// <summary>
        /// Reads a 16-bit unsigned integer
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private static long readUint16TI(DataReader reader)
        {
            uint ObjLSB = reader.ReadByte();
            var ObjMSB = (int)reader.ReadByte();

            var result = (ObjMSB << 8) + ObjLSB;
            return result;
        }
開發者ID:modulexcite,項目名稱:events,代碼行數:13,代碼來源:TI_BLESensorTagCharacteristicParsers.cs

示例2: onewireReset

        async Task<bool> onewireReset(string deviceId)
        {
            try
            {
                if (serialPort != null)
                    serialPort.Dispose();

                serialPort = await SerialDevice.FromIdAsync(deviceId);

                // Configure serial settings
                serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
                serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
                serialPort.BaudRate = 9600;
                serialPort.Parity = SerialParity.None;
                serialPort.StopBits = SerialStopBitCount.One;
                serialPort.DataBits = 8;
                serialPort.Handshake = SerialHandshake.None;

                dataWriteObject = new DataWriter(serialPort.OutputStream);
                dataWriteObject.WriteByte(0xF0);
                await dataWriteObject.StoreAsync();

                dataReaderObject = new DataReader(serialPort.InputStream);
                await dataReaderObject.LoadAsync(1);
                byte resp = dataReaderObject.ReadByte();
                if (resp == 0xFF)
                {
                    System.Diagnostics.Debug.WriteLine("Nothing connected to UART");
                    return false;
                }
                else if (resp == 0xF0)
                {
                    System.Diagnostics.Debug.WriteLine("No 1-wire devices are present");
                    return false;
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Response: " + resp);
                    serialPort.Dispose();
                    serialPort = await SerialDevice.FromIdAsync(deviceId);

                    // Configure serial settings
                    serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000);
                    serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000);
                    serialPort.BaudRate = 115200;
                    serialPort.Parity = SerialParity.None;
                    serialPort.StopBits = SerialStopBitCount.One;
                    serialPort.DataBits = 8;
                    serialPort.Handshake = SerialHandshake.None;
                    dataWriteObject = new DataWriter(serialPort.OutputStream);
                    dataReaderObject = new DataReader(serialPort.InputStream);
                    return true;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
                return false;
            }
        }
開發者ID:selomkofori,項目名稱:ds18b20_win10iot,代碼行數:60,代碼來源:OneWire.cs

示例3: StreamReadLine

 private static async Task<String> StreamReadLine(DataReader reader) {
     int next_char;
     String data = "";
     while (true) {
         await reader.LoadAsync(1);
         next_char = reader.ReadByte();
         if (next_char == '\n') { break; }
         if (next_char == '\r') { continue; }
         data += Convert.ToChar(next_char);
     }
     return data;
 }
開發者ID:nikita-afonasov,項目名稱:WinPhone8Driver,代碼行數:12,代碼來源:AcceptedRequest.cs

示例4: OnConnection

        static async void OnConnection(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            try
            {
                if (IsRobot)
                {
                    DataReader reader = new DataReader(args.Socket.InputStream);
                    String str = "";
                    while (true)
                    {
                        uint len = await reader.LoadAsync(1);
                        if (len > 0)
                        {
                            byte b = reader.ReadByte();
                            str += Convert.ToChar(b);
                            if (b == '.')
                            {
                                Debug.WriteLine("Network Received: '{0}'", str);
                                //Controllers.ParseCtrlMessage(str);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    String lastStringSent;
                    while (true)
                    {
                        DataWriter writer = new DataWriter(args.Socket.OutputStream);
                        lastStringSent = ctrlStringToSend;
                        writer.WriteString(lastStringSent);
                        await writer.StoreAsync();
                        msLastSendTime = Stopwatch.ElapsedMilliseconds;

                        // re-send periodically
                        long msStart = Stopwatch.ElapsedMilliseconds;
                        for (; ;)
                        {
                            long msCurrent = Stopwatch.ElapsedMilliseconds;
                            if ((msCurrent - msStart) > 3000) break;
                            if (lastStringSent.CompareTo(ctrlStringToSend) != 0) break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("OnConnection() - " + e.Message);
            }
        }
開發者ID:LeighCurran,項目名稱:IoTExamples,代碼行數:51,代碼來源:NetworkService.cs

示例5: OnConnection

        private async void OnConnection(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
        {
            try
            {

                DataReader reader = new DataReader(args.Socket.InputStream);
                String str = "";
                while (true)
                {
                    uint len = await reader.LoadAsync(1);
                    if (len > 0)
                    {
                        byte b = reader.ReadByte();
                        str += Convert.ToChar(b);
                        
                        if (b == '.')
                        {
                            //Debug.WriteLine("Network Received: '{0}'", str);
                            //Controllers.ParseCtrlMessage(str);

                            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                txbReceived.Text = str;
                            });


                            DataWriter writer = new DataWriter(socket.OutputStream);
                            writer.WriteString(String.Format("Received the following: {0}", str));
                            await writer.StoreAsync();
                            


                            str = string.Empty;
                            break;
                        }
                        
                        

                    }
                        
                }

            }
            catch (Exception e)
            {
                Debug.WriteLine("OnConnection() - " + e.Message);
            }
        }
開發者ID:QQOak,項目名稱:NetworkSockets,代碼行數:48,代碼來源:MainPage.xaml.cs

示例6: readLine

        // Read in bytes one at a time until we get a newline, then return the whole line
        private async Task<string> readLine(DataReader input)
        {
            string line = "";
            char a = ' ';
            // Keep looping as long as we haven't hit a newline OR line is empty
            while ((a != '\n' && a != '\r') || line.Length == 0 )
            {
                // Wait until we have 1 byte available to read
                await input.LoadAsync(1);
                // Read that one byte, typecasting it as a char
                a = (char)input.ReadByte();

                // If the char is a newline or a carriage return, then don't add it on to the line and quit out
                if( a != '\n' && a != '\r' )
                    line += a;
            }

            // Return the string we've built
            return line;
        }
開發者ID:EE590-Spring2014,項目名稱:Materials,代碼行數:21,代碼來源:MainPage.xaml.cs

示例7: OnConnection

 static async void OnConnection(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
 {
     try
     {
         DataReader reader = new DataReader(args.Socket.InputStream);
         while (true)
         {
             uint len = await reader.LoadAsync(1);
             if (len > 0)
             {
                 byte b = reader.ReadByte();
                 Debug.WriteLine("Network Received: '{0}'", Convert.ToString(b,2));
                 MainPage.SendCommand(b);
                 //break;
             }
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine("OnConnection() - " + e.Message);
     }
 }
開發者ID:NejTech,項目名稱:Ingenuity,代碼行數:22,代碼來源:NetworkCmd.cs

示例8: DoNextRead

        private void DoNextRead(byte[] blob)
        {
            DataReader reader = new DataReader(_socket.InputStream);
            reader.InputStreamOptions = InputStreamOptions.Partial;

            var task = Task.Run(() =>
            {
                try
                {
                    reader.LoadAsync((uint)blob.Length).AsTask().Wait();
                    uint bytesRead = 0;
                    while(reader.UnconsumedBufferLength > 0)
                    {
                        blob[bytesRead++] = reader.ReadByte();
                    }

                    if(bytesRead > 0)
                    {
                        OnReceive(blob, bytesRead);
                    }
                }
                catch(Exception)
                {
                }
                finally
                {
                    reader.DetachStream();
                    reader.Dispose();
                }
            });
        }
開發者ID:visual14ph,項目名稱:f1livetiming,代碼行數:31,代碼來源:W8ConnectionDriver.cs

示例9: _serialDevice_PinChanged

        private void _serialDevice_PinChanged(SerialDevice sender, PinChangedEventArgs args)
        {
            if (args.PinChange != SerialPinChange.RingIndicator) return;
            _dataReaderObject = new DataReader(_serialDevice.InputStream)
            {
                InputStreamOptions = InputStreamOptions.Partial
            };
            byte response = _dataReaderObject.ReadByte();
            _dataReaderObject.DetachStream();
            _dataReaderObject = null;

            HandleResponse(response);
        }
開發者ID:RodneyWimberly,項目名稱:X10SerialSlave,代碼行數:13,代碼來源:CM11AServer.cs

示例10: OnPerformAction

        private async void OnPerformAction()
        {
            var stream = socket.OutputStream;
            using (var writer = new DataWriter(stream))
            {
                writer.ByteOrder = ByteOrder.LittleEndian;
                //writer.WriteInt16(6);
                //writer.WriteByte(0x00);
                //writer.WriteByte(3);
                //writer.WriteUInt16(1500);
                //writer.WriteUInt16(1000);

                //var bytes = new byte[] { 6, 0, 0, 3, 220, 5, 232, 3 };
                //writer.WriteBytes(bytes);

                writer.WriteInt16(12);
                writer.WriteByte(Byte0);
                writer.WriteByte(Byte1);
                writer.WriteByte(Byte2);
                writer.WriteByte(Byte3);
                writer.WriteByte(Byte4);
                writer.WriteByte(Byte5);
                writer.WriteByte(Byte6);
                writer.WriteByte(Byte7);
                writer.WriteUInt32(FourBytes);

                await writer.StoreAsync();
                writer.DetachStream();
            }
            using (var reader = new DataReader(socket.InputStream))
            {
                reader.ByteOrder = ByteOrder.LittleEndian;
                await reader.LoadAsync(5);
                var length = reader.ReadUInt16();
                var byte1 = reader.ReadByte();
                var byte2 = reader.ReadByte();
                var status = reader.ReadByte();

                reader.DetachStream();
            }
        }
開發者ID:r0t0r-r0t0r,項目名稱:GyroControl,代碼行數:41,代碼來源:MainPageViewModel.cs

示例11: LoadData

        private ActivityDataDoc LoadData(DataReader reader)
        {
            //read signature
            int signature = reader.ReadInt32();

            //read head
            ActivityDataDoc ret = new ActivityDataDoc();

            ret.version = (int)reader.ReadByte();
            ret.year = (int)reader.ReadByte();
            ret.month = (int)reader.ReadByte();
            ret.day = (int)reader.ReadByte();

            //read data
            while (reader.UnconsumedBufferLength > 0)
            {
                var row = new ActivityDataRow();

                //row head
                row.mode = reader.ReadByte();
                row.hour = reader.ReadByte();
                row.minute = reader.ReadByte();

                //row meta
                int size = (int)reader.ReadByte();
                byte[] meta = new byte[4];
                reader.ReadBytes(meta);

                //row data
                for (int i = 0, j = 0; meta[i] != 0 && i < 4 && j < size; ++i)
                {
                    int lvalue = meta[i] >> 4;
                    int rvalue = meta[i] & 0x0f;

                    if (j < size)
                    {
                        int rawValue = reader.ReadInt32();
                        ActivityDataRow.DataType dtype = dataTypeMap[lvalue];
                        double value = GetValue(rawValue, dtype);
                        row.data.Add(dtype, value);
                        j++;
                    }

                    if (j < size)
                    {
                        int rawValue = reader.ReadInt32();
                        ActivityDataRow.DataType dtype = dataTypeMap[rvalue];
                        double value = GetValue(rawValue, dtype);
                        row.data.Add(dtype, value);
                        j++;
                    }
                }
                ret.data.Add(row);

            }
            return ret;
        }
開發者ID:kreyosopensource,項目名稱:KreyosWP,代碼行數:57,代碼來源:Protocol.cs

示例12: bReadSource

        // Read in iBuffLength number of samples
        private async Task<bool> bReadSource(DataReader input)
        {
            UInt32 k;
            byte byteInput;
            uint iErrorCount = 0;

            // Read in the data
            for (k = 0; k < iStreamBuffLength; k++)
            {

                // Wait until we have 1 byte available to read
                await input.LoadAsync(1);

                // Read in the byte
                byteInput = input.ReadByte();

                // Save to the ring buffer and see if the frame can be parsed
                if (++idxCharCount < iFrameSize)
                {
                    mbus.writeRingBuff(byteInput);
                }
                else
                {
                    iUnsignedShortArray = mbus.writeRingBuff(byteInput, iShortCount);
                    iErrorCount = mbus.iGetErrorCount();
                }

                if (iErrorCount == 0 && idxCharCount >= iFrameSize)
                {
                    // The frame was valid
                    rectFrameOK.Fill = new SolidColorBrush(Colors.Green);

                    // Was it the next one in the sequence?
                    if( ++byteAddress == Convert.ToByte(mbus.iGetAddress()))
                    {
                        rectFrameSequence.Fill = new SolidColorBrush(Colors.Green);
                    }
                    else
                    {
                        rectFrameSequence.Fill = new SolidColorBrush(Colors.Red);
                        byteAddress = Convert.ToByte(mbus.iGetAddress());
                    }


                    AddScopeData( Convert.ToSingle(iUnsignedShortArray[0]) * fScope1ScaleADC, Convert.ToSingle(iUnsignedShortArray[1]) * fScope2ScaleADC);
                    AddScopeData(Convert.ToSingle(iUnsignedShortArray[2]) * fScope1ScaleADC, Convert.ToSingle(iUnsignedShortArray[3]) * fScope2ScaleADC);

                    // Reset the character counter
                    idxCharCount = 0;
                }

                if(idxCharCount>(iFrameSize>>1))
                {
                    rectFrameOK.Fill = new SolidColorBrush(Colors.Black);

                }


            }

            // Success, return a true
            return true;
        }
開發者ID:Wam1q,項目名稱:SerialScope,代碼行數:64,代碼來源:MainPage.xaml.cs

示例13: ReadBigEndian16bit

 protected short ReadBigEndian16bit(DataReader reader)
 {
     byte lo = reader.ReadByte();
     byte hi = reader.ReadByte();
     return (short)(((short)hi << 8) + (short)lo);
 }
開發者ID:traceyt,項目名稱:SensorTag-Azure,代碼行數:6,代碼來源:Movement.cs

示例14: 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

示例15: Run

        public override void Run()
        {
            #if WINRT
            StorageFile file = Package.Current.InstalledLocation.GetFileAsync(_path).AsTask().Result;
            using(var raStream = file.OpenReadAsync().AsTask().Result)
            {
                byte[] blob = new byte[CHUNK_SIZE];

                while (IsRunning && raStream.CanRead)
                {
                    DataReader reader = new DataReader(raStream.GetInputStreamAt(0));
                    reader.InputStreamOptions = InputStreamOptions.Partial;
                    try
                    {
                        reader.LoadAsync((uint)blob.Length).AsTask().Wait();
                        int bytesRead = 0;
                        while (reader.UnconsumedBufferLength > 0)
                        {
                            blob[bytesRead++] = reader.ReadByte();
                        }

                        if (bytesRead > 0)
                        {
                            HandleData(blob, bytesRead);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        reader.DetachStream();
                        reader.Dispose();
                    }

                    if (raStream.Position >= raStream.Size)
                    {
                        Terminate();
                        break;
                    }

                    Task.Delay(INTERVAL).Wait();
                }
            }
            #else
            byte [] blob = new byte[CHUNK_SIZE];

            while(IsRunning && _fileStream.CanRead)
            {
                int read = _fileStream.Read(blob, 0, CHUNK_SIZE);

                if( read > 0 )
                {
                    HandleData(blob, read);
                }

                if(_fileStream.CanSeek && _fileStream.Position >= _fileStream.Length)
                {
                    Terminate();
                    break;
                }

                Thread.Sleep(INTERVAL);
            }
            #endif
        }
開發者ID:visual14ph,項目名稱:f1livetiming,代碼行數:66,代碼來源:FileCapDriver.cs


注:本文中的Windows.Storage.Streams.DataReader.ReadByte方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。