2006-02-21 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Tue, 21 Feb 2006 23:33:47 +0000 (23:33 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Tue, 21 Feb 2006 23:33:47 +0000 (23:33 -0000)
* SerialPort.cs: Little work on support the Read methods.

svn path=/trunk/mcs/; revision=57117

mcs/class/System/System.IO.Ports/ChangeLog
mcs/class/System/System.IO.Ports/SerialPort.cs

index 891470bddf12de3b0af334c061ac188efa69e21b..58fb4d2022f174aae426fdb36b45d035cbf78753 100644 (file)
@@ -1,3 +1,7 @@
+2006-02-21  Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * SerialPort.cs: Little work on support the Read methods.
+
 2006-02-14  Carlos Alberto Cortez <calberto.cortez@gmail.com>
 
        * SerialPort.cs: Little work on default values and
index 153e845f024dd85d32d940dbaa16c2064d121844..f14e673f0794997af3f55b10e720e7f3f24e6ead 100644 (file)
@@ -516,12 +516,35 @@ namespace System.IO.Ports
 
                public int Read (byte[] buffer, int offset, int count)
                {
+                       if (!isOpen)
+                               throw new InvalidOperationException ();
+                       if (buffer == null)
+                               throw new ArgumentNullException ("buffer");
+                       if (offset < 0 || offset >= buffer.Length)
+                               throw new ArgumentOutOfRangeException ("offset");
+                       if (count < 0 || count > buffer.Length)
+                               throw new ArgumentOutOfRangeException ("count");
+                       if (count > buffer.Length - offset)
+                               throw new ArgumentException ("count > buffer.Length - offset");
+                       
                        return read_serial (unixFd, buffer, offset, count, readTimeout);
                }
 
                public int Read (char[] buffer, int offset, int count)
                {
-                       throw new NotImplementedException ();
+                       if (!isOpen)
+                               throw new InvalidOperationException ();
+                       if (buffer == null)
+                               throw new ArgumentNullException ("buffer");
+                       if (offset < 0 || offset >= buffer.Length)
+                               throw new ArgumentOutOfRangeException ("offset");
+                       if (count < 0 || count > buffer.Length)
+                               throw new ArgumentOutOfRangeException ("count");
+                       if (count > buffer.Length - offset)
+                               throw new ArgumentException ("count > buffer.Length - offset");
+
+                       byte [] bytes = encoding.GetBytes (buffer, offset, count);
+                       return read_serial (unixFd, bytes, 0, bytes.Length, readTimeout);
                }
 
                byte[] read_buffer = new byte[4096];