Skip to main content

Class EDDevice

Base class for all Brainboxes Ethernet Remote IO devices (part numbers starting "ED-XXX"). Provides access to digital and analog IO lines, event-driven monitoring, and device management.

Assembly: Brainboxes.IO.dll
View Source
Declaration
public class EDDevice : Device<IConnection, IIOProtocol>, IEDDevice, IDevice<IConnection, IIOProtocol>, IDisposable

Inheritance: System.Object -> Brainboxes.IO.Device<Brainboxes.IO.IConnection,Brainboxes.IO.IIOProtocol>

Derived:

Expand

Implements:
Brainboxes.IO.IEDDevice, Brainboxes.IO.IDevice<Brainboxes.IO.IConnection,Brainboxes.IO.IIOProtocol>, System.IDisposable

Properties

IOLines

IOLines indexed by their logical line number as described on the Brainboxes product label

View Source
Declaration
public IOList<IOLine> IOLines { get; protected set; }

Outputs

The devices output Lines (if it has any) indexed by IOLineNumber e.g. DOUT0, DOUT1, DOUT2

View Source
Declaration
public IOList<IOLine> Outputs { get; protected set; }

Inputs

The devices input Lines (if it has any) indexed by IOLineNumber e.g. DOUT0, DOUT1, DOUT2

View Source
Declaration
public IOList<IOLine> Inputs { get; protected set; }

AInputs

The devices analog input lines (if it has any) index by IOLineNumber e.g AOUT0, AOUT1, AOUT2

View Source
Declaration
public IOList<IOLine> AInputs { get; protected set; }

AOutputs

The devices analog output lines (if it has any) indexed by IOLineNumber e.g AOUT0, AOUT1, AOUT2

View Source
Declaration
public IOList<IOLine> AOutputs { get; protected set; }

IOLineCacheTimeout

The time between checking the state of the IO lines for event handling, defaults to 250 ms Also the stale period, when the cached value of the IO line has to be re-queried on the device

View Source
Declaration
public int IOLineCacheTimeout { get; set; }

Fields

_numberOfRegisteredEvents

The number of events registered with this EDDevice

View Source
Declaration
protected int _numberOfRegisteredEvents

_IOCounterUpdateDirection

whether the Digital Input IO Line counter updates on a rising edge or a falling edge

View Source
Declaration
protected IOChangeTypes _IOCounterUpdateDirection

_pollingTimer

The timer thread used for polling IO

View Source
Declaration
protected Timer _pollingTimer

_threadShouldBeRunning

flag to indicate whether the pollingThread should be running

View Source
Declaration
protected volatile bool _threadShouldBeRunning

_ioLineCacheTimeout

cache timeout is also the polling interval

View Source
Declaration
protected int _ioLineCacheTimeout

Methods

SendCommand(string)

Send a command to the Brainboxes device using the supplied protocol.

View Source
Declaration
public string SendCommand(string command)
Returns

System.String: Response or null if no response

Parameters
TypeNameDescription
System.Stringcommandcommand to send

FactoryReset()

Factory resets the device, this can take some time as the current connection is broken and a new on has to be re-established the connection may not reconnect if the current IP address settings cannot be re-got be the device in default settings mode

View Source
Declaration
public void FactoryReset()

Restart()

Power Cycle the device this can take some time as the current connection is broken and a new on has to be re-established the function will block until the device is powered up and reconnected to

View Source
Declaration
public void Restart()

_reconnectAfterResetOrRestart(string)

Disconnects from the device the tries to reconnect each second over a period of 20 seconds, returns as soon as a connection is established

View Source
Declaration
protected void _reconnectAfterResetOrRestart(string restartOrReconnect)
Parameters
TypeName
System.StringrestartOrReconnect

Connect()

Connect to a Brainboxes Remote IO Device

View Source
Declaration
public override void Connect()

Disconnect()

Disconnect from a Brainboxes Remote IO Device

View Source
Declaration
public override void Disconnect()

ToString()

ToString

View Source
Declaration
public override string ToString()
Returns

System.String

Describe()

Give a complete summary of the EDDevice

View Source
Declaration
public override string Describe()
Returns

System.String

SubscribeToTargetEvent(ref AIOLineChangedEventHandler, double)

Register an event with this handler to be notified when the state of an Analog input goes over the limit specified

View Source
Declaration
public void SubscribeToTargetEvent(ref AIOLineChangedEventHandler function, double target)
Parameters
TypeName
Brainboxes.IO.AIOLineChangedEventHandlerfunction
System.Doubletarget

SubscribeToDeltaEvent(ref AIOLineChangedEventHandler, double)

Register an event with this handler to be notified when the state of an Analog line changes by larger than the limit specified

View Source
Declaration
public void SubscribeToDeltaEvent(ref AIOLineChangedEventHandler function, double delta)
Parameters
TypeName
Brainboxes.IO.AIOLineChangedEventHandlerfunction
System.Doubledelta

SubscribeToTargetRangeEvent(ref AIOLineChangedEventHandler, double, double)

Register an event with this handler to be notified when the state of an Analog line changes to be within the specified delta range of a specified target value and also when it changes to be outside of the specified delta range

View Source
Declaration
public void SubscribeToTargetRangeEvent(ref AIOLineChangedEventHandler function, double target, double delta)
Parameters
TypeName
Brainboxes.IO.AIOLineChangedEventHandlerfunction
System.Doubletarget
System.Doubledelta

UnsubscribeToDeltaEvent(ref AIOLineChangedEventHandler)

Unsubscribe a registered delta event with this handler to stop being notified when this event is triggered

View Source
Declaration
public void UnsubscribeToDeltaEvent(ref AIOLineChangedEventHandler function)
Parameters
TypeName
Brainboxes.IO.AIOLineChangedEventHandlerfunction

UnsubscribeToTargetEvent(ref AIOLineChangedEventHandler)

Unsubscribe a registered target event with this handler to stop being notified when this event is triggered

View Source
Declaration
public void UnsubscribeToTargetEvent(ref AIOLineChangedEventHandler function)
Parameters
TypeName
Brainboxes.IO.AIOLineChangedEventHandlerfunction

UnsubscribeToTargetRangeEvent(ref AIOLineChangedEventHandler)

Unsubscribe a registered target range event with this handler to stop being notified when this event is triggered

View Source
Declaration
public void UnsubscribeToTargetRangeEvent(ref AIOLineChangedEventHandler function)
Parameters
TypeName
Brainboxes.IO.AIOLineChangedEventHandlerfunction

_eventAdded()

Called whenever an event is added to any of the event collection

View Source
Declaration
protected void _eventAdded()

_eventRemoved()

Called whenever an event is removed from any of the event collections

View Source
Declaration
protected void _eventRemoved()

_startPollingForChanges()

Spins up a background timing thread which polls the Brainboxes ED Device periodically at ioLineCacheTimeout

View Source
Declaration
protected void _startPollingForChanges()

_stopPollingForChanges()

Stop and dispose the background thread which is polling for changes on the Brainboxes ED Device

View Source
Declaration
protected void _stopPollingForChanges()

_pollingThreadFunc(object)

This is the function which is run on the background thread which Polls the ED Device for changes and then dispatches events

View Source
Declaration
protected void _pollingThreadFunc(object state)
Parameters
TypeName
System.Objectstate

_pollAnalog()

Get the Status of the analog IO lines Update all the Input and the Output values

View Source
Declaration
protected void _pollAnalog()

_pollIOASCII()

Get the status of the Digital IO lines first check the current values if there are any inputs also check the latched values if the latches have been triggered reset them

View Source
Declaration
protected void _pollIOASCII()

_pollIOModbusTCP()

Get the status of the IO lines first check the current values if there are any inputs also check the counters

View Source
Declaration
protected void _pollIOModbusTCP()

_dispatchDigitalEvents()

Only Dispatch events after the state of all the digital IOLines has been updated by the _pollIO function otherwise event handlers may experience inconsistencies in the digital IOLine data

View Source
Declaration
protected void _dispatchDigitalEvents()

_dispatchAnalogEvents()

Only Dispatch events after the state of all the analog IO lines has been updated by the _pollAnalog function other event handlers may experience inconsistencies in the analog IO line data

View Source
Declaration
protected void _dispatchAnalogEvents()

Dispose(bool)

Dispose of this Brainboxes Remote IO Device

View Source
Declaration
protected override void Dispose(bool itIsSafeToAlsoFreeManagedObjects)
Parameters
TypeName
System.BooleanitIsSafeToAlsoFreeManagedObjects

Create(string, int, int)

Supply a connection IP address or com port and the correct ED device will be created and returned.

View Source
Declaration
public static EDDevice Create(string ipAddressOrComPort, int portOrBaudRate = 0, int timeout = 2000)
Returns

Brainboxes.IO.EDDevice: An Brainboxes.IO.EDDevice subclass matching the detected device type, or null if the device type cannot be determined.

Parameters
TypeNameDescription
System.StringipAddressOrComPortEither an IP address e.g. "192.168.0.1" or a COM port name e.g. "COM3".
System.Int32portOrBaudRateOptional. Either the IP port number (e.g. 9500 for ASCII, 502 for Modbus) or the COM port baud rate (e.g. 115200). If not supplied, the port is determined by querying the device.
System.Int32timeoutThe connection timeout in milliseconds. Defaults to 2000ms.

Events

_ioLinesChanged

IOLines Changed Event

View Source
Declaration
protected event IOLinesChangedEventHandler _ioLinesChanged
Event Type

Brainboxes.IO.IOLinesChangedEventHandler

_ioLineChanged

IOLine Changed Event

View Source
Declaration
protected event IOLineChangedEventHandler _ioLineChanged
Event Type

Brainboxes.IO.IOLineChangedEventHandler

_ioLineRisingEdge

IOLine Rising Edge Event

View Source
Declaration
protected event IOLineChangedEventHandler _ioLineRisingEdge
Event Type

Brainboxes.IO.IOLineChangedEventHandler

_ioLineFallingEdge

IOLine Falling Edge Event

View Source
Declaration
protected event IOLineChangedEventHandler _ioLineFallingEdge
Event Type

Brainboxes.IO.IOLineChangedEventHandler

_ioLineCount

IOLine Count Event

View Source
Declaration
protected event IOLineChangedEventHandler _ioLineCount
Event Type

Brainboxes.IO.IOLineChangedEventHandler

_aioLineChangedDelta

Analog IO Line Delta changed event

View Source
Declaration
protected event AIOLineChangedEventHandler _aioLineChangedDelta
Event Type

Brainboxes.IO.AIOLineChangedEventHandler

_aioLineChangedTarget

Analog IO Line Target changed event

View Source
Declaration
protected event AIOLineChangedEventHandler _aioLineChangedTarget
Event Type

Brainboxes.IO.AIOLineChangedEventHandler

_aioLineChangedTargetRange

Analog IO Line Target range changed event

View Source
Declaration
protected event AIOLineChangedEventHandler _aioLineChangedTargetRange
Event Type

Brainboxes.IO.AIOLineChangedEventHandler

IOLinesChanged

Register an event with this handler to be notified when the state of one or more IOLines change within a polling interval This is useful when a state in the program is dependent on 2 or more ioLine states

View Source
Declaration
public event IOLinesChangedEventHandler IOLinesChanged
Event Type

Brainboxes.IO.IOLinesChangedEventHandler

IOLineChanged

Register an event with this handler to be notified when the state of an input or output line changes

View Source
Declaration
public event IOLineChangedEventHandler IOLineChanged
Event Type

Brainboxes.IO.IOLineChangedEventHandler

IOLineRisingEdge

Register an event with this handler to be notified when the state of an input or output line goes from 0 -> 1 / low to high / closed to open

View Source
Declaration
public event IOLineChangedEventHandler IOLineRisingEdge
Event Type

Brainboxes.IO.IOLineChangedEventHandler

IOLineFallingEdge

Register an event with this handler to be notified when the state of an input or output line goes from 1 -> 0 / high to low / open to closed

View Source
Declaration
public event IOLineChangedEventHandler IOLineFallingEdge
Event Type

Brainboxes.IO.IOLineChangedEventHandler

IOLineCount

Register an event with this handler to be notified when the state of an input changes increment the count of the IOLine

View Source
Declaration
public event IOLineChangedEventHandler IOLineCount
Event Type

Brainboxes.IO.IOLineChangedEventHandler

Implements

  • Brainboxes.IO.IEDDevice
  • Brainboxes.IO.IDevice<Brainboxes.IO.IConnection,Brainboxes.IO.IIOProtocol>
  • System.IDisposable