Table of Contents

Class AsciiCommandExecutorBase

Namespace
TechnologySolutions.Rfid.AsciiProtocol
Assembly
TechnologySolutions.Rfid.AsciiProtocol.Core.dll

A base class that implements responder chain management

public abstract class AsciiCommandExecutorBase : IAsciiCommandExecuting, IAsciiCommander, IAsciiResponderChain, IDisposable
Inheritance
AsciiCommandExecutorBase
Implements
Derived
Inherited Members
Extension Methods

Constructors

AsciiCommandExecutorBase()

Initializes a new instance of the AsciiCommandExecutorBase class

protected AsciiCommandExecutorBase()

Properties

HasSynchronousResponder

Gets a value indicating whether the chain has a synchronous responder

public bool HasSynchronousResponder { get; }

Property Value

bool

IsInCommand

Gets a value indicating whether a command is being executed

public bool IsInCommand { get; }

Property Value

bool

IsResponsive

Gets a value indicating whether the last command completed as expected i.e. did not timeout.

public bool IsResponsive { get; }

Property Value

bool

LastActivityTime

Gets or sets the time of the readers last activity (send or receive)

public DateTime LastActivityTime { get; }

Property Value

DateTime

LastCommandLine

Gets the last command line sent

public string LastCommandLine { get; }

Property Value

string

Remarks

Because TSLAsciiCommands add a unique id number each time their commandLine property is accessed this property can be used (primarily for debugging) to get the actual command line issued (if examined immediately after the command is executed)

ResponderChain

Gets the chain of responders that handle responses to commands

public IEnumerable<IAsciiCommandResponder> ResponderChain { get; }

Property Value

IEnumerable<IAsciiCommandResponder>

Methods

AbortSynchronousCommand()

Terminates any executing synchronous command

public void AbortSynchronousCommand()

Remarks

If ExecuteCommand is blocking waiting for a command response this will abort the call and the method will return. The synchronous command being executed will be left in an incomplete state with its response incomplete

AddResponder(IAsciiCommandResponder)

Add a responder to the responder chain

public void AddResponder(IAsciiCommandResponder responder)

Parameters

responder IAsciiCommandResponder

The responder to add

AddSynchronousResponder()

Add a synchronous responder into the chain

public void AddSynchronousResponder()

CanExecuteCommand()

Returns a value indicating whether a command can be executed

public abstract bool CanExecuteCommand()

Returns

bool

True if ExecuteCommand can be called

Remarks

This should be false when the reader is not connected or currently executing a command

ClearResponders()

Clear all responders from the responder chain

public void ClearResponders()

Dispose()

Disposes an instance of the AsciiCommandExecutorBase class

public void Dispose()

Dispose(bool)

Disposes an instance of the AsciiCommandExecutorBase class

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

True to dispose managed as well as native resources

ExecuteCommand(IAsciiCommand, IAsciiCommandSynchronousResponder)

Execute the given command.

public virtual void ExecuteCommand(IAsciiCommand command, IAsciiCommandSynchronousResponder synchronousResponder)

Parameters

command IAsciiCommand

The command to be executed

synchronousResponder IAsciiCommandSynchronousResponder

For command to execute synchronously (not return until complete) set this to a responder (e.g. command.Responder) to receive the command response. To execute the command asynchronously and let the responder chain handle the events set this to null (Nothing in Visual Basic).

Remarks

Command execution is asynchronous unless the command has a (non-nil) synchronousCommandResponder then the command will be executed synchronously. Synchronous behaviour requires prior call to addSynchronousResponder. Warning: derived classes must call the base implementation to ensure synchronous commands work correctly

ExecuteCommandAsync(IAsciiCommand, IAsciiCommandSynchronousResponder)

Execute the given command.

public Task ExecuteCommandAsync(IAsciiCommand command, IAsciiCommandSynchronousResponder synchronousResponder)

Parameters

command IAsciiCommand

The command to be executed

synchronousResponder IAsciiCommandSynchronousResponder

For command to execute synchronously (not return until complete) set this to a responder (e.g. command.Responder) to receive the command response. To execute the command asynchronously and let the responder chain handle the events set this to null (Nothing in Visual Basic).

Returns

Task

Remarks

Command execution is asynchronous unless the command has a (non-nil) synchronousCommandResponder then the command will be executed synchronously. Synchronous behaviour requires prior call to addSynchronousResponder. Warning: derived classes must call the base implementation to ensure synchronous commands work correctly

OnResponderChainError(IAsciiCommandResponder, IAsciiResponseLine, Exception)

Raises the ResponderChain Error event

protected virtual void OnResponderChainError(IAsciiCommandResponder responder, IAsciiResponseLine line, Exception ex)

Parameters

responder IAsciiCommandResponder
line IAsciiResponseLine
ex Exception

ProcessReceivedLine(string, bool)

Called from ProcessReceivedLines(IList<string>) to process each line received from the reader

protected virtual void ProcessReceivedLine(string line, bool moreAvailable)

Parameters

line string

The received line

moreAvailable bool

True if not the last line in the set

ProcessReceivedLines(IList<string>)

This should be called when new data is received from the reader

protected virtual void ProcessReceivedLines(IList<string> receivedLines)

Parameters

receivedLines IList<string>

A number of complete lines received from the reader

RemoveResponder(IAsciiCommandResponder)

Remove a responder from the responder chain

public void RemoveResponder(IAsciiCommandResponder responder)

Parameters

responder IAsciiCommandResponder

The responder to remove

RemoveSynchronousResponder()

Remove the synchronous responder from the chain

public void RemoveSynchronousResponder()

Send(string)

Send the given string as a CrLf terminated string, to the reader. This method waits until the command has been successfully sent

public virtual void Send(string line)

Parameters

line string

line The ASCII string to send to the device

Exceptions

InvalidOperationException

if no device is connected

Events

ResponderChainError

The handler for errors in the ResponderChain

public event EventHandler<ResponderChainExceptionArgs> ResponderChainError

Event Type

EventHandler<ResponderChainExceptionArgs>