Skip to main content

Class DefaultSerialProtocol

Default implementation of Brainboxes.IO.ISerialProtocol for text-based serial communication over Brainboxes Ethernet-to-Serial devices (ES-series).

Assembly: Brainboxes.IO.dll
View Source
Declaration
public class DefaultSerialProtocol : Protocol, ISerialProtocol, IProtocol, ICloneable

Inheritance: System.Object -> Brainboxes.IO.Protocol

Implements:
Brainboxes.IO.ISerialProtocol, Brainboxes.IO.IProtocol, System.ICloneable

Properties

Encoding

The character encoding used to send and receive data, default UTF-8, should be a highly compatible option for text based communication protocols including full compatibility with ASCII

View Source
Declaration
public Encoding Encoding { get; set; }

TerminatingCharacters

The character or sequence of characters that define the end of a data transmission, this will be automatically added to the end of sent data and stripped fromcheer the end of a received data The default terminating-character is \n New Line (Linux Standard Line Ending) Note Default Windows line ending is \r\n Carriage Return New Line, which will still work with this default, For better results with Windows line endings change this value to '\r\n'

View Source
Declaration
public string TerminatingCharacters { get; set; }

DataAvailable

Whether there is data available, returns 0 for no data and 1 more 1 or more characters

View Source
Declaration
public int DataAvailable { get; }

Fields

_encoding

default encoding UTF-8, should be a highly compatible option for text based communication protocols including full compatibility with ASCII

View Source
Declaration
protected Encoding _encoding

receiveBuffer

The receive buffer stores the inbound stream data before it is converted to the char encoding the underlying stream has a default receive buffer size of 8192 see: https://msdn.microsoft.com/en-us/library/system.net.sockets.socket.receivebuffersize%28v=vs.110%29.aspx

View Source
Declaration
protected byte[] receiveBuffer

_terminatingChars

default terminating character \n New Line (Linux Standard Line Ending)

View Source
Declaration
protected string _terminatingChars

Methods

Send(string)

Send data down the serial port encoded in the set encoding

View Source
Declaration
public virtual void Send(string message)
Parameters
TypeName
System.Stringmessage

Receive()

Receive data from the serial port decoded in the set encoding Will block until: the timeout is reached in which case an exception is thrown or until the terminating character is found

View Source
Declaration
public virtual string Receive()
Returns

System.String

Clone()

Make a shallow copy of the DefaultSerialProtocol This means when it is assigned to each port the instance is not shared so each port maintains its own state

View Source
Declaration
public object Clone()
Returns

System.Object

Implements