Class PSMultiCommSimple
- Namespace
- PalmSens.Core.Simplified
- Assembly
- PalmSens.Core.Simplified.dll
public class PSMultiCommSimple
- Inheritance
-
PSMultiCommSimple
- Inherited Members
Constructors
PSMultiCommSimple(IPlatformMulti, IPlatformInvoker)
Initializes a new instance of the PSMultiCommSimple class. This class handles is used to perform measurements and control a collection of channels manually. It requires a reference to the platform specific instance of the class, i.e. PSMultiCommSimpleWinForms, PSMultiCommSimpleWPF or PSMultiCommSimpleXamarin
public PSMultiCommSimple(IPlatformMulti platform, IPlatformInvoker platformInvoker)
Parameters
platformIPlatformMultiThe reference to the platform specific PSMultiCommSimple class.
platformInvokerIPlatformInvoker
Exceptions
- ArgumentNullException
Platform cannot be null
Properties
Capabilities
Gets the capabilities of the connected channels.
public DeviceCapabilities[] Capabilities { get; }
Property Value
- DeviceCapabilities[]
The channel capabilities.
Exceptions
- NullReferenceException
Not connected to any channels.
ChannelStates
Gets the states of the connected channels.
public CommManager.DeviceState[] ChannelStates { get; }
Property Value
- DeviceState[]
The states of the connected channels.
Exceptions
- NullReferenceException
Not connected to any channels.
Comms
Gets or sets the connected channels' CommManagers and (un)subscribes the corresponding events.
public CommManager[] Comms { get; }
Property Value
- CommManager[]
The CommManager.
CommsByChannelIndex
Gets a dictionary connections by channel index. Do not modify this dictionary.
public Dictionary<int, CommManager> CommsByChannelIndex { get; }
Property Value
- Dictionary<int, CommManager>
The index of the comms by channel.
Connected
Gets a value indicating whether PSCommSimple is connected to any channels.
public bool Connected { get; }
Property Value
- bool
trueif connected; otherwise,false.
ConnectedChannels
Gets the connected channel types.
public enumDeviceType[] ConnectedChannels { get; }
Property Value
- enumDeviceType[]
The connected channel types.
Exceptions
- NullReferenceException
Not connected to any channels.
ConnectedDevices
Gets the connected devices.
public Device[] ConnectedDevices { get; }
Property Value
- Device[]
The connected devices.
Exceptions
- NullReferenceException
Not connected to any channels.
IsCellOn
Gets values indicating whether the connected channels' [cell is on].
public bool[] IsCellOn { get; }
Property Value
- bool[]
trueif [cell is on]; otherwise,false.
Exceptions
- NullReferenceException
Not connected to any channels.
NConnectedChannels
Gets the number of connected channels.
public int NConnectedChannels { get; }
Property Value
- int
The n connected channels.
Methods
AbortAllActiveMeasurementsAsync()
Aborts all active measurements channels.
public Task AbortAllActiveMeasurementsAsync()
Returns
Exceptions
- NullReferenceException
Not connected to a channel.
- Exception
The channel is not currently performing measurement
AbortMeasurementAsync(int)
Aborts the active measurement on the specified channel.
public Task AbortMeasurementAsync(int channel)
Parameters
channelint
Returns
Exceptions
- NullReferenceException
Not connected to a channel.
- Exception
The channel is not currently performing measurement
AbortMeasurementsAsync(int[])
Aborts the active measurement on the specified channels.
public Task AbortMeasurementsAsync(int[] channels)
Parameters
channelsint[]
Returns
Exceptions
- NullReferenceException
Not connected to a channel.
- Exception
The channel is not currently performing measurement
CheckConnections(IList<Device>, CancellationToken)
public Task CheckConnections(IList<Device> devices, CancellationToken cancellationToken)
Parameters
devicesIList<Device>cancellationTokenCancellationToken
Returns
Connect(IReadOnlyList<Device>, IList<int>)
Connects the specified devices.
public Task Connect(IReadOnlyList<Device> devices, IList<int> channelIndices = null)
Parameters
devicesIReadOnlyList<Device>The devices.
channelIndicesIList<int>The channel indices.
Returns
Disconnect()
Disconnects from the connected channels.
public Task Disconnect()
Returns
Exceptions
- NullReferenceException
Not connected to any channels.
Dispose()
public void Dispose()
GetAvailableDevicesAsync()
Returns an array of available instruments/channels.
public Task<IReadOnlyList<Device>> GetAvailableDevicesAsync()
Returns
- Task<IReadOnlyList<Device>>
GetInternalStorageHandler(int)
Get an internal storage handler that will read the current connected device stored files. This is only for devices that have internal storage.
public IInternalStorageBrowser GetInternalStorageHandler(int channel)
Parameters
channelint
Returns
- IInternalStorageBrowser
A new instance of the internal storage handler for the current connection.
Exceptions
- InvalidOperationException
This is thrown when the device is not connected or if the device does not support storage.
- ArgumentException
This is thrown when the channel passed in does not exist in the current communications mapping.
GetTaskResultsAndOrExceptions<T>(Func<int, Task<(T Result, int ChannelIndex, Exception Exception)>>, IList<int>)
Runs an Func delegate asynchronously on the specified channels and handles any exceptions preventing successful results from being returned unless throwExceptions is specifically set to true
public static Task<IReadOnlyList<(T Result, int ChannelIndex, Exception Exception)>> GetTaskResultsAndOrExceptions<T>(Func<int, Task<(T Result, int ChannelIndex, Exception Exception)>> func, IList<int> channels)
Parameters
Returns
- Task<IReadOnlyList<(T Result, int ChannelIndex, Exception Exception)>>
Type Parameters
T
IsValidMethod(Method)
Determines whether [the specified method] is compatible with all connected channels.
public bool[] IsValidMethod(Method method)
Parameters
methodMethodThe method.
Returns
- bool[]
trueif the method is valid; otherwise,false.
IsValidMethod(Method, int)
Determines whether [the specified method] is compatible with the specified channel.
public bool IsValidMethod(Method method, int channel)
Parameters
methodMethodThe method.
channelintThe specified channel.
Returns
- bool
trueif the method is valid; otherwise,false.
IsValidMethod(Method, int[])
Determines whether [the specified method] is compatible with the specified channels.
public bool[] IsValidMethod(Method method, int[] channels)
Parameters
methodMethodThe method.
channelsint[]The specified channels.
Returns
- bool[]
trueif the method is valid; otherwise,false.
MeasureAllChannelsAsync(Method)
Awaits a measurement as specified in the method until completion on all channels.
public Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>> MeasureAllChannelsAsync(Method method)
Parameters
methodMethodThe method containing the measurement parameters.
Returns
- Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>>
A SimpleMeasurement instance containing all the data related to the measurement.
MeasureAllChannelsAsync(Method, int)
Awaits a measurement as specified in the method until completion on all channels.
public Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>> MeasureAllChannelsAsync(Method method, int muxChannel)
Parameters
methodMethodThe method containing the measurement parameters.
muxChannelintThe mux channel to measure on.
Returns
- Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>>
A SimpleMeasurement instance containing all the data related to the measurement.
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to specified channel.
- ArgumentException
Method is incompatible with the connected channel.
- Exception
Could not start measurement.
MeasureAsync(Method, int)
Runs a measurement as specified in the method on the specified channel.
public Task<SimpleMeasurement> MeasureAsync(Method method, int channel)
Parameters
methodMethodThe method containing the measurement parameters.
channelint
Returns
- Task<SimpleMeasurement>
A SimpleMeasurement instance containing all the data related to the measurement.
MeasureAsync(Method, int, int, TaskBarrier)
Awaits a measurement as specified in the method on the specified channel until completion.
public Task<SimpleMeasurement> MeasureAsync(Method method, int channel, int muxChannel, TaskBarrier taskBarrier = null)
Parameters
methodMethodThe method containing the measurement parameters.
channelintThe channel.
muxChannelintThe mux channel to measure on.
taskBarrierTaskBarrier
Returns
- Task<SimpleMeasurement>
A SimpleMeasurement instance containing all the data related to the measurement.
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to specified channel.
- ArgumentException
Method is incompatible with the connected channel.
- Exception
Could not start measurement.
MeasureAsync(Method, int[])
Awaits a measurement as specified in the method until completion on the specified collection of channels.
public Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>> MeasureAsync(Method method, int[] channels)
Parameters
methodMethodThe method containing the measurement parameters.
channelsint[]The channels.
Returns
- Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>>
A SimpleMeasurement instance containing all the data related to the measurement.
MeasureAsync(Method, int[], int)
Awaits a measurement as specified in the method until completion on the specified collection of channels. No results will be returned if other measurements were started correctly.
public Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>> MeasureAsync(Method method, int[] channels, int muxChannel)
Parameters
methodMethodThe method containing the measurement parameters.
channelsint[]The channels.
muxChannelintThe mux channel to measure on.
Returns
- Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>>
An array of ValueTuples containing:
- An instance of the SimpleMeasurement instance containing all the data related to the measurement, null in the case of an exception
- The channel index
- Null unless an exception was caught
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to specified channel.
- ArgumentException
Method is incompatible with the connected channel.
- Exception
Could not start measurement.
ReadCellCurrentAsync()
Reads the cell current on all channels.
public Task<IReadOnlyList<(float Current, int ChannelIndex, Exception Exception)>> ReadCellCurrentAsync()
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
ReadCellCurrentAsync(int)
Reads the cell current on the specified channel.
public Task<float> ReadCellCurrentAsync(int channel)
Parameters
channelint
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
ReadCellCurrentAsync(int[])
Reads the cell current on the specified channels.
public Task<IReadOnlyList<(float Current, int ChannelIndex, Exception Exception)>> ReadCellCurrentAsync(int[] channels)
Parameters
channelsint[]
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
ReadCellPotentialAsync()
Reads the cell potential on all channels.
public Task<IReadOnlyList<(float Potential, int ChannelIndex, Exception Exception)>> ReadCellPotentialAsync()
Returns
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to a channel
- Exception
Channel must be in idle mode for manual control
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
ReadCellPotentialAsync(int)
Reads the cell potential on the specified channel.
public Task<float> ReadCellPotentialAsync(int channel)
Parameters
channelintThe channel.
Returns
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to a channel
- Exception
Channel must be in idle mode for manual control
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
ReadCellPotentialAsync(int[])
Reads the cell potential on the specified channels.
public Task<IReadOnlyList<(float Potential, int ChannelIndex, Exception Exception)>> ReadCellPotentialAsync(int[] channels)
Parameters
channelsint[]
Returns
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to a channel
- Exception
Channel must be in idle mode for manual control
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
RunAsyncAggregateExceptions(Func<int, Task<(int ChannelIndex, Exception Exception)>>, int[])
Runs a Func delegate asynchronously on the specified channels and aggregates any exceptions
public static Task RunAsyncAggregateExceptions(Func<int, Task<(int ChannelIndex, Exception Exception)>> func, int[] channels)
Parameters
Returns
SetCellCurrentAsync(float)
Sets the cell current on all channels.
public Task SetCellCurrentAsync(float current)
Parameters
currentfloatThe current.
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
SetCellCurrentAsync(float, int)
Sets the cell current on the specified channel.
public Task SetCellCurrentAsync(float current, int channel)
Parameters
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
SetCellCurrentAsync(float, int[])
Sets the cell current on the specified channels.
public Task SetCellCurrentAsync(float current, int[] channels)
Parameters
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
SetCellPotentialAsync(float)
Sets the cell potential on all channels.
public Task SetCellPotentialAsync(float potential)
Parameters
potentialfloatThe potential.
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
SetCellPotentialAsync(float, int)
Sets the cell potential on the specified channel.
public Task SetCellPotentialAsync(float potential, int channel)
Parameters
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
SetCellPotentialAsync(float, int[])
Sets the cell potential on the specified channels.
public Task SetCellPotentialAsync(float potential, int[] channels)
Parameters
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
SetCurrentRangeAsync(CurrentRange)
Sets the current range on all channels.
public Task SetCurrentRangeAsync(CurrentRange currentRange)
Parameters
currentRangeCurrentRangeThe current range.
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
SetCurrentRangeAsync(CurrentRange, int)
Sets the current range on the specified channel.
public Task SetCurrentRangeAsync(CurrentRange currentRange, int channel)
Parameters
currentRangeCurrentRangeThe current range.
channelint
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
SetCurrentRangeAsync(CurrentRange, int[])
Sets the current range on the specified channels.
public Task SetCurrentRangeAsync(CurrentRange currentRange, int[] channels)
Parameters
currentRangeCurrentRangeThe current range.
channelsint[]
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
StartMeasureAllChannelsAsync(Method, int, bool)
Starts a measurement as specified in the method on all channels.
public Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>> StartMeasureAllChannelsAsync(Method method, int muxChannel, bool useHWsync = false)
Parameters
methodMethodThe method containing the measurement parameters.
muxChannelintThe mux channel to measure on.
useHWsyncbool
Returns
- Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>>
A SimpleMeasurement instance containing all the data related to the measurement.
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to specified channel.
- ArgumentException
Method is incompatible with the connected channel.
- Exception
Could not start measurement.
StartMeasureAsync(Method, int)
Starts a measurement as specified in the method on the specified channel.
public Task<SimpleMeasurement> StartMeasureAsync(Method method, int channel)
Parameters
methodMethodThe method containing the measurement parameters.
channelint
Returns
- Task<SimpleMeasurement>
A SimpleMeasurement instance containing all the data related to the measurement.
StartMeasureAsync(Method, int, int, TaskBarrier)
Starts a measurement as specified in the method on the specified channel.
public Task<SimpleMeasurement> StartMeasureAsync(Method method, int channel, int muxChannel, TaskBarrier taskBarrier = null)
Parameters
methodMethodThe method containing the measurement parameters.
channelintThe channel.
muxChannelintThe mux channel to measure on.
taskBarrierTaskBarrier
Returns
- Task<SimpleMeasurement>
A SimpleMeasurement instance containing all the data related to the measurement.
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to specified channel.
- ArgumentException
Method is incompatible with the connected channel.
- Exception
Could not start measurement.
StartMeasureAsync(Method, int[], bool)
Starts a measurement as specified in the method on the specified channel.
public Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>> StartMeasureAsync(Method method, int[] channels, bool useHWSync = false)
Parameters
methodMethodThe method containing the measurement parameters.
channelsint[]The channels.
useHWSyncbool
Returns
- Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>>
A SimpleMeasurement instance containing all the data related to the measurement.
StartMeasurementAllChannelsAsync(Method, bool)
Starts a measurement as specified in the method on the specified channel.
public Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>> StartMeasurementAllChannelsAsync(Method method, bool useHWSync = false)
Parameters
methodMethodThe method containing the measurement parameters.
useHWSyncbool
Returns
- Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>>
A SimpleMeasurement instance containing all the data related to the measurement.
StartMeasurementAsync(Method, int[], int, bool)
Starts a measurement as specified in the method on the specified collection of channels. No results will be returned if other measurements were started correctly.
public Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>> StartMeasurementAsync(Method method, int[] channels, int muxChannel, bool useHWSync = false)
Parameters
methodMethodThe method containing the measurement parameters.
channelsint[]The channels.
muxChannelintThe mux channel to measure on.
useHWSyncbool
Returns
- Task<IReadOnlyList<(SimpleMeasurement Measurement, int ChannelIndex, Exception Exception)>>
An array of ValueTuples containing:
- An instance of the SimpleMeasurement instance containing all the data related to the measurement, null in the case of an exception
- The channel index
- Null unless an exception was caught
Exceptions
- NullReferenceException
Not connected to any channels. or Not connected to specified channel.
- ArgumentException
Method is incompatible with the connected channel.
- Exception
Could not start measurement.
TurnCellOffAsync()
Turns the cell off on all channels.
public Task TurnCellOffAsync()
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
TurnCellOffAsync(int)
Turns the cell off on specified channel.
public Task TurnCellOffAsync(int channel)
Parameters
channelintThe channel.
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
TurnCellOffAsync(int[])
Turns the cell off on specified channels.
public Task TurnCellOffAsync(int[] channels)
Parameters
channelsint[]The channels.
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
TurnCellOffTask(int, bool)
Turns the cell off on the specified channel.
public Task<(int ChannelIndex, Exception Exception)> TurnCellOffTask(int channel, bool throwExceptions)
Parameters
channelintThe channel.
throwExceptionsboolif set to
true[throw on exceptions], otherwise return them.
Returns
- Task<(int ChannelIndex, Exception Exception)>
A ValueTuple containing the channel index and any exceptions that were thrown
TurnCellOnAsync()
Turns the cell on on all channels.
public Task TurnCellOnAsync()
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
TurnCellOnAsync(int)
Turns the cell on on specified channel.
public Task TurnCellOnAsync(int channel)
Parameters
channelintThe channel.
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
TurnCellOnAsync(int[])
Turns the cell on on specified channels.
public Task TurnCellOnAsync(int[] channels)
Parameters
channelsint[]The channels.
Returns
Exceptions
- NullReferenceException
Not connected to a channel
- Exception
Channel must be in idle mode for manual control
ValidateMethod(Method, out bool[], out List<string>[])
Validates whether the specified method is compatible with the capabilities of all connected channels.
public void ValidateMethod(Method method, out bool[] isValidMethod, out List<string>[] errors)
Parameters
methodMethodThe method containing the measurement parameters.
isValidMethodbool[]if set to
true[is valid method].errorsList<string>[]The errors.
Exceptions
- NullReferenceException
Not connected to a channel.
- ArgumentNullException
The specified method cannot be null.
ValidateMethod(Method, int, out bool, out List<string>)
Validates whether the specified method is compatible with the capabilities of the specified connected channel.
public void ValidateMethod(Method method, int channel, out bool isValidMethod, out List<string> errors)
Parameters
methodMethodThe method containing the measurement parameters.
channelintThe specified channel.
isValidMethodboolif set to
true[is valid method].errorsList<string>The errors.
Exceptions
- NullReferenceException
Not connected to a channel.
- ArgumentNullException
The specified method cannot be null.
ValidateMethod(Method, int[], out bool[], out List<string>[])
Validates whether the specified method is compatible with the capabilities of the specified connected channels.
public void ValidateMethod(Method method, int[] channels, out bool[] isValidMethod, out List<string>[] errors)
Parameters
methodMethodThe method containing the measurement parameters.
channelsint[]The specified channels.
isValidMethodbool[]if set to
true[is valid method].errorsList<string>[]The errors.
Exceptions
- NullReferenceException
Not connected to a channel.
- ArgumentNullException
The specified method cannot be null.
Events
Disconnected
Occurs when a channel is [disconnected].
public event MultiChannelDisconnectedEventHandler Disconnected
Event Type
MeasurementEnded
Occurs when a measurement has ended.
public event MultiChannelMeasurementEventHandler MeasurementEnded
Event Type
MeasurementStarted
Occurs at the start of a new measurement.
public event MultiChannelMeasurementEventHandler MeasurementStarted
Event Type
ReceiveStatus
Occurs when a channel status package is received, these packages are not sent during a measurement.
public event MultiChannelStatusEventHandler ReceiveStatus
Event Type
SimpleCurveStartReceivingData
Occurs when a new [SimpleCurve starts receiving data].
public event PSCommSimple.SimpleCurveStartReceivingDataHandler SimpleCurveStartReceivingData
Event Type
StateChanged
Occurs when the devive's [state changed].
public event MultiChannelStateChangedEventHandler StateChanged