Class ReaderDevice

java.lang.Object
com.cognex.cmbsdk.readerdevice.ReaderDevice
All Implemented Interfaces:
DataManSystem.OnConnectedListener, DataManSystem.OnConnectionErrorListener, DataManSystem.OnDisconnectedListener, ResultCollector.ResultCollectorListener

Represents a Phone Camera or MX barcode reader You should instantiate this class using getPhoneCameraDevice() or getMXDevice() factory methods.
  • Field Details

  • Method Details

    • getMXDevice

      public static ReaderDevice getMXDevice(android.content.Context context)
      Creates a ReaderDevice object for a connected MX barcode reader.
      Parameters:
      context - The application's environment.
      Returns:
      The newly created ReaderDevice object.
    • getPhoneCameraDevice

      public static ReaderDevice getPhoneCameraDevice(android.app.Activity activity, int cameraMode, int previewOptions)
      Creates a ReaderDevice object for a Phone Camera barcode reader.
      Parameters:
      activity - The parent activity
      cameraMode - The CameraMode when using the Mobile device camera.
      previewOptions - The PreviewOption when using the Mobile device camera.
      Returns:
      The newly created ReaderDevice object.
    • getPhoneCameraDevice

      public static ReaderDevice getPhoneCameraDevice(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer)
      Creates a ReaderDevice object for a Phone Camera barcode reader.
      Parameters:
      context - The parent context
      cameraMode - The CameraMode when using the Mobile device camera.
      previewOptions - The PreviewOption when using the Mobile device camera.
      previewContainer - The container where the camera preview will be placed.
      Returns:
      The newly created ReaderDevice object 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 a ReaderDevice object for a Phone Camera barcode reader.
      Parameters:
      context - The parent context
      cameraMode - The CameraMode when using the Mobile device camera.
      previewOptions - The PreviewOption when 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 ReaderDevice object 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 a ReaderDevice object for a Phone Camera barcode reader.
      Parameters:
      context - The parent context
      cameraMode - The CameraMode when using the Mobile device camera.
      previewOptions - The PreviewOption when 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 ReaderDevice object or null if input params are not valid
    • getBluetoothReaderDevice

      public static ReaderDevice getBluetoothReaderDevice(android.content.Context context, android.bluetooth.BluetoothDevice device)
      Creates a ReaderDevice object for a connected Bluetooth device.
      Parameters:
      device - The Bluetooth device to connect to.
      context - The application's environment.
      Returns:
      The newly created ReaderDevice object.
    • 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

      public void loadCameraConfig() throws UnsupportedOperationException
      Load config from app data if exist Method is only supported for Phone Camera
      Throws:
      UnsupportedOperationException
    • setReaderDeviceListener

      public void setReaderDeviceListener(ReaderDevice.ReaderDeviceListener listener)
      Registers a listener for read results and connection state changes
      Parameters:
      listener - The ReaderDevice.ReaderDeviceListener to be registered
      See Also:
    • getAvailability

      public abstract ReaderDevice.Availability getAvailability()
      Returns the availability of the reader
      Returns:
      ReaderDevice.Availability state 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

      public void setParser(ReaderDevice.ResultParser parser)
      Set reader device resultParser
      Parameters:
      parser - from ReaderDevice.ResultParser values
    • getParser

      public ReaderDevice.ResultParser getParser()
      Get reader device selected parser
      Returns:
      the current ReaderDevice.ResultParser of 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

      public float[] getCameraExposureCompensationRange() throws UnsupportedOperationException
      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

      public void setReadStringEncoding(ReadStringEncoding readStringEncoding)
      Set the encoding that is used to decode Read String from base64 result
      Parameters:
      readStringEncoding - from ReadStringEncoding values
    • getReadStringEncoding

      public ReadStringEncoding getReadStringEncoding()
      Get the encoding that is used to decode Read String from base64 result
      Returns:
      the current ReadStringEncoding
    • getDeviceClass

      public DataManDeviceClass getDeviceClass()
      Tells the connection type of the ReaderDevice object
      Returns:
      the current DataManDeviceClass
    • getConnectionState

      public ConnectionState getConnectionState()
      Returns the current connection state of the reader
      Returns:
      the current ConnectionState of the reader
      See Also:
    • connect

      public void connect(ReaderDevice.OnConnectionCompletedListener connectionCompletedListener)
      Connects to the barcode reader.
      Parameters:
      connectionCompletedListener - The ReaderDevice.OnConnectionCompletedListener listener 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

      public void getDeviceBatteryLevel(ReaderDevice.OnDeviceBatteryLevelListener listener)
      Retrieves the current battery percentage level of the reader.
      Parameters:
      listener - The ReaderDevice.OnDeviceBatteryLevelListener to 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 - The Symbology to enable or disable
      enable - true to enable, false to disable
      listener - The callback interface to call as the setting completes
      See Also:
    • isSymbologyEnabled

      public void isSymbologyEnabled(Symbology symbology, ReaderDevice.OnSymbologyListener listener)
      Retrieves whether the specified symbology is enabled or disabled
      Parameters:
      symbology - The Symbology to check
      listener - The callback to be invoked as the information is available
      See Also:
    • setLightsOn

      public void setLightsOn(boolean on, ReaderDevice.OnLightsListener listener)
      Turns on or off all internal lights of the reader
      Parameters:
      on - true, to turn on the lights, false to turn off the lights
      listener - The callback to be invoked as the method completes
      See Also:
    • isLightsOn

      public void isLightsOn(ReaderDevice.OnLightsListener listener)
      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

      public void resetConfig(ReaderDevice.OnResetConfigListener listener)
      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

      public DataManSystem getDataManSystem()
      Returns the DataManSystem instance for this ReaderDevice
      Returns:
      DataManSystem instance
    • connectImpl

      protected abstract void connectImpl()
    • initDMS

      protected void initDMS(DataManSystem dms)
    • initDMS

      protected void initDMS(DataManSystem dms, EnumSet<ResultType> resultTypes)
    • getLightCommand

      protected ReaderDevice.LightCommand getLightCommand()
    • onConnected

      public void onConnected(DataManSystem dataManSystem)
      Description copied from interface: DataManSystem.OnConnectedListener
      Called after successfully connecting to a reader.
      Specified by:
      onConnected in interface DataManSystem.OnConnectedListener
      Parameters:
      dataManSystem - The DataManSystem object that invoked the callback.
    • onDisconnected

      public void onDisconnected(DataManSystem dataManSystem)
      Description copied from interface: DataManSystem.OnDisconnectedListener
      Called after disconnected from a reader.
      Specified by:
      onDisconnected in interface DataManSystem.OnDisconnectedListener
      Parameters:
      dataManSystem - The DataManSystem object that invoked the callback.
    • onConnectionError

      public void onConnectionError(DataManSystem dataManSystem, Exception exception)
      Description copied from interface: DataManSystem.OnConnectionErrorListener
      Called when an error occurs while connecting to a reader.
      Specified by:
      onConnectionError in interface DataManSystem.OnConnectionErrorListener
      Parameters:
      dataManSystem - The DataManSystem object that invoked the callback.
      exception - The exception object representing the error
    • onComplexResultArrived

      public void onComplexResultArrived(ComplexResult result)
      Specified by:
      onComplexResultArrived in interface ResultCollector.ResultCollectorListener
    • onSimpleResultDropped

      public void onSimpleResultDropped(SimpleResult result)
      Specified by:
      onSimpleResultDropped in interface ResultCollector.ResultCollectorListener