Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@gnome.org>2006-08-14 05:46:11 +0400
committerMiguel de Icaza <miguel@gnome.org>2006-08-14 05:46:11 +0400
commitd82e3e883c470bde12709aa759d21a246e819e72 (patch)
tree303f3caa8f01fc0ed945615ba402033591a57692 /mcs/class/System/System.IO.Ports
parent37c538659cfa84e97d5d9519a96f36d1510bbd27 (diff)
2006-08-13 Miguel de Icaza <miguel@novell.com>
* SerialPort.cs (ReadTo): Implemented. Add a couple of missing checks. svn path=/trunk/mcs/; revision=63694
Diffstat (limited to 'mcs/class/System/System.IO.Ports')
-rw-r--r--mcs/class/System/System.IO.Ports/ChangeLog5
-rw-r--r--mcs/class/System/System.IO.Ports/SerialPort.cs37
2 files changed, 36 insertions, 6 deletions
diff --git a/mcs/class/System/System.IO.Ports/ChangeLog b/mcs/class/System/System.IO.Ports/ChangeLog
index 8d858c21415..8f2d44160f4 100644
--- a/mcs/class/System/System.IO.Ports/ChangeLog
+++ b/mcs/class/System/System.IO.Ports/ChangeLog
@@ -1,6 +1,9 @@
2006-08-13 Miguel de Icaza <miguel@novell.com>
- * SerialPort.cs: Also handle ttyUSB for Chris.
+ * SerialPort.cs (ReadTo): Implemented.
+ Add a couple of missing checks.
+
+ Also handle ttyUSB for Chris.
* SerialPortStream.cs (BytesToRead, BytesToWrite): Implement.
diff --git a/mcs/class/System/System.IO.Ports/SerialPort.cs b/mcs/class/System/System.IO.Ports/SerialPort.cs
index 1a13c329be1..1dad19650bd 100644
--- a/mcs/class/System/System.IO.Ports/SerialPort.cs
+++ b/mcs/class/System/System.IO.Ports/SerialPort.cs
@@ -528,7 +528,7 @@ namespace System.IO.Ports
return stream.Read (bytes, 0, bytes.Length);
}
- public int ReadByte ()
+ internal int read_byte ()
{
byte [] buff = new byte [1];
if (stream.Read (buff, 0, 1) > 0)
@@ -536,14 +536,22 @@ namespace System.IO.Ports
return -1;
}
+
+ public int ReadByte ()
+ {
+ CheckOpen ();
+ return read_byte ();
+ }
public int ReadChar ()
{
+ CheckOpen ();
+
byte [] buffer = new byte [16];
int i = 0;
-
+
do {
- int b = ReadByte ();
+ int b = read_byte ();
if (b == -1)
return -1;
buffer [i++] = (byte) b;
@@ -557,6 +565,8 @@ namespace System.IO.Ports
public string ReadExisting ()
{
+ CheckOpen ();
+
int count = BytesToRead;
byte [] bytes = new byte [count];
@@ -566,6 +576,7 @@ namespace System.IO.Ports
public string ReadLine ()
{
+ CheckOpen ();
List<byte> bytes_read = new List<byte>();
byte [] buff = new byte [1];
@@ -578,7 +589,6 @@ namespace System.IO.Ports
return new String (encoding.GetChars (bytes_read.ToArray ()));
}
- [MonoTODO("Not implemented")]
public string ReadTo (string value)
{
CheckOpen ();
@@ -587,7 +597,24 @@ namespace System.IO.Ports
if (value.Length == 0)
throw new ArgumentException ("value");
- throw new NotImplementedException ();
+ // Turn into byte array, so we can compare
+ byte [] byte_value = encoding.GetBytes (value);
+ int current = 0;
+ List<byte> seen = new List<byte> ();
+
+ while (true){
+ int n = read_byte ();
+ if (n == -1)
+ break;
+ seen.Add ((byte)n);
+ if (n == byte_value [current]){
+ current++;
+ if (current == byte_value.Length)
+ return encoding.GetString (seen.ToArray (), 0, seen.Count - byte_value.Length);
+ } else
+ current = 0;
+ }
+ return encoding.GetString (seen.ToArray ());
}
public void Write (string str)