Package com.cognex.cmbsdk.readerdevice
Class ReaderDevice
java.lang.Object
com.cognex.cmbsdk.readerdevice.ReaderDevice
- All Implemented Interfaces:
DataManSystem.OnConnectedListener,DataManSystem.OnConnectionErrorListener,DataManSystem.OnDisconnectedListener,ResultCollector.ResultCollectorListener
public abstract class ReaderDevice
extends Object
implements DataManSystem.OnConnectedListener, DataManSystem.OnDisconnectedListener, DataManSystem.OnConnectionErrorListener, ResultCollector.ResultCollectorListener
Represents a Phone Camera or MX barcode reader
You should instantiate this class using
getPhoneCameraDevice() or getMXDevice() factory methods.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum values forReaderDeviceavailabilityprotected static interfacestatic interfaceInterface definition for monitoring the state of connection processstatic interfaceInterface definition for device battery level callbackstatic interfaceInterface definition for lights state information callbackstatic interfaceInterface definition for device reset callbackstatic interfaceInterface definition for symbology enabled callbackstatic interfaceInterface definition forReaderDevicestatus and result listenerstatic enumEnum values forReaderDeviceparsers -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected DataManSystemprotected ReaderDevice.ReaderDeviceListener -
Method Summary
Modifier and TypeMethodDescriptionvoidbeep()Plays a beep on the readervoidconnect(ReaderDevice.OnConnectionCompletedListener connectionCompletedListener) Connects to the barcode reader.protected abstract voidvoidDisconnects from a connected barcode reader.voidenableImage(boolean enable) Enable or disable image results from readervoidenableImageGraphics(boolean enable) Enable or disable SVG image graphics results from readerabstract ReaderDevice.AvailabilityReturns the availability of the readerstatic ReaderDevicegetBluetoothReaderDevice(android.content.Context context, android.bluetooth.BluetoothDevice device) Creates aReaderDeviceobject for a connected Bluetooth device.float[]Get camera exposure compensation range (0: lower value, 1: upper value, 2: step)Returns the current connection state of the readerReturns the DataManSystem instance for this ReaderDevicevoidRetrieves the current battery percentage level of the reader.Tells the connection type of theReaderDeviceobjectprotected ReaderDevice.LightCommandstatic ReaderDevicegetMXDevice(android.content.Context context) Creates aReaderDeviceobject for a connected MX barcode reader.Get reader device selected parserstatic ReaderDevicegetPhoneCameraDevice(android.app.Activity activity, int cameraMode, int previewOptions) Creates aReaderDeviceobject for a Phone Camera barcode reader.static ReaderDevicegetPhoneCameraDevice(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer) Creates aReaderDeviceobject for a Phone Camera barcode reader.static ReaderDevicegetPhoneCameraDevice(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer, String registrationKey) Creates aReaderDeviceobject for a Phone Camera barcode reader.static ReaderDevicegetPhoneCameraDevice(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer, String registrationKey, String customData) Creates aReaderDeviceobject for a Phone Camera barcode reader.Get the encoding that is used to decode Read String from base64 resultprotected voidinitDMS(DataManSystem dms) protected voidinitDMS(DataManSystem dms, EnumSet<ResultType> resultTypes) booleanRetrieves whether the camera driver errors will be shown as toast messages or in logcatvoidisLightsOn(ReaderDevice.OnLightsListener listener) Retrieves whether all lights of the barcode reader are turned on or off.voidisSymbologyEnabled(Symbology symbology, ReaderDevice.OnSymbologyListener listener) Retrieves whether the specified symbology is enabled or disabledvoidLoad config from app data if exist Method is only supported for Phone CameravoidonComplexResultArrived(ComplexResult result) voidonConnected(DataManSystem dataManSystem) Called after successfully connecting to a reader.voidonConnectionError(DataManSystem dataManSystem, Exception exception) Called when an error occurs while connecting to a reader.voidonDisconnected(DataManSystem dataManSystem) Called after disconnected from a reader.voidonSimpleResultDropped(SimpleResult result) voidResets the reader configurations to factory defaultvoidsetCameraExposureCompensation(float exposureCompensation) Sets the camera exposure compensation valuevoidsetCameraPreviewContainer(android.view.ViewGroup previewContainer) Sets the container where the camera preview will be placed.voidsetLightsOn(boolean on, ReaderDevice.OnLightsListener listener) Turns on or off all internal lights of the readervoidsetParser(ReaderDevice.ResultParser parser) Set reader device resultParservoidRegisters a listener for read results and connection state changesvoidsetReadStringEncoding(ReadStringEncoding readStringEncoding) Set the encoding that is used to decode Read String from base64 resultvoidsetSymbologyEnabled(Symbology symbology, boolean enable, ReaderDevice.OnSymbologyListener listener) Enable or disable the provided symbology on the readervoidshowCameraDriverErrorAsToast(boolean showAsToast) Configure reader device to show the camera driver messages as toast or in logcatabstract booleanStarts device availability monitoringvoidStarts triggeringabstract voidStops device availability monitoringvoidStops triggering
-
Field Details
-
dms
-
readerDeviceListener
-
deviceType
-
-
Method Details
-
getMXDevice
Creates aReaderDeviceobject for a connected MX barcode reader.- Parameters:
context- The application's environment.- Returns:
- The newly created
ReaderDeviceobject.
-
getPhoneCameraDevice
public static ReaderDevice getPhoneCameraDevice(android.app.Activity activity, int cameraMode, int previewOptions) Creates aReaderDeviceobject for a Phone Camera barcode reader.- Parameters:
activity- The parent activitycameraMode- TheCameraModewhen using the Mobile device camera.previewOptions- ThePreviewOptionwhen using the Mobile device camera.- Returns:
- The newly created
ReaderDeviceobject.
-
getPhoneCameraDevice
public static ReaderDevice getPhoneCameraDevice(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer) Creates aReaderDeviceobject for a Phone Camera barcode reader.- Parameters:
context- The parent contextcameraMode- TheCameraModewhen using the Mobile device camera.previewOptions- ThePreviewOptionwhen using the Mobile device camera.previewContainer- The container where the camera preview will be placed.- Returns:
- The newly created
ReaderDeviceobject or null if input params are not valid
-
getPhoneCameraDevice
public static ReaderDevice getPhoneCameraDevice(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer, String registrationKey) Creates aReaderDeviceobject for a Phone Camera barcode reader.- Parameters:
context- The parent contextcameraMode- TheCameraModewhen using the Mobile device camera.previewOptions- ThePreviewOptionwhen using the Mobile device camera.previewContainer- The container where the camera preview will be placed.registrationKey- The registration key for the Phone Camera license.- Returns:
- The newly created
ReaderDeviceobject or null if input params are not valid
-
getPhoneCameraDevice
public static ReaderDevice getPhoneCameraDevice(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer, String registrationKey, String customData) Creates aReaderDeviceobject for a Phone Camera barcode reader.- Parameters:
context- The parent contextcameraMode- TheCameraModewhen using the Mobile device camera.previewOptions- ThePreviewOptionwhen using the Mobile device camera.previewContainer- The container where the camera preview will be placed.registrationKey- The registration key for the Phone Camera license.customData- The custom data used when licensing for custom tracking.- Returns:
- The newly created
ReaderDeviceobject or null if input params are not valid
-
getBluetoothReaderDevice
public static ReaderDevice getBluetoothReaderDevice(android.content.Context context, android.bluetooth.BluetoothDevice device) Creates aReaderDeviceobject for a connected Bluetooth device.- Parameters:
device- The Bluetooth device to connect to.context- The application's environment.- Returns:
- The newly created
ReaderDeviceobject.
-
setCameraPreviewContainer
public void setCameraPreviewContainer(android.view.ViewGroup previewContainer) throws UnsupportedOperationException Sets the container where the camera preview will be placed.- Parameters:
previewContainer- The container where the camera preview will be placed.- Throws:
UnsupportedOperationException- when used on connector other than the Phone Camera Method is only supported for Phone Camera
-
loadCameraConfig
Load config from app data if exist Method is only supported for Phone Camera- Throws:
UnsupportedOperationException
-
setReaderDeviceListener
Registers a listener for read results and connection state changes- Parameters:
listener- TheReaderDevice.ReaderDeviceListenerto be registered- See Also:
-
getAvailability
Returns the availability of the reader- Returns:
ReaderDevice.Availabilitystate of the reader- See Also:
-
startAvailabilityListening
public abstract boolean startAvailabilityListening()Starts device availability monitoring- Returns:
- true, if device availability can be monitored
-
stopAvailabilityListening
public abstract void stopAvailabilityListening()Stops device availability monitoring -
enableImage
public void enableImage(boolean enable) Enable or disable image results from reader- Parameters:
enable- true to enable image results
-
enableImageGraphics
public void enableImageGraphics(boolean enable) Enable or disable SVG image graphics results from reader- Parameters:
enable- true to enable image graphics results
-
setParser
Set reader device resultParser- Parameters:
parser- fromReaderDevice.ResultParservalues
-
getParser
Get reader device selected parser- Returns:
- the current
ReaderDevice.ResultParserof the reader
-
setCameraExposureCompensation
public void setCameraExposureCompensation(float exposureCompensation) throws UnsupportedOperationException Sets the camera exposure compensation value- Parameters:
exposureCompensation- Float value that will be set as exposure compensation- Throws:
UnsupportedOperationException- when used on connector other than the Phone Camera
-
getCameraExposureCompensationRange
Get camera exposure compensation range (0: lower value, 1: upper value, 2: step)- Returns:
- lower value, upper value and step value in float array or null if range is not available The camera needs to be started within cmbSDK at least once to get the camera exposure compensation range
- Throws:
UnsupportedOperationException- when used on connector other than the Phone Camera
-
setReadStringEncoding
Set the encoding that is used to decode Read String from base64 result- Parameters:
readStringEncoding- fromReadStringEncodingvalues
-
getReadStringEncoding
Get the encoding that is used to decode Read String from base64 result- Returns:
- the current
ReadStringEncoding
-
getDeviceClass
Tells the connection type of theReaderDeviceobject- Returns:
- the current
DataManDeviceClass
-
getConnectionState
Returns the current connection state of the reader- Returns:
- the current
ConnectionStateof the reader - See Also:
-
connect
Connects to the barcode reader.- Parameters:
connectionCompletedListener- TheReaderDevice.OnConnectionCompletedListenerlistener to invoke as the connection process is completed.- See Also:
-
disconnect
public void disconnect()Disconnects from a connected barcode reader. -
startScanning
public void startScanning()Starts triggering -
stopScanning
public void stopScanning()Stops triggering -
beep
public void beep()Plays a beep on the reader -
getDeviceBatteryLevel
Retrieves the current battery percentage level of the reader.- Parameters:
listener- TheReaderDevice.OnDeviceBatteryLevelListenerto be called as the information is available- See Also:
-
setSymbologyEnabled
public void setSymbologyEnabled(Symbology symbology, boolean enable, ReaderDevice.OnSymbologyListener listener) Enable or disable the provided symbology on the reader- Parameters:
symbology- TheSymbologyto enable or disableenable- true to enable, false to disablelistener- The callback interface to call as the setting completes- See Also:
-
isSymbologyEnabled
Retrieves whether the specified symbology is enabled or disabled- Parameters:
symbology- TheSymbologyto checklistener- The callback to be invoked as the information is available- See Also:
-
setLightsOn
Turns on or off all internal lights of the reader- Parameters:
on- true, to turn on the lights, false to turn off the lightslistener- The callback to be invoked as the method completes- See Also:
-
isLightsOn
Retrieves whether all lights of the barcode reader are turned on or off.- Parameters:
listener- The callback to be invoked as the result is available- See Also:
-
resetConfig
Resets the reader configurations to factory default- Parameters:
listener- The callback interface to be invoked as the operation completes- See Also:
-
isCameraDriverErrorShownAsToast
public boolean isCameraDriverErrorShownAsToast()Retrieves whether the camera driver errors will be shown as toast messages or in logcat -
showCameraDriverErrorAsToast
public void showCameraDriverErrorAsToast(boolean showAsToast) Configure reader device to show the camera driver messages as toast or in logcat- Parameters:
showAsToast- true to see messages as toast or false to receive them in logcat
-
getDataManSystem
Returns the DataManSystem instance for this ReaderDevice- Returns:
DataManSysteminstance
-
connectImpl
protected abstract void connectImpl() -
initDMS
-
initDMS
-
getLightCommand
-
onConnected
Description copied from interface:DataManSystem.OnConnectedListenerCalled after successfully connecting to a reader.- Specified by:
onConnectedin interfaceDataManSystem.OnConnectedListener- Parameters:
dataManSystem- TheDataManSystemobject that invoked the callback.
-
onDisconnected
Description copied from interface:DataManSystem.OnDisconnectedListenerCalled after disconnected from a reader.- Specified by:
onDisconnectedin interfaceDataManSystem.OnDisconnectedListener- Parameters:
dataManSystem- TheDataManSystemobject that invoked the callback.
-
onConnectionError
Description copied from interface:DataManSystem.OnConnectionErrorListenerCalled when an error occurs while connecting to a reader.- Specified by:
onConnectionErrorin interfaceDataManSystem.OnConnectionErrorListener- Parameters:
dataManSystem- TheDataManSystemobject that invoked the callback.exception- The exception object representing the error
-
onComplexResultArrived
- Specified by:
onComplexResultArrivedin interfaceResultCollector.ResultCollectorListener
-
onSimpleResultDropped
- Specified by:
onSimpleResultDroppedin interfaceResultCollector.ResultCollectorListener
-