-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #959 from glopesdev/issue-952
Add operators for reading and writing binary data from a serial port
- Loading branch information
Showing
24 changed files
with
653 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using System.ComponentModel; | ||
using Bonsai.IO; | ||
using Bonsai.IO.Ports; | ||
|
||
namespace Bonsai.Arduino | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Bonsai.IO.Ports | ||
{ | ||
internal class Constants | ||
{ | ||
public const string XmlNamespace = "clr-namespace:Bonsai.IO.Ports;assembly=Bonsai.System"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace Bonsai.IO | ||
{ | ||
/// <summary> | ||
/// This type is obsolete. Please use the <see cref="Ports.BaudRateConverter"/> operator instead. | ||
/// </summary> | ||
[Obsolete] | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public class BaudRateConverter : Ports.BaudRateConverter | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.IO.Ports; | ||
using System.Reactive.Linq; | ||
|
||
namespace Bonsai.IO | ||
{ | ||
/// <summary> | ||
/// This type is obsolete. Please use the <see cref="Ports.CreateSerialPort"/> operator instead. | ||
/// </summary> | ||
[Obsolete] | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
[Description("This type is obsolete. Please use the Ports.CreateSerialPort operator instead.")] | ||
public class CreateSerialPort : Source<SerialPort>, INamedElement | ||
{ | ||
readonly SerialPortConfiguration configuration = new SerialPortConfiguration(); | ||
|
||
/// <summary> | ||
/// Gets or sets the optional alias for the serial port connection. | ||
/// </summary> | ||
[Category("Connection")] | ||
[Description("The optional alias for the serial port connection.")] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the serial port. | ||
/// </summary> | ||
[Category("Connection")] | ||
[TypeConverter(typeof(SerialPortNameConverter))] | ||
[Description("The name of the serial port.")] | ||
public string PortName | ||
{ | ||
get { return configuration.PortName; } | ||
set { configuration.PortName = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the serial baud rate. | ||
/// </summary> | ||
[Category("Connection")] | ||
[TypeConverter(typeof(BaudRateConverter))] | ||
[Description("The serial baud rate.")] | ||
public int BaudRate | ||
{ | ||
get { return configuration.BaudRate; } | ||
set { configuration.BaudRate = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the byte encoding used for pre- and post-transmission conversion of text. | ||
/// </summary> | ||
[TypeConverter(typeof(Ports.SerialPortEncodingConverter))] | ||
[Description("The byte encoding used for pre- and post-transmission conversion of text.")] | ||
public string Encoding | ||
{ | ||
get { return configuration.Encoding; } | ||
set { configuration.Encoding = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the parity bit for the <see cref="SerialPort"/> object. | ||
/// </summary> | ||
[Description("The parity checking protocol.")] | ||
public Parity Parity | ||
{ | ||
get { return configuration.Parity; } | ||
set { configuration.Parity = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the byte that replaces invalid bytes in the data stream when a parity error occurs. | ||
/// </summary> | ||
[Description("The byte that replaces invalid bytes in the data stream when a parity error occurs.")] | ||
public byte ParityReplace | ||
{ | ||
get { return configuration.ParityReplace; } | ||
set { configuration.ParityReplace = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the number of data bits per byte. | ||
/// </summary> | ||
[Description("The number of data bits per byte.")] | ||
public int DataBits | ||
{ | ||
get { return configuration.DataBits; } | ||
set { configuration.DataBits = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the number of stop bits per byte. | ||
/// </summary> | ||
[Description("The number of stop bits per byte.")] | ||
public StopBits StopBits | ||
{ | ||
get { return configuration.StopBits; } | ||
set { configuration.StopBits = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the handshaking protocol for serial port transmission of data. | ||
/// </summary> | ||
[Description("The handshaking protocol for serial port transmission of data.")] | ||
public Handshake Handshake | ||
{ | ||
get { return configuration.Handshake; } | ||
set { configuration.Handshake = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether null bytes are ignored when transmitted | ||
/// between the port and the receive buffer. | ||
/// </summary> | ||
[Description("Indicates whether null bytes are ignored when transmitted between the port and the receive buffer.")] | ||
public bool DiscardNull | ||
{ | ||
get { return configuration.DiscardNull; } | ||
set { configuration.DiscardNull = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the Data Terminal Ready (DTR) signal should | ||
/// be enabled during serial communication. | ||
/// </summary> | ||
[Description("Indicates whether the Data Terminal Ready (DTR) signal should be enabled during serial communication.")] | ||
public bool DtrEnable | ||
{ | ||
get { return configuration.DtrEnable; } | ||
set { configuration.DtrEnable = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the Request to Send (RTS) signal should be | ||
/// enabled during serial communication. | ||
/// </summary> | ||
[Description("Indicates whether the Request to Send (RTS) signal should be enabled during serial communication.")] | ||
public bool RtsEnable | ||
{ | ||
get { return configuration.RtsEnable; } | ||
set { configuration.RtsEnable = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the size of the read buffer, in bytes. This is the maximum number of | ||
/// read bytes which can be buffered. | ||
/// </summary> | ||
[Description("The size of the read buffer, in bytes. This is the maximum number of read bytes which can be buffered.")] | ||
public int ReadBufferSize | ||
{ | ||
get { return configuration.ReadBufferSize; } | ||
set { configuration.ReadBufferSize = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the size of the write buffer, in bytes. This is the maximum number of | ||
/// bytes which can be queued for write. | ||
/// </summary> | ||
[Description("The size of the write buffer, in bytes. This is the maximum number of bytes which can be queued for write.")] | ||
public int WriteBufferSize | ||
{ | ||
get { return configuration.WriteBufferSize; } | ||
set { configuration.WriteBufferSize = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the number of bytes received into the internal input buffer before | ||
/// the read event is fired. | ||
/// </summary> | ||
[Description("The number of bytes received into the internal input buffer before the read event is fired.")] | ||
public int ReceivedBytesThreshold | ||
{ | ||
get { return configuration.ReceivedBytesThreshold; } | ||
set { configuration.ReceivedBytesThreshold = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Generates an observable sequence that contains the serial port connection object. | ||
/// </summary> | ||
/// <returns> | ||
/// A sequence containing a single instance of the <see cref="SerialPort"/> class | ||
/// representing the serial connection. | ||
/// </returns> | ||
public override IObservable<SerialPort> Generate() | ||
{ | ||
return Observable.Using( | ||
() => Ports.SerialPortManager.ReserveConnection(Name, configuration), | ||
connection => Observable.Return(connection.SerialPort).Concat(Observable.Never(connection.SerialPort))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace Bonsai.IO | ||
{ | ||
/// <summary> | ||
/// This type is obsolete. Please use the <see cref="Ports.SerialPortConfiguration"/> operator instead. | ||
/// </summary> | ||
[Obsolete] | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public class SerialPortConfiguration : Ports.SerialPortConfiguration | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.ComponentModel; | ||
|
||
namespace Bonsai.IO | ||
{ | ||
/// <summary> | ||
/// This type is obsolete. Please use the <see cref="Ports.SerialPortNameConverter"/> operator instead. | ||
/// </summary> | ||
[Obsolete] | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public class SerialPortNameConverter : Ports.SerialPortNameConverter | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.