System.IO.Ports.WinSerialStream.Read C# (CSharp) Méthode

Read() public méthode

public Read ( [ buffer, int offset, int count ) : int
buffer [
offset int
count int
Résultat int
		public override int Read ([In, Out] byte [] buffer, int offset, int count)
		{
			CheckDisposed ();
			if (buffer == null)
				throw new ArgumentNullException ("buffer");
			if (offset < 0 || count < 0)
				throw new ArgumentOutOfRangeException ("offset or count less than zero.");

			if (buffer.Length - offset < count )
				throw new ArgumentException ("offset+count",
							      "The size of the buffer is less than offset + count.");

			int bytes_read;

			unsafe {
				fixed (byte* ptr = buffer) {
					if (ReadFile (handle, ptr + offset, count, out bytes_read, read_overlapped))
						return bytes_read;
				
					// Test for overlapped behavior
					if (Marshal.GetLastWin32Error () != FileIOPending)
						ReportIOError (null);
				
					if (!GetOverlappedResult (handle, read_overlapped, ref bytes_read, true))
						ReportIOError (null);
			
				}
			}

			if (bytes_read == 0)
				throw new TimeoutException (); // We didn't get any byte

			return bytes_read;
		}