Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,289 @@
2010-04-22 Miguel de Icaza <miguel@novell.com>
* SerialPort.cs: Try to detect serial devices in other Unix
systems.
More tune ups for BSDs.
2010-02-23 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: DiscardNull should *not* report any error if the port
is not open. We haven't implemented it yet, but added the needed
comment in case we forget when actually implementing it.
Fixes #512244.
2010-01-25 Leszek Ciesielski <skolima@gmail.com>
* SerialPortStream.cs: Read was returning requested count instead
of actual bytes read. Thanks to Thad Thompson for spotting this.
2010-01-22 Leszek Ciesielski <skolima@gmail.com>
* SerialPortStream.cs: Check for error on every native call
2009-11-28 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* WinSerialStream.cs: Make CommStat a struct instead of a class to
make properly work ClearCommError.
Fixes the remaining bits of #348751.
2009-09-24 Christian Hoff <christian_hoff@gmx.net>
* SerialPort.cs: Do not close the base stream if Dispose is called from
the finalizer.
2009-09-21 Leszek Ciesielski <skolima@gmail.com>
* SerialPortStream.cs: Throw exception when errors occur in Close()
2007-09-14 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* WinSerialStream.cs: Fix the signature of ClearCommError.
Fixes #348751.
2008-09-14 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: Throw ArgumentException if NewLine gets an empty
string value.
Fixes #339012.
2008-09-08 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: In BaseStream property call CheckOpen instead of
duplicating the code.
2008-02-19 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPortStream.cs: Set DllImport.SetLastError to true for
all MonoPosixHelper functions, so in case of error we can retrieve the
error and print a simple but effective message about it.
2007-12-03 Miguel de Icaza <miguel@novell.com>
* SerialPort.cs: Apply patch from Martin Green
<martin@martsoft.co.uk> to support Serial Ports enumeration on
Windows.
2007-11-13 Atsushi Enomoto <atsushi@ximian.com>
* SerialPort.cs :
Added [DefaultValue]. For PortName it is useless though.
Do not use ObsoleteAttribute for MonoTODO role.
2007-11-05 Miguel de Icaza <miguel@novell.com>
* SerialPort.cs: Cope with multi-character newlines. Fixes #321988.
2007-10-13 Miguel de Icaza <miguel@novell.com>
* SerialPortStream.cs: Send a break on the Unix case.
2007-08-12 Lukasz Byczynski <lukaszb@forcom.com.pl>
* SerialPortStream.cs: added timeout handling on write
* WinSerialStream.cs: fixed setting handshake flags
2007-07-01 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: Don't throw ArgumentOutOfRangeException when the
buffer has Length = 0 (and has the appropriate arguments).
2007-05-21 Atsushi Enomoto <atsushi@ximian.com>
* SerialPort.cs : slightly boring 2.0 attributes.
2007-05-01 Sebastien Pouliot <sebastien@ximian.com>
* WinSerialStream.cs: Fix build due to NativeOverlapped being updated
to 2.0 definition (int to IntPtr).
Wed Apr 11 15:40:55 CEST 2007 Paolo Molaro <lupus@ximian.com>
* WinSerialStream.cs: fixed logic for signal value check (bug #81342).
2006-11-18 Jelle Hissink <Jelle.Hissink@C-it.nl>
* SerialPortStream.cs: Fix the parameters in Read, and also poll
before the read, so we can thorw the TimeoutException.
2006-09-28 Andrew Skiba <andrews@mainsoft.com>
* SerialPort.cs,WinSerialStream.cs: TARGET_JVM
2006-08-14 Chris Toshok <toshok@ximian.com>
* SerialPort.cs: the paths returned by Directory.GetFiles have the
directory at the beginning of the string.
2006-08-13 Miguel de Icaza <miguel@novell.com>
* SerialPort.cs (ReadTo): Implemented.
Add a couple of missing checks.
Also handle ttyUSB for Chris.
* SerialPortStream.cs (BytesToRead, BytesToWrite): Implement.
* SerialPort.cs (ReadByte): Go directly to the stream, no need to
call the wrapper code.
(ReadChar): implement.
(ReadLine): implement.
Add DefaultValueAttributes to various methods.
* SerialPortStream.cs, WinSerialStream.cs: Use the same checking
we use elsewhere for parameters.
2005-05-12 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* ISerialStream.cs: Add support for break state.
* SerialPort.cs: Likewise.
* WinSerialStream.cs: Add support for break state and
some other bits (BytesToRead, BytesToWrite, DsrHolding,
CDHolding, CtsHolding, DiscardIn, DiscardOut).
* SerialPortStream.cs: Add a SetBreak function to
implement the updated ISerialStream interface (not implemented
by now).
2005-05-08 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs:
* WinSerialStream.cs: Actually plug the Win serial stream
in the SerialPort and use it if we are on Windows (use std
stream otherwise).
2005-05-08 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* WinSerialStream.cs: Implement some bits needed for
the backend thing.
2005-05-06 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* ISerialStream.cs:
* SerialPortStream.cs:
* SerialPort.cs:
* SerialSignal.cs:
Some changes to make SerialPorStream implement ISerialInterface,
and be able to have OS-depending backends.
2006-05-06 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* ISerialStream.cs: New internal interface used for
accessing the backend streams functionality.
2006-04-20 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* WinSerialPort.cs: Inital import of the backend stream
for Windows support.
2006-04-06 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs:
* SerialPortStream.cs: Add signals managing.
* SerialSignal.cs: New.
2006-04-05 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: Add protected Dispose method, and move
the Close stuff there.
2006-04-04 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: Re-arrange values for ctors (keep things
clean).
2006-04-03 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs:
* SerialPortStream.cs: Remove the buffers from the SerialPort
class, and take them to SerialPortStream. We need them for
storing the internal read (pass the buffer sizes to SerialPortStream
ctor by now, and use those numbers when we support them).
2006-03-27 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: Inherit from Component, and use protected
Events property to save the event handlers. Also add internal
methods to trigger the events and remove pragmas.
2006-03-15 Miguel de Icaza <miguel@gnome.org>
* SerialPort.cs: We will do detection of systems differently as we
discussed over email. Drop malloc/free/uname calls.
2006-03-15 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: Add basic detection of serial ports and
default serial port.
2006-03-14 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs:
* SerialPortStream.cs: Change SerialPortStream ctor
parameters and fix some related values.
2006-03-11 Miguel de Icaza <miguel@novell.com>
* y
* SerialPort.cs: Remove unused variable (writeBuffer).
* SerialPortStream.cs (Dispose): override, not new.
2006-03-08 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs:
* SerialPortStream.cs: Small advance/cleanups.
2006-02-29 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs:
* SerialReceivedEventArgs.cs:
* SerialErrorEventArgs.cs:
* SerialPinChangedEventArgs.cs: Fix signatures and values
related to events.
2006-02-28 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs:
* SerialPortStream.cs: Cleanups and some small funcionalities
added. Also, some code was moved to SerialPortStream, to have a
better design.
2006-02-21 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs:
* SerialPortStream.cs: Move SerialPortStream to a new file,
to have a better organization.
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
exception report.
* Parity.cs:
* Handshake.cs:
* StopBits.cs: New enum files (taken outside SerialPort
and with the right values now).
2006-02-13 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialPort.cs: Work on Encoding property and use it
in Write methods.
2006-02-10 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* SerialError.cs:
* SerialData.cs:
* SerialPinChange.cs: New enums.
2004-12-26 Zoltan Varga <vargaz@freemail.hu>
* System.IO.Ports/SerialPort.cs: Fix build under csc.

View File

@@ -0,0 +1,21 @@
//
// System.IO.Ports.Handshake.cs
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
namespace System.IO.Ports
{
public enum Handshake
{
None,
XOnXOff,
RequestToSend,
RequestToSendXOnXOff
}
}

View File

@@ -0,0 +1,33 @@
//
// System.IO.Ports.ISerialStream.cs
//
// Authors:
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
using System;
namespace System.IO.Ports
{
interface ISerialStream : IDisposable
{
int Read (byte [] buffer, int offset, int count);
void Write (byte [] buffer, int offset, int count);
void SetAttributes (int baud_rate, Parity parity, int data_bits, StopBits sb, Handshake hs);
void DiscardInBuffer ();
void DiscardOutBuffer ();
SerialSignal GetSignals ();
void SetSignal (SerialSignal signal, bool value);
void SetBreakState (bool value);
void Close ();
int BytesToRead { get; }
int BytesToWrite { get; }
int ReadTimeout { get; set; }
int WriteTimeout { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
//
// System.IO.Ports.Parity.cs
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
namespace System.IO.Ports
{
public enum Parity
{
None,
Odd,
Even,
Mark,
Space
}
}

View File

@@ -0,0 +1,18 @@
//
// System.IO.Ports.SerialData.cs
//
// Authors:
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
namespace System.IO.Ports
{
public enum SerialData
{
Chars = 1,
Eof
}
}

View File

@@ -0,0 +1,22 @@
//
// System.IO.Ports.SerialError.cs
//
// Authors:
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
namespace System.IO.Ports
{
public enum SerialError
{
RXOver = 1,
Overrun = 2,
RXParity = 4,
Frame = 8,
TXFull = 256
}
}

View File

@@ -0,0 +1,24 @@
/* -*- Mode: Csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
namespace System.IO.Ports
{
public class SerialErrorReceivedEventArgs : EventArgs
{
internal SerialErrorReceivedEventArgs (SerialError eventType)
{
this.eventType = eventType;
}
// properties
public SerialError EventType {
get {
return eventType;
}
}
SerialError eventType;
}
}

View File

@@ -0,0 +1,22 @@
//
// System.IO.Ports.SerialPinChange.cs
//
// Authors:
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
namespace System.IO.Ports
{
public enum SerialPinChange
{
CtsChanged = 8,
DsrChanged = 16,
CDChanged = 32,
Break = 64,
Ring = 256
}
}

View File

@@ -0,0 +1,23 @@
/* -*- Mode: Csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
namespace System.IO.Ports
{
public class SerialPinChangedEventArgs : EventArgs
{
internal SerialPinChangedEventArgs (SerialPinChange eventType)
{
this.eventType = eventType;
}
// properties
public SerialPinChange EventType {
get {
return eventType;
}
}
SerialPinChange eventType;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,332 @@
//
// System.IO.Ports.SerialPortStream.cs
//
// Authors:
// Chris Toshok (toshok@ximian.com)
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
// Slightly modified by Konrad M. Kruczynski (added baud rate value checking)
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace System.IO.Ports
{
class SerialPortStream : Stream, ISerialStream, IDisposable
{
int fd;
int read_timeout;
int write_timeout;
bool disposed;
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern int open_serial (string portName);
public SerialPortStream (string portName, int baudRate, int dataBits, Parity parity, StopBits stopBits,
bool dtrEnable, bool rtsEnable, Handshake handshake, int readTimeout, int writeTimeout,
int readBufferSize, int writeBufferSize)
{
fd = open_serial (portName);
if (fd == -1)
ThrowIOException ();
TryBaudRate (baudRate);
if (!set_attributes (fd, baudRate, parity, dataBits, stopBits, handshake))
ThrowIOException (); // Probably Win32Exc for compatibility
read_timeout = readTimeout;
write_timeout = writeTimeout;
SetSignal (SerialSignal.Dtr, dtrEnable);
if (handshake != Handshake.RequestToSend &&
handshake != Handshake.RequestToSendXOnXOff)
SetSignal (SerialSignal.Rts, rtsEnable);
}
public override bool CanRead {
get {
return true;
}
}
public override bool CanSeek {
get {
return false;
}
}
public override bool CanWrite {
get {
return true;
}
}
public override bool CanTimeout {
get {
return true;
}
}
public override int ReadTimeout {
get {
return read_timeout;
}
set {
if (value < 0 && value != SerialPort.InfiniteTimeout)
throw new ArgumentOutOfRangeException ("value");
read_timeout = value;
}
}
public override int WriteTimeout {
get {
return write_timeout;
}
set {
if (value < 0 && value != SerialPort.InfiniteTimeout)
throw new ArgumentOutOfRangeException ("value");
write_timeout = value;
}
}
public override long Length {
get {
throw new NotSupportedException ();
}
}
public override long Position {
get {
throw new NotSupportedException ();
}
set {
throw new NotSupportedException ();
}
}
public override void Flush ()
{
// If used, this _could_ flush the serial port
// buffer (not the SerialPort class buffer)
}
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern int read_serial (int fd, byte [] buffer, int offset, int count);
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern bool poll_serial (int fd, out int error, int timeout);
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 error;
bool poll_result = poll_serial (fd, out error, read_timeout);
if (error == -1)
ThrowIOException ();
if (!poll_result) {
// see bug 79735 http://bugzilla.ximian.com/show_bug.cgi?id=79735
// should the next line read: return -1;
throw new TimeoutException();
}
int result = read_serial (fd, buffer, offset, count);
if (result == -1)
ThrowIOException ();
return result;
}
public override long Seek (long offset, SeekOrigin origin)
{
throw new NotSupportedException ();
}
public override void SetLength (long value)
{
throw new NotSupportedException ();
}
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern int write_serial (int fd, byte [] buffer, int offset, int count, int timeout);
public override void Write (byte[] buffer, int offset, int count)
{
CheckDisposed ();
if (buffer == null)
throw new ArgumentNullException ("buffer");
if (offset < 0 || count < 0)
throw new ArgumentOutOfRangeException ();
if (buffer.Length - offset < count)
throw new ArgumentException ("offset+count",
"The size of the buffer is less than offset + count.");
// FIXME: this reports every write error as timeout
if (write_serial (fd, buffer, offset, count, write_timeout) < 0)
throw new TimeoutException("The operation has timed-out");
}
protected override void Dispose (bool disposing)
{
if (disposed)
return;
disposed = true;
if (close_serial (fd) != 0)
ThrowIOException();
}
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern int close_serial (int fd);
public override void Close ()
{
((IDisposable) this).Dispose ();
}
void IDisposable.Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
~SerialPortStream ()
{
Dispose (false);
}
void CheckDisposed ()
{
if (disposed)
throw new ObjectDisposedException (GetType ().FullName);
}
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern bool set_attributes (int fd, int baudRate, Parity parity, int dataBits, StopBits stopBits, Handshake handshake);
public void SetAttributes (int baud_rate, Parity parity, int data_bits, StopBits sb, Handshake hs)
{
if (!set_attributes (fd, baud_rate, parity, data_bits, sb, hs))
ThrowIOException ();
}
[DllImport("MonoPosixHelper", SetLastError = true)]
static extern int get_bytes_in_buffer (int fd, int input);
public int BytesToRead {
get {
int result = get_bytes_in_buffer (fd, 1);
if (result == -1)
ThrowIOException ();
return result;
}
}
public int BytesToWrite {
get {
int result = get_bytes_in_buffer (fd, 0);
if (result == -1)
ThrowIOException ();
return result;
}
}
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern int discard_buffer (int fd, bool inputBuffer);
public void DiscardInBuffer ()
{
if (discard_buffer (fd, true) != 0)
ThrowIOException();
}
public void DiscardOutBuffer ()
{
if (discard_buffer (fd, false) != 0)
ThrowIOException();
}
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern SerialSignal get_signals (int fd, out int error);
public SerialSignal GetSignals ()
{
int error;
SerialSignal signals = get_signals (fd, out error);
if (error == -1)
ThrowIOException ();
return signals;
}
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern int set_signal (int fd, SerialSignal signal, bool value);
public void SetSignal (SerialSignal signal, bool value)
{
if (signal < SerialSignal.Cd || signal > SerialSignal.Rts ||
signal == SerialSignal.Cd ||
signal == SerialSignal.Cts ||
signal == SerialSignal.Dsr)
throw new Exception ("Invalid internal value");
if (set_signal (fd, signal, value) == -1)
ThrowIOException ();
}
[DllImport ("MonoPosixHelper", SetLastError = true)]
static extern int breakprop (int fd);
public void SetBreakState (bool value)
{
if (value)
if (breakprop (fd) == -1)
ThrowIOException ();
}
[DllImport ("libc")]
static extern IntPtr strerror (int errnum);
static void ThrowIOException ()
{
int errnum = Marshal.GetLastWin32Error ();
string error_message = Marshal.PtrToStringAnsi (strerror (errnum));
throw new IOException (error_message);
}
[DllImport ("MonoPosixHelper")]
static extern bool is_baud_rate_legal (int baud_rate);
private void TryBaudRate (int baudRate)
{
if (!is_baud_rate_legal (baudRate))
{
// this kind of exception to be compatible with MSDN API
throw new ArgumentOutOfRangeException ("baudRate",
"Given baud rate is not supported on this platform.");
}
}
}
}

View File

@@ -0,0 +1,22 @@
/* -*- Mode: Csharp; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
namespace System.IO.Ports
{
public class SerialDataReceivedEventArgs : EventArgs
{
internal SerialDataReceivedEventArgs (SerialData eventType)
{
this.eventType = eventType;
}
// properties
public SerialData EventType {
get {
return eventType;
}
}
SerialData eventType;
}
}

View File

@@ -0,0 +1,21 @@
//
// System.IO.Ports.SerialSignal.cs
//
// Authors:
// Carlos Alberto Cortez (calberto.cortez@gmail.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
namespace System.IO.Ports
{
enum SerialSignal {
None = 0,
Cd = 1, // Carrier detect
Cts = 2, // Clear to send
Dsr = 4, // Data set ready
Dtr = 8, // Data terminal ready
Rts = 16 // Request to send
}
}

View File

@@ -0,0 +1,20 @@
//
// System.IO.Ports.StopBits.cs
//
// Authors:
// Chris Toshok (toshok@ximian.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
namespace System.IO.Ports
{
public enum StopBits
{
None,
One,
Two,
OnePointFive
}
}

File diff suppressed because it is too large Load Diff