Class ScannerModule
Represents a module for a barcode scanner.
public class ScannerModule : InitializableCompositeModule, ICompositeModule, IInitializable, INotifyPropertyChangedEx, IHasServiceView, IScanner, ILisrtModule, INotifyPropertyChanged, IHasDeviceLabel
- Inheritance
-
PropertyChangedBaseScannerModule
- Implements
-
INotifyPropertyChangedEx
- Inherited Members
-
PropertyChangedBase.Refresh()PropertyChangedBase.IsNotifyingPropertyChangedBase.PropertyChanged
- Extension Methods
Examples
This example shows how to use the ScannerModule with a serial port:
var serialPort = new SerialPortModule("RS232")
{
Encoding = Encoding.ASCII,
// The barcode scanner must be configured accordingly
EndDelimiter = Encoding.ASCII.GetBytes("\r"),
};
new ScannerModule("Scanner", serialPort);
Constructors
ScannerModule(string, ICommunication)
Initializes a new instance of the ScannerModule class.
public ScannerModule(string name, ICommunication communication)
Parameters
name
stringThe name of the module.
communication
ICommunicationThe communication port.
Exceptions
- ArgumentNullException
Thrown when
communication
is null orname
is null, empty or whitespace.
Properties
DeviceLabel
Gets or sets the device label.
[Configuration("")]
public string DeviceLabel { get; set; }
Property Value
Icon
Gets an icon which is representative for the module.
public override Uri Icon { get; }
Property Value
InstanceID
Gets or sets the instance ID.
public int InstanceID { get; set; }
Property Value
Methods
Exit()
Deinitializes the module and its communication.
public override void Exit()
Initialize()
Initializes the module and its communication module.
public override void Initialize()
OnCommunicationDataReceived(object, DataReceivedEventArgs)
Executed on DataReceived event.
protected virtual void OnCommunicationDataReceived(object sender, DataReceivedEventArgs e)
Parameters
sender
objectThe ICommunication sender.
e
DataReceivedEventArgsThe event args of the DataReceived event.
Remarks
Receives the string from ICommunication and invokes the CodeScanned event.
ShowServiceView()
Shows the service window.
public virtual void ShowServiceView()
WaitForCodeScanned(int)
Waits until a barcode is scanned.
public virtual string WaitForCodeScanned(int timeoutInMilliseconds)
Parameters
Returns
- string
The scanned code.
Exceptions
- NotInitializedException
Thrown when the module is not initialized.
- ArgumentOutOfRangeException
Thrown when
timeoutInMilliseconds
is a negative number other than -1 milliseconds, which represents an infinite time-out. -or- The number of milliseconds in timeout is greater than MaxValue.- TimeoutException
Thrown when
timeoutInMilliseconds
has elapsed.
WaitForCodeScanned(CancellationToken, int)
Waits until a barcode is scanned.
public virtual string WaitForCodeScanned(CancellationToken cancellationToken, int timeoutInMilliseconds = -1)
Parameters
cancellationToken
CancellationTokenCancellation token to cancel the operation.
timeoutInMilliseconds
intTimeout in milliseconds. Use Infinite(-1) for an infinite timeout.
Returns
- string
The scanned code.
Exceptions
- NotInitializedException
Thrown when the module is not initialized.
- ArgumentOutOfRangeException
Thrown when
timeoutInMilliseconds
is a negative number other than -1 milliseconds, which represents an infinite time-out. -or- The number of milliseconds in timeout is greater than MaxValue.- TimeoutException
Thrown when
timeoutInMilliseconds
has elapsed.- OperationCanceledException
Thrown when
cancellationToken
is canceled.
Events
CodeScanned
Occurs when a code is scanned.
public event EventHandler<string> CodeScanned