Class DataManSystem

java.lang.Object
com.cognex.cmbsdk.DataManSystem

public class DataManSystem extends Object
Represents a remote DataMan system.
  • Field Details

    • lockObject

      protected final Object lockObject
    • DEFAULT_DMCC_TIMEOUT

      public static final int DEFAULT_DMCC_TIMEOUT
      See Also:
    • WRITE_CHUNK_SIZE

      public static final int WRITE_CHUNK_SIZE
      See Also:
  • Method Details

    • createDataManSystemOverEthernet

      @Deprecated public static DataManSystem createDataManSystemOverEthernet(InetAddress address)
      Deprecated.
      Creates a DataManSystem object with an underlying Ethernet transport.
      Parameters:
      address - The IP address of the host to connect to.
      Returns:
      The newly created DataManSystem object.
    • createDataManSystemOverEthernet

      @Deprecated public static DataManSystem createDataManSystemOverEthernet(InetAddress address, android.os.Handler handler)
      Deprecated.
      Creates a DataManSystem object with an underlying Ethernet transport.
      Parameters:
      address - The IP address of the host to connect to.
      handler - The Handler object to be used to execute the listeners on its thread.
      Returns:
      The newly created DataManSystem object.
    • createDataManSystemOverEthernet

      @Deprecated public static DataManSystem createDataManSystemOverEthernet(InetAddress address, int port)
      Deprecated.
      Creates a DataManSystem object with an underlying Ethernet transport.
      Parameters:
      address - The IP address of the host to connect to.
      port - The port of the host to connect to.
      Returns:
      The newly created DataManSystem object.
    • createDataManSystemOverEthernet

      @Deprecated public static DataManSystem createDataManSystemOverEthernet(InetAddress address, int port, android.os.Handler handler)
      Deprecated.
      Creates a DataManSystem object with an underlying Ethernet transport.
      Parameters:
      address - The IP address of the host to connect to.
      port - The port of the host to connect to.
      handler - The Handler object to be used to execute the listeners on its thread.
      Returns:
      The newly created DataManSystem object.
    • createDataManSystemOverBluetooth

      @Deprecated public static DataManSystem createDataManSystemOverBluetooth(android.bluetooth.BluetoothDevice device)
      Deprecated.
      Creates a DataManSystem object with a Bluetooth Device.
      Parameters:
      device - The Bluetooth Device to connect to.
      Returns:
      The newly created DataManSystem object.
    • createDataManSystemForMXDevice

      @Deprecated public static DataManSystem createDataManSystemForMXDevice(android.content.Context context)
      Deprecated.
      Creates a DataManSystem object for a connected MX device.
      Parameters:
      context - The application's environment.
      Returns:
      The newly created DataManSystem object.
    • createDataManSystemForMXDevice

      @Deprecated public static DataManSystem createDataManSystemForMXDevice(android.content.Context context, android.os.Handler handler)
      Deprecated.
      Creates a DataManSystem object for a connected MX device.
      Parameters:
      context - The application's environment.
      handler - The Handler object to be used to execute the listeners on its thread.
      Returns:
      The newly created DataManSystem object.
    • createDataManSystemOverCamera

      @Deprecated public static DataManSystem createDataManSystemOverCamera(android.app.Activity activity, int cameraMode, int previewOptions)
      Deprecated.
      Creates a DataManSystem object for a Phone camera.
      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 DataManSystem object.
    • createDataManSystemOverCamera

      @Deprecated public static DataManSystem createDataManSystemOverCamera(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer)
      Deprecated.
      Creates a DataManSystem object for a Phone camera.
      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 DataManSystem object or null if input params are not valid.
    • createDataManSystemOverCamera

      @Deprecated public static DataManSystem createDataManSystemOverCamera(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer, String registrationKey)
      Deprecated.
      Creates a DataManSystem object for a Phone camera.
      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 DataManSystem object or null if input params are not valid.
    • createDataManSystemOverCamera

      @Deprecated public static DataManSystem createDataManSystemOverCamera(android.content.Context context, int cameraMode, int previewOptions, android.view.ViewGroup previewContainer, String registrationKey, String customData)
      Deprecated.
      Creates a DataManSystem object for a Phone camera.
      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 DataManSystem object or null if input params are not valid.
    • createDataManSystemOverConnector

      @Deprecated public static DataManSystem createDataManSystemOverConnector(android.content.Context context, SystemConnector connector, boolean handleConnectorDisconnect, android.os.Handler.Callback handlerCallback)
      Deprecated.
    • getVersion

      public static String getVersion()
      Gets the current version of the SDK.
      Returns:
      The current version of the SDK.
    • 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
    • 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). Camera driver must to be opened before
      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
    • setFlushBufferEnabled

      public void setFlushBufferEnabled(boolean enabled)
      Enables or disables buffer flushing on the device. If enabled, COM.BUFFER-START-SEND DMCC command is sent to the device after a successful connection.
      Parameters:
      enabled - enables or disables buffer flushing
    • isFlushBufferEnabled

      public boolean isFlushBufferEnabled()
      Returns if buffer flushing was enabled or disabled on connecting to the device.
      Returns:
      status of buffer flushing on the device
    • getExpectReadStringAsResponse

      public boolean getExpectReadStringAsResponse()
      Gets the value indicating whether the new syntax is expected for DMCC results arriving. This syntax is the default for newer device firmware versions.The new format contains the number of bytes in the first row, then the result bytes follow.
      Returns:
      The value indicating whether the new syntax is expected for DMCC results arriving.
      See Also:
    • setExpectReadStringAsResponse

      public void setExpectReadStringAsResponse(boolean value)
      Sets the value indicating whether the new syntax should be used when handling DMCC results.
      Parameters:
      value - The value indicating whether the new syntax should be used when handling DMCC results.
      See Also:
    • getTimeout

      public int getTimeout()
      Gets the timeout value (in milliseconds) used in operations that can time out. The default is 5000 milliseconds.
      Returns:
      The timeout value used is the operations that can time out.
      See Also:
    • setTimeout

      public void setTimeout(int timeout)
      Sets the timeout value (in milliseconds) used in operations that can time out. This is used when connecting to a reader, when sending a command (except for when the timeout can explicitly be set) and when requesting a live image.
      Parameters:
      timeout - The value to be used as timeout.
      See Also:
    • getExtraHeaderData

      public String getExtraHeaderData()
      Gets the extra header data sent with all commands.
      Returns:
      The extra header data sent with all commands.
      See Also:
    • setExtraHeaderData

      public void setExtraHeaderData(String extraHeaderData)
      Sets the extra header data sent with all commands.
      Parameters:
      extraHeaderData - The extra header data to be send with all commands.
      See Also:
    • getResultTypes

      public EnumSet<ResultType> getResultTypes()
      Gets the result types that should be handled by the SDK. All other result types will be ignored.
      Returns:
      The result types which are handled by the SDK.
      See Also:
    • setResultTypes

      public void setResultTypes(EnumSet<ResultType> resultTypes)
      Sets the result types that should be handled by the SDK. All other result types will be ignored.
      Parameters:
      resultTypes - The result types to be handled by the SDK.
      See Also:
    • getCharset

      public Charset getCharset()
      Gets the Charset object used when converting a series of bytes from the reader to a string.
      Returns:
      The Charset object used when converting a series of bytes from the reader to a string.
      See Also:
    • setCharset

      public void setCharset(Charset charset)
      Sets the Charset object used when converting a series of bytes from the reader to a string.
      Parameters:
      charset - The Charset object to be used when converting a series of bytes from the reader to a string.
      See Also:
    • isLiveImageEnabled

      public boolean isLiveImageEnabled()
      Indicates whether Live Image mode is enabled or not.
      Returns:
      true if Live Image mode is enabled, otherwise false.
      See Also:
    • isHeartbeatEnabled

      public boolean isHeartbeatEnabled()
      Indicates whether heartbeat is enabled or not.
      Returns:
      true if heartbeat is enabled, otherwise false.
      See Also:
    • setLogger

      public void setLogger(Logger logger)
      Sets the optional logger which can be used for debugging purposes.
      Parameters:
      logger - The logger object to be used for logging.
    • setOnConnectedListener

      public void setOnConnectedListener(DataManSystem.OnConnectedListener listener)
      Registers a callback to be invoked when a connection to a reader is successfully established.
      Parameters:
      listener - The callback that will be invoked.
      See Also:
    • setOnConnectionErrorListener

      public void setOnConnectionErrorListener(DataManSystem.OnConnectionErrorListener listener)
      Register a callback to be invoked when a connection error occurs during connecting to a reader.
      Parameters:
      listener - The callback that will be invoked.
      See Also:
    • setOnDisconnectedListener

      public void setOnDisconnectedListener(DataManSystem.OnDisconnectedListener listener)
      Register a callback to be invoked when disconnected from a reader.
      Parameters:
      listener - The callback that will be invoked.
      See Also:
    • setOnBinaryDataTransferProgressListener

      public void setOnBinaryDataTransferProgressListener(DataManSystem.OnBinaryDataTransferProgressListener listener)
      Register a callback to be invoked to report binary data transfer progress.
      Parameters:
      listener - The callback that will be invoked.
    • setOnOffProtocolByteReceivedListener

      public void setOnOffProtocolByteReceivedListener(DataManSystem.OnOffProtocolByteReceivedListener listener)
      Register a callback to be invoked when an off protocol byte is received.
      Parameters:
      listener - The callback that will be invoked.
    • setOnReadStringArrivedListener

      public void setOnReadStringArrivedListener(DataManSystem.OnReadStringArrivedListener listener)
      Register a callback to be invoked when a simple read string is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnXmlResultArrivedListener

      public void setOnXmlResultArrivedListener(DataManSystem.OnXmlResultArrivedListener listener)
      Register a callback to be invoked when a read result in XML format is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnXmlStatisticsArrivedListener

      public void setOnXmlStatisticsArrivedListener(DataManSystem.OnXmlStatisticsArrivedListener listener)
      Register a callback to be invoked when a read statistics in XML format is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnImageArrivedListener

      public void setOnImageArrivedListener(DataManSystem.OnImageArrivedListener listener)
      Register a callback to be invoked when a read image is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnImageDataArrivedListener

      public void setOnImageDataArrivedListener(DataManSystem.OnImageDataArrivedListener listener)
      Register a callback to be invoked when a read image as byte array is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnImageGraphicsArrivedListener

      public void setOnImageGraphicsArrivedListener(DataManSystem.OnImageGraphicsArrivedListener listener)
      Register a callback to be invoked when an image graphics in XML format is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnTrainingResultArrivedListener

      public void setOnTrainingResultArrivedListener(DataManSystem.OnTrainingResultArrivedListener listener)
      Register a callback to be invoked when a training result in XML format is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnCodeQualityDataArrivedListener

      public void setOnCodeQualityDataArrivedListener(DataManSystem.OnCodeQualityDataArrivedListener listener)
      Register a callback to be invoked when a code quality data in XML format is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnStatusEventArrivedListener

      public void setOnStatusEventArrivedListener(DataManSystem.OnStatusEventArrivedListener listener)
      Register a callback to be invoked when a status event is arrived.
      Parameters:
      listener - The callback that will be invoked.
    • setOnSystemWentOnlineListener

      public void setOnSystemWentOnlineListener(DataManSystem.OnSystemWentOnlineListener listener)
      Register a callback to be invoked when the reader went online.
      Parameters:
      listener - The callback that will be invoked.
    • setOnSystemWentOfflineListener

      public void setOnSystemWentOfflineListener(DataManSystem.OnSystemWentOfflineListener listener)
      Register a callback to be invoked when the reader went offline.
      Parameters:
      listener - The callback that will be invoked.
    • setOnHeartbeatResponseMissedListener

      public void setOnHeartbeatResponseMissedListener(DataManSystem.OnHeartbeatResponseMissedListener listener)
      Register a callback to be invoked when the response of a heartbeat command is missed.
      Parameters:
      listener - The callback that will be invoked.
      See Also:
    • getState

      @Deprecated public ConnectionState getState()
      Deprecated.
      use getConnectionState() instead
      Gets the current connection state of this DataManSystem instance.
      Returns:
      The current connection state.
      See Also:
    • connect

      public boolean connect()
      Initiates a connection to the device with default user name, password and timeout. If connecting succeeds, the user is notified via the DataManSystem.OnConnectedListener. If an error occurs during connecting, the user is notified via the DataManSystem.OnConnectionErrorListener.
      Returns:
      true if the connection could be initiated (the state of the connection was ConnectionState.Disconnected, otherwise false.
      See Also:
    • connect

      public boolean connect(String userName, String password)
      Initiates a connection to the device with the given user name and password and with the default timeout. If connecting succeeds, the user is notified via the DataManSystem.OnConnectedListener. If an error occurs during connecting, the user is notified via the DataManSystem.OnConnectionErrorListener.
      Parameters:
      userName - The user name to authenticate with the remote system.
      password - The password to authenticate with the remote system.
      Returns:
      true if the connection could be initiated (the state of the connection was ConnectionState.Disconnected, otherwise false.
      See Also:
    • disconnect

      public void disconnect()
      Initiates a disconnection from the device. If the DataManSystem.OnDisconnectedListener is set, it will be invoked after the device is disconnected.
      See Also:
    • isConnected

      public boolean isConnected()
      Indicates the status of the connection.
      Returns:
      true if the system is connected, otherwise false.
    • getDeviceClass

      public DataManDeviceClass getDeviceClass()
      Gets the device type of the DataManSystem instance.
      Returns:
      the current device type
    • getConnectionState

      public ConnectionState getConnectionState()
      Returns the connection state of the system.
      Returns:
      the current connection state
    • sendCommand

      public void sendCommand(String command)
      Sends a command to the connected device with the default timeout. The user will not be notified about the result.
      Parameters:
      command - The command to be send.
      See Also:
    • sendCommand

      public void sendCommand(String command, DataManSystem.OnResponseReceivedListener listener)
      Sends a command to the connected device with the default timeout. The user will be notified about the result in the DataManSystem.OnResponseReceivedListener.
      Parameters:
      command - The command to be send.
      listener - The callback to be invoked when the answer to the command arrives.
      See Also:
    • sendCommand

      public void sendCommand(String command, byte[] data, int timeout, boolean expectBinaryResponse, DataManSystem.OnResponseReceivedListener listener)
      Sends a command and the specified binary data to the connected device with the given timeout value. If a binary response is expected, it also can be specified. The user will be notified about the result in the DataManSystem.OnResponseReceivedListener.
      Parameters:
      command - The command to be send.
      data - Binary data to be send to the remote system.
      timeout - Timeout for the command.
      expectBinaryResponse - Value to indicate if we expect binary response.
      listener - The callback to be invoked when the answer to the command arrives.
      See Also:
    • sendCommandSync

      public DmccResponse sendCommandSync(String command, byte[] data, int timeout, boolean expectBinaryResponse) throws InterruptedException, TimeoutException, DataManException, IOException
      Sends a command and the specified binary data to the connected device with the given timeout value. If a binary response is expected, it also can be specified. This method will block until the response from the Reader is received or the specified timeout has reached.
      Parameters:
      command - The command to be send.
      data - Binary data to be send to the remote system.
      timeout - Timeout for the command.
      expectBinaryResponse - Value to indicate if we expect binary response.
      Returns:
      DmccResponse Reader response for the sent command or null, if the command has failed
      Throws:
      InterruptedException - if the command sending is interrupted
      TimeoutException - if the command has timed out
      DataManException - if there was a command related issue
      IOException - if there was a communication issue
    • sendBatchCommands

      @Deprecated public void sendBatchCommands(List<String> commands, DataManSystem.OnBatchCommandsCompletedListener listener)
      Deprecated.
      use sendCommandSync instead
      Sends the commands provided in a List to the connected device serially with the default timeout. The user will be notified about the result of each command in the DataManSystem.OnBatchCommandsCompletedListener.
      Parameters:
      commands - The List of commands to be sent to the reader.
      listener - The callback to be invoked when the response to a specific command arrives.
      See Also:
    • enableLiveImage

      public void enableLiveImage(ImageFormat imageFormat, ImageSize imageSize, ImageQuality imageQuality, DataManSystem.OnLiveImageArrivedListener listener)
      Enables live image mode and start requesting live images.
      Parameters:
      imageFormat - The ImageFormat object to specify the image type.
      imageSize - The ImageSize object to specify the image size.
      imageQuality - The ImageQuality object to specify the image quality.
      listener - The callback to be invoked when the live image arrives.
      See Also:
    • disableLiveImage

      public void disableLiveImage()
      Disables live image mode and stops requesting live images.
      See Also:
    • enableHeartbeat

      public void enableHeartbeat(int interval)
      Enables heartbeat and start sending heartbeat commands in every interval milliseconds. If a response to a heartbeat command is not received, the DataManSystem.OnHeartbeatResponseMissedListener is invoked if set.
      Parameters:
      interval - The interval (in milliseconds) between heartbeat commands.
      See Also:
    • disableHeartbeat

      public void disableHeartbeat()
      Disables heartbeat and stops sending heartbeat commands.
      See Also:
    • onCommandInfoHandled

      public void onCommandInfoHandled(com.cognex.cmbsdk.CommandInfo commandInfo)