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
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
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
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
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
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
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
public int IOLineCacheTimeout { get; set; }
Fields
_numberOfRegisteredEvents
The number of events registered with this EDDevice
View Source
protected int _numberOfRegisteredEvents
_IOCounterUpdateDirection
whether the Digital Input IO Line counter updates on a rising edge or a falling edge
View Source
protected IOChangeTypes _IOCounterUpdateDirection
_pollingTimer
The timer thread used for polling IO
View Source
protected Timer _pollingTimer
_threadShouldBeRunning
flag to indicate whether the pollingThread should be running
View Source
protected volatile bool _threadShouldBeRunning
_ioLineCacheTimeout
cache timeout is also the polling interval
View Source
protected int _ioLineCacheTimeout
Methods
SendCommand(string)
Send a command to the Brainboxes device using the supplied protocol.
View Source
public string SendCommand(string command)
Returns
System.String: Response or null if no response
Parameters
| Type | Name | Description |
|---|---|---|
System.String | command | command 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
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
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
protected void _reconnectAfterResetOrRestart(string restartOrReconnect)
Parameters
| Type | Name |
|---|---|
System.String | restartOrReconnect |
Connect()
Connect to a Brainboxes Remote IO Device
View Source
public override void Connect()
Disconnect()
Disconnect from a Brainboxes Remote IO Device
View Source
public override void Disconnect()
ToString()
ToString
View Source
public override string ToString()
Returns
System.String
Describe()
Give a complete summary of the EDDevice
View Source
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
public void SubscribeToTargetEvent(ref AIOLineChangedEventHandler function, double target)
Parameters
| Type | Name |
|---|---|
| Brainboxes.IO.AIOLineChangedEventHandler | function |
System.Double | target |
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
public void SubscribeToDeltaEvent(ref AIOLineChangedEventHandler function, double delta)
Parameters
| Type | Name |
|---|---|
| Brainboxes.IO.AIOLineChangedEventHandler | function |
System.Double | delta |
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
public void SubscribeToTargetRangeEvent(ref AIOLineChangedEventHandler function, double target, double delta)
Parameters
| Type | Name |
|---|---|
| Brainboxes.IO.AIOLineChangedEventHandler | function |
System.Double | target |
System.Double | delta |
UnsubscribeToDeltaEvent(ref AIOLineChangedEventHandler)
Unsubscribe a registered delta event with this handler to stop being notified when this event is triggered
View Source
public void UnsubscribeToDeltaEvent(ref AIOLineChangedEventHandler function)
Parameters
| Type | Name |
|---|---|
| Brainboxes.IO.AIOLineChangedEventHandler | function |
UnsubscribeToTargetEvent(ref AIOLineChangedEventHandler)
Unsubscribe a registered target event with this handler to stop being notified when this event is triggered
View Source
public void UnsubscribeToTargetEvent(ref AIOLineChangedEventHandler function)
Parameters
| Type | Name |
|---|---|
| Brainboxes.IO.AIOLineChangedEventHandler | function |
UnsubscribeToTargetRangeEvent(ref AIOLineChangedEventHandler)
Unsubscribe a registered target range event with this handler to stop being notified when this event is triggered
View Source
public void UnsubscribeToTargetRangeEvent(ref AIOLineChangedEventHandler function)
Parameters
| Type | Name |
|---|---|
| Brainboxes.IO.AIOLineChangedEventHandler | function |
_eventAdded()
Called whenever an event is added to any of the event collection
View Source
protected void _eventAdded()
_eventRemoved()
Called whenever an event is removed from any of the event collections
View Source
protected void _eventRemoved()
_startPollingForChanges()
Spins up a background timing thread which polls the Brainboxes ED Device periodically at ioLineCacheTimeout
View Source
protected void _startPollingForChanges()
_stopPollingForChanges()
Stop and dispose the background thread which is polling for changes on the Brainboxes ED Device
View Source
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
protected void _pollingThreadFunc(object state)
Parameters
| Type | Name |
|---|---|
System.Object | state |
_pollAnalog()
Get the Status of the analog IO lines Update all the Input and the Output values
View Source
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
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
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
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
protected void _dispatchAnalogEvents()
Dispose(bool)
Dispose of this Brainboxes Remote IO Device
View Source
protected override void Dispose(bool itIsSafeToAlsoFreeManagedObjects)
Parameters
| Type | Name |
|---|---|
System.Boolean | itIsSafeToAlsoFreeManagedObjects |
Create(string, int, int)
Supply a connection IP address or com port and the correct ED device will be created and returned.
View Source
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
| Type | Name | Description |
|---|---|---|
System.String | ipAddressOrComPort | Either an IP address e.g. "192.168.0.1" or a COM port name e.g. "COM3". |
System.Int32 | portOrBaudRate | Optional. 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.Int32 | timeout | The connection timeout in milliseconds. Defaults to 2000ms. |
Events
_ioLinesChanged
IOLines Changed Event
View Source
protected event IOLinesChangedEventHandler _ioLinesChanged
Event Type
Brainboxes.IO.IOLinesChangedEventHandler
_ioLineChanged
IOLine Changed Event
View Source
protected event IOLineChangedEventHandler _ioLineChanged
Event Type
Brainboxes.IO.IOLineChangedEventHandler
_ioLineRisingEdge
IOLine Rising Edge Event
View Source
protected event IOLineChangedEventHandler _ioLineRisingEdge
Event Type
Brainboxes.IO.IOLineChangedEventHandler
_ioLineFallingEdge
IOLine Falling Edge Event
View Source
protected event IOLineChangedEventHandler _ioLineFallingEdge
Event Type
Brainboxes.IO.IOLineChangedEventHandler
_ioLineCount
IOLine Count Event
View Source
protected event IOLineChangedEventHandler _ioLineCount
Event Type
Brainboxes.IO.IOLineChangedEventHandler
_aioLineChangedDelta
Analog IO Line Delta changed event
View Source
protected event AIOLineChangedEventHandler _aioLineChangedDelta
Event Type
Brainboxes.IO.AIOLineChangedEventHandler
_aioLineChangedTarget
Analog IO Line Target changed event
View Source
protected event AIOLineChangedEventHandler _aioLineChangedTarget
Event Type
Brainboxes.IO.AIOLineChangedEventHandler
_aioLineChangedTargetRange
Analog IO Line Target range changed event
View Source
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
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
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
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
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
public event IOLineChangedEventHandler IOLineCount
Event Type
Brainboxes.IO.IOLineChangedEventHandler
Implements
- Brainboxes.IO.IEDDevice
Brainboxes.IO.IDevice<Brainboxes.IO.IConnection,Brainboxes.IO.IIOProtocol>System.IDisposable