Cognex Mobile Barcode SDK (cmbSDK) is a tool for developing mobile barcode scanning applications. CmbSDK is based on Cognex's DataMan technology and the Manatee Works Barcode Scanning SDK and it allows you to create barcode scanning applications for mobile devices. Mobile devices used for barcode scanning range from smartphones to the MX Series industrial barcode readers. CmbSDK abstracts the device through a ReaderDevice connection layer. Once the application establishes its connection with the reader, a single, unified API is used as interface to configure the device, eliminating the need to write too much conditional code.
CmbSDK provides two basic ReaderDevice connection layers:
The cmbSDK supports Cognex’s MX Series Mobile Terminals and some of their features using cmbSDK are the following:
Normally you connect your mobile device (phone or tablet) to your PC via the USB or lightning port to start debugging. If an MX Mobile Terminal is attached to your mobile device via the USB or lightning port while your application is running, you need to debug your application via Wi-Fi.
To debug using Android Studio, connect your Android device via USB to your PC and make sure you can run and debug your application using the USB cable.
To Connect your Android device to Wi-Fi, make sure that Android Tools are installed beside your IDE.
The differences in the capabilities of smartphones as barcode scanning devices result in a user experience different from purpose-built scanners, impacting the design of the mobile barcode scanning application. By following a few simple guidelines, you can develop applications with the cmbSDK that work the same way when using an MX Mobile Terminal or the built-in camera of a mobile device.
CmbSDK employs a default set of options for barcode reading with the built-in camera of the mobile device. However, cmbSDK does not implement saved configurations for the camera reader. This means that every time an application starts that uses the camera reader, it starts with the default settings of the camera reader. For a list of the default settings, see the Appendix.
Without a hardware trigger, mobile devices must use alternative methods to initiate barcode scanning. The cmbSDK supports three methods to trigger barcode scanning:
The built-in camera provides a live-stream preview on the display of the mobile device for barcode aiming. Reposition the mobile device until the barcode appears in the field of view of the built-in camera and the application decodes it. CmbSDK provides a built-in preview control that can be displayed in partial or full screen, and in either portrait or landscape orientation.
The cmbSDK also supports passive aimers: devices attached to the mobile device or its case that use the LED flash of the device as a light source to project an aiming or targeting pattern. The mobile device can project an aimer pattern similar to a purpose-built scanner so live-preview is not needed. However, by using the LED flash as an aimer, general scanning illumination is not available.
The cmbSDK supports portrait orientation, landscape orientation and auto-rotation for both the presentation of the barcode preview and the scan direction. Mobile devices can scan most barcodes regardless of the orientation of the application and/or the mobile device.
Portrait or Landscape | Portrait only | Landscape only |
---|---|---|
Most barcodes can be scanned in either portrait or landscape orientation. | Most well defined and moderately sized barcodes can be scanned in a portrait orientation, which is the most natural way to hold the mobile device. Example: QR, Data Matrix, Maxicode. |
Long, dense, or poorly formed barcodes are easier to scan in a landscape orientation, which is of higher resolution. Example: PDF417. |
Mobile devices are an ideal platform for barcode decoding. The cmbSDK is optimized for mobile environment, but image analysis and barcode decoding is still a CPU intensive activity. Since these processes share the mobile device's CPU with the mobile operating system (OS), services, and other applications, these processes optimize your barcode scanning application and limit it to only using the features of the cmbSDK that they need.
To optimize your application:
No barcode symbologies are enabled by default, when the cmbSDK is initialized for use with the mobile device's built-in camera.
Installing the Android cmbSDK
Browse the cmbSDK .AAR file in the File name field, and click Finish.
Install the MX Connect application from the Play Store to communicate with MX mobile terminals.
Installing the iOS cmbSDK:
To use cmbSDK for barcode scanning with a mobile device without an MX mobile terminal, you need to install a license key. If the license key is missing, asterisks will appear instead of scanned results.
Contact your Cognex Sales Representative for information on how to obtain a license key, including 30-day trial licenses.
Android:
<meta-data android:name="MX_MOBILE_LICENSE" android:value="YOUR_MX_MOBILE_LICENSE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ScannerActivity" android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="MX_MOBILE_LICENSE"
android:value="g/9ytJzcja+sxt4DTEDxR4hp6sZh9bmL97vUx+EE9uY=" />
</application>
You can also add the license key by copying the text below when you create new instance from ReaderDevice.
case PhoneCamera:
readerDevice = ReaderDevice.getPhoneCameraDevice(this, param_cameraMode,
PreviewOption.DEFAULTS, null, "SDK_KEY");
iOS:
After obtaining your license key, add it as a String in your application's Info.plist file under the key MX_MOBILE_LICENSE.
Install cmbSDK to your project.
Use DataManSystem.createDataManSystemForMXDevice() factory method to create a DatamanSystem object.
CmbSDK provides a high-level, abstract interface for supported scanning devices: the MX mobile terminals and the camera of the mobile phone.
The primary interface between your application and the barcode scanning device is the ReaderDevice class. The ReaderDevice class represents an abstraction layer to the device, handling all communication and necessary hardware management, such as scanning with a smartphone.
Perform the following steps to use cmbSDK:
Create an instance from the ReaderDevice class with the type of scanning device you want to use (MX reader or camera reader).
Connect to the ReaderDevice instance you created.
Configure the ReaderDevice instance, if necessary.
Start scanning.
Perform the following steps to set up and start using cmbSDK:
import com.cognex.dataman.sdk.*
import com.cognex.mobile.barcode.sdk.*
Build your UI according to your needs, but considering the following aspects:
Our sample app (that you can find in the cmbSDK bundle) is using full screen preview. To change the sample app to use partial view, add the following RelativeLayout at the end of ConstraintLayout in activity_scanner.xml file. Use this layout ad a ViewGroup parameter in reader device constructor (getPhoneCameraDevice) when reader device is initialized.
<RelativeLayout
android:id="@+id/rlPreviewContainer"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="parent" />
public class ScannerActivity extends AppCompatActivity implements
OnConnectionCompletedListener, ReaderDeviceListener,
ActivityCompat.OnRequestPermissionsResultCallback {
....
// The connect method has completed, here you can see whether there was an error with establishing the connection or not
@Override
public void onConnectionCompleted(ReaderDevice readerDevice, Throwable error) {
// If we have valid connection error param will be null,
// otherwise here is error that inform us about issue that we have while connecting to reader device
if (error != null) {
// ask for Camera Permission if necessary
if (error instanceof CameraPermissionException)
ActivityCompat.requestPermissions(((ScannerActivity) this), new String[]{Manifest.permission.CAMERA}, REQUEST_PERMISSION_CODE);
updateUIByConnectionState();
}
}
// This is called when a connection with the self.readerDevice has been changed.
// The readerDevice is usable only in the "ConnectionState.Connected" state
@Override
public void onConnectionStateChanged(ReaderDevice reader) {
clearResult();
if (reader.getConnectionState() == ConnectionState.Connected) {
// We just connected, so now configure the device how we want it
configureReaderDevice();
}
isScanning = false;
updateUIByConnectionState();
}
// This is called after scanning has completed, either by detecting a barcode, canceling the scan by using the on-screen button or a hardware trigger button, or if the scanning timed-out
@Override
public void onReadResultReceived(ReaderDevice readerDevice, ReadResults results) {
clearResult();
if (results.getSubResults() != null && results.getSubResults().size() > 0) {
for (ReadResult subResult : results.getSubResults()) {
createResultItem(subResult);
}
} else if (results.getCount() > 0) {
createResultItem(results.getResultAt(0));
}
isScanning = false;
btnScan.setText("START SCANNING");
resultListAdapter.notifyDataSetChanged();
}
// This is called when a MX-1xxx device has became available (USB cable was plugged, or MX device was turned on),
// or when a MX-1xxx that was previously available has become unavailable (USB cable was unplugged, turned off due to inactivity or battery drained)
@Override
public void onAvailabilityChanged(ReaderDevice reader) {
if (reader.getAvailability() == Availability.AVAILABLE) {
connectToReaderDevice();
} else if (reader.getAvailability() == Availability.UNAVAILABLE) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert
.setTitle("Device became unavailable")
.setPositiveButton("OK", null)
.create()
.show();
}
}
Initialize a Reader Device object for MX readers using the following factory method:
case MX:
readerDevice = ReaderDevice.getMXDevice(this);
//Listen when a MX device has became available/unavailable
if (!availabilityListenerStarted) {
readerDevice.startAvailabilityListening();
availabilityListenerStarted = true;
}
The availability of the MX mobile terminal can change when the device turns on or off, or if the USB cable gets connected or disconnected. You can handle those changes using the following ReaderDeviceListener interface method:
public void onAvailabilityChanged(ReaderDevice reader);
You are recommended to use an MX mobile terminal to scan barcodes. However, cmbSDK also supports using the built-in camera of a mobile device. This includes the support of optional external aimers or illumination, and the customization of the live-stream preview's appearance.
To scan barcodes using the built-in camera of a mobile device, initialize the ReaderDevice object using the getPhoneCameraDevice static method. The camera reader has several options when initialized. The following parameters are required:
The Context parameter provides a reference to the activity you are currently in.
The CameraMode parameter is of type CameraMode defined in CameraMode.java and it accepts one of the values listed in the following table.
These modes provide the following default settings for the reader:
Based on the selected mode, additional illumination options and behaviors are set, also listed in the table.
Value | Description | Illumination | Live-Stream Preview |
---|---|---|---|
NO_AIMER | Initializes the reader to use a live-stream preview on the mobile device screen so the user can position the barcode within the camera’s field of view for detection and decoding. Use this mode if the mobile device does not have an aiming accessory. | Illumination is available and a button to control it is visible on the live-stream preview. | Displayed |
If commands are sent to the reader for aimer control, they are ignored. | |||
PASSIVE_AIMER | Initializes the reader to use a passive aimer. No live-stream preview is available on the device screen in this mode, since an aiming pattern is projected. | Illumination is not available, and the live-stream preview does not have an illumination button. | Not Displayed |
If commands are sent to the reader for illumination control, they are ignored because it is assumed in this mode that the built-in LED of the mobile device is being used for the aimer. | |||
FRONT_CAMERA | Initializes the reader to use the front camera of the mobile device, if available. Use this configuration with care because most front facing cameras do not have auto focus and illumination, and provide significantly lower resolution images. Illumination is not available in this mode. | The front camera is used. | Displayed |
Illumination is not available and the live-stream preview does not have an illumination button. | |||
If commands are sent to the reader for aimer or illumination control, they are ignored. |
The PreviewOption parameter is of type PreviewOption defined in PreviewOption.java, and is used to change the reader’s default values or override defaults derived from the selected CameraMode. You can specify the following options:
Value | Description |
---|---|
DEFAULTS | Accept all defaults set by the CameraMode. |
NO_ZOOM_BUTTON | Hides the zoom button on the live-stream preview, preventing the user from adjusting the zoom of the mobile device camera. |
NO_ILLUMINATION_BUTTON | Hides the illumination button on the live-stream preview, preventing the user from toggling the illumination. |
HARDWARE_TRIGGER | Enables a simulated hardware trigger (the volume down button) for starting scanning on the mobile device. This button only starts scanning when pressed, it does not need to be held like a purpose-built scanner’s trigger, and pressing it a second time does not stop the scanning process. |
PAUSED | If using a live-stream preview, the preview is displayed when the startScanning() method is called, but the reader does not start decoding until the user presses the on-screen button to start the scanning process. |
ALWAYS_SHOW | Forces a live-stream preview to be displayed even if an aiming mode is selected (for example CameraMode == PASSIVE_AIMER). |
HIGH_RESOLUTION | Uses the device camera in higher resolution, changing the default 1280x720 resolution to 1920x1080 on devices that support it, and to the default resolution on devices that do not support it. This can help with scanning small barcodes, but increases the decoding time as there is more data to process in each frame. |
HIGH_FRAME_RATE | Uses the device's camera in 60 FPS instead of the default 30 FPS to provide a smoother camera preview. |
SHOW_CLOSE_BUTTON | Show close button in partial view. |
The ViewGroup (optional) parameter specifies the container for the live-stream preview. If the parameter is left null, a full screen preview is used.
The RegistrationKey (optional) parameter is used to license your SDK with license key that you have
The CustomData (optional) parameter is used for custom tracking
Example
Create a reader with no aimer, no zoom button, and using a soft trigger:
readerDevice = ReaderDevice.getPhoneCameraDevice(this, CameraMode.NO_AIMER, PreviewOption.NO_ZOOM_BUTTON | PreviewOption.PAUSED);
This starts a preview with the scanner paused and a soft trigger button to toggle scanning. After pressing the soft trigger button, the expected preview look is this:
The viewfinder in the image has an active scanning surface as a result of having set active symbologies. For more details, see Enabling Symbologies.
From Android 6.0 and above you need to request permission from the user to access the built-in camera of the mobile device.
If the camera cannot be opened due to permission issues, the onConnectionCompleted(readerDevice, error) callback contains a CameraPermissionException in the error parameter. You can check for this exception type with the instanceof operator and request permission within the Activity.
if (error instanceof CameraPermissionException)
ActivityCompat.requestPermissions(((ScannerActivity) this), new String[]{Manifest.permission.CAMERA}, REQUEST_PERMISSION_CODE);
You need to implement the ActivityCompat.OnRequestPermissionResultCallback interface in your Activity to catch the user permission result.
To handle user response in onRequestPermissionResult(…), you can use the following code to retry connecting to the phone camera:
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
// Check result from permission request. If it is allowed by the user, connect to readerDevice
if (requestCode == REQUEST_PERMISSION_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (readerDevice != null && readerDevice.getConnectionState() != ConnectionState.Connected)
readerDevice.connect(ScannerActivity.this);
} else {
if (ActivityCompat.shouldShowRequestPermissionRationale(((ScannerActivity) this), Manifest.permission.CAMERA)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setMessage("You need to allow access to the Camera")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialogInterface,
int i) {
ActivityCompat.requestPermissions(ScannerActivity.this, new String[]{Manifest.permission.CAMERA},
REQUEST_PERMISSION_CODE);
}
})
.setNegativeButton("Cancel", null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
}
}
Before connecting, set the ReaderDeviceListener object to receive events:
readerDevice.setReaderDeviceListener(this);
For details, see step 3 in Setting up you application to-use the Cognex Mobile Barcode SDK for Android.
Additionally, you can enable sending the last triggered image and SVG from the reader:
readerDevice.enableImage(true);
readerDevice.enableImageGraphics(true);
Invoke the connect method after initializing the ReaderDevice and setting a listener method to handle responses from the reader. The connect method takes OnConnectionCompletedListener as parameter:
//Make sure the device is turned ON and ready
readerDevice.connect(ScannerActivity.this);
The following listener methods are called with the new ReaderDevice status information:
public void onConnectionStateChanged(ReaderDevice reader);
public void onConnectionCompleted(ReaderDevice reader, Throwable err)
The onConnectionCompleted method passed as a parameter of connect is also invoked as the connection process completes. If there was a connection error, this method provides a Throwable object.
After connecting to the scanning device, you may need to change some of its settings. CmbSDK provides a set of high-level and device-independent APIs for setting and retrieving the current configuration of the device.
You can start scanning barcodes with a properly configured reader by calling the startScanning method from your ReaderDevice class:
readerDevice.startScanning();
You can stop scanning with the following:
readerDevice.stopScanning();
Scanning stops under one of the following conditions:
When a barcode is decoded successfully, you receive a ReadResults iterable result collection object in the ReaderDevice listener method. The onReadResultReceived listener method is invoked either because the reader decoded a barcode or the scanning process was complete.
Example
// This is called after scanning has completed, either by detecting a barcode, canceling the scan by using the on-screen button or a hardware trigger button, or if the scanning timed-out
@Override
public void onReadResultReceived(ReaderDevice readerDevice, ReadResults results) {
clearResult();
if (results.getSubResults() != null && results.getSubResults().size() > 0) {
for (ReadResult subResult : results.getSubResults()) {
createResultItem(subResult);
}
} else if (results.getCount() > 0) {
createResultItem(results.getResultAt(0));
}
isScanning = false;
btnScan.setText("START SCANNING");
resultListAdapter.notifyDataSetChanged();
}
CmbSDK does not enable any symbologies by default for barcode reading with the built-in camera of the mobile device. You must enable all barcode symbologies your application needs to scan to achieve optimal scanning performance. For more details, see Optimizing Mobile Device Performance.
Individual symbologies can be enabled using the following method of the ReaderDevice class:
public void setSymbologyEnabled(final Symbology symbology, final boolean enable, final OnSymbologyListener listener)
readerDevice.setSymbologyEnabled(Symbology.DATAMATRIX, true, null);
readerDevice.setSymbologyEnabled(Symbology.UPC_EAN, true, null);
All symbologies used for the symbology parameter in this method can be found in ReaderDevice.java.
Examples
/* Enable QR scanning */
readerDevice.setSymbologyEnabled(Symbology.QR, true, null);
You can also use the same method to disable symbologies:
/ * Disable Code 25 scanning */ readerDevice.setSymbologyEnabled(Symbology.C25, false, null);
You can implement the method for OnSymbologiesListener to check the result of the symbology change:
@Override
public void onSymbologyEnabled(ReaderDevice reader, Symbology symbology, Boolean enabled, Throwable error) {
if (error != null) {
/* Unsuccessful
probably the symbology is unsupported by the current device, or there is a problem with the connection between the readerDevice and MX device */
} else {
// Success }
}
If your reader device is equipped with illumination lights, you can control them: when scanning starts, you can turn them on or off. Use the following method of your Reader Device object:
readerDevice.setLightsOn(true, null);
You can implement the interface method for OnLightsListener, which is the second parameter of the method.
public class ScannerActivity extends AppCompatActivity implements .... OnLightsListener .... { ....
@Override
public void onLightsOnCompleted(ReaderDevice reader, Boolean on, Throwable error) {
if (error != null) { // Unsuccessful
} else {
// Success }
} }
If the built-in camera of a mobile device is used as the reader device, you can configure zoom levels and how they are used. There are three zoom levels:
The SET CAMERA.ZOOM-PERCENT [100-MAX] [100-MAX] command is for configuring how far the two levels zoom in percentage. 100 is not zoomed and MAX (goes up to 1000) zooms as far as the device is capable of. The first argument is used for setting level 1 zoom, and the second for level 2 zoom.
You can check the current zoom setting with the GET CAMERA.ZOOM-PERCENT command, which returns two values: level 1 and level 2 zoom.
Example
readerDevice.getDataManSystem().sendCommand("SET CAMERA.ZOOM-PERCENT 250 500");
GET/SET CAMERA.ZOOM 0-2 is another command that sets the zoom level or returns the actual setting. Possible values for the SET command are:
You can call this command before or even during scanning, and the zoom goes up to the configured level. If scanning is finished, the value is reset to normal behavior (0).
Example
readerDevice.getDataManSystem().sendCommand("SET CAMERA.ZOOM 2");
When using the mobile device's camera, cmbSDK allows you to see the camera preview inside a preview container or in full screen. This preview also contains a customizable overlay. The cmbSDK camera overlay features buttons for zooming, flashing and closing the scanner, and a progress bar indicating the scan timeout.
To use the legacy camera overlay originally used in cmbSDK v2.0.x and ManateeWorks SDK, use this property from MWOverlay before initializing the readerDevice:
MWOverlay.overlayMode = MWOverlay.OverlayMode.OM_LEGACY;
When using the cmbSDK overlay:
Both the cmbSDK and the legacy overlay allow you to change the images used on the zoom and flash buttons if your images have the same name as the names cmbSDK uses. You can find the images and names used in cmbSDK in the Resources/drawable-mdpi and drawable-hdpi directories. While the other resolutions are optional, these two directories must contain your images with the correct names so that cmbSDK displays the proper images.
Both the cmbSDK and the legacy overlay allow you to change the color and width of the rectangle that is displayed when a barcode is detected.
Example:
MWOverlay.locationLineColor = Color.YELLOW;
MWOverlay.locationLineWidth = 6;
Cognex scanning devices implement DataMan Control Commands (DMCC) for configuring and controlling the device. Every feature of the device can be controlled using this text-based language. The API provides a method for sending DMCC commands to the device. Commands exist both for setting and querying configuration properties.
The Appendix includes the complete DMCC reference for the camera reader.
The following examples show different DMCC sent to the device for more advanced configuration.
Examples
//Change the scan direction to omnidirectional
readerDevice.getDataManSystem().sendCommand("SET DECODER.1D-SYMBOLORIENTATION 0", ScannerActivity.this);
//Change live-stream preview's scanning timeout to 10 seconds
readerDevice.getDataManSystem().sendCommand("SET DECODER.MAX-SCAN-TIMEOUT 10", ScannerActivity.this);
You can also invoke DMCC query commands and receive their response in the OnResponseReceivedListener.onResponseReceived() method.
//Get the type of device connected readerDevice.getDataManSystem().sendCommand("GET DEVICE.NAME", new OnResponseReceivedListener() {
@Override
public void onResponseReceived(DataManSystem dataManSystem, DmccResponse dmccResponse) {
if (dmccResponse.getError() != null) {
// Unsuccessful
Log.e("DMCC_ERR", “GET DEVICE.NAME failed”,dmccResponse.getError());
} else {
// Success - Use the following result fields:
//int mResponseId = dmccResponse.getResponseId(); //String mPayLoad = dmccResponse.getPayLoad(); //byte[] mBinaryData = dmccResponse.getBinaryData(); }
} );
}
CmbSDK includes a method for resetting the device to its default settings. In case of an MX mobile terminal, the default setting are the saved configurations. In case of a built-in camera, the default settings are the defaults identified in the Appendix, where no symbologies are enabled.
To reset the device, add:
readerDevice.resetConfig(null);
When using an MX mobile terminal, there are three states that we can distinguish:
You can monitor the completion of this async method using the OnResetConfigListener interface, which is an optional parameter.
public class ScannerActivity extends Activity implements .... OnResetConfigListener .... { ....
@Override
public void onResetConfigCompleted(ReaderDevice reader, Throwable error) {
if (error != null) { // Unsuccessful
} else {
// Success }
}
When a barcode is successfully read, the onReadResultReceived method creates and returns a ReadResult object. In case of having multiple barcodes successfully read on a single image or frame, multiple ReadResult objects are returned in the ReadResult object.
The ReadResult class has properties describing the result of a barcode read:
When a scanning ends with no successful read, a ReadResult is returned with the goodRead property set to false.
To enable the image and imageGraphics properties being filled in the ReadResult object, set the corresponding enableImage() and/or enableImageGraphics() properties of the ReaderDevice object.
To access the raw bytes from the scanned barcode, you can use the XML property. The bytes are stored as a Base64 String under the "full_string" tag. The example shows how you can use an XML parser to extract the raw bytes from the XML property.
Example
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
String tag = "";
// the raw bytes will be stored in this variable
byte[] bytes;
xpp.setInput(new StringReader(result.getXml()));
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
tag = xpp.getName();
}
else if (eventType == XmlPullParser.TEXT && tag.equals("full_string")) {
String base64String = xpp.getText();
// Get the bytes from the base64 string here
bytes = Base64.decode(base64String, Base64.DEFAULT);
break;
}
else if (eventType == XmlPullParser.END_TAG && tag.equals("full_string")) {
tag = "";
break;
}
eventType = xpp.next();
}
} catch (Exception e) {
e.printStackTrace();
}
The image and SVG results are disabled by default, which means that when scanning, the ReadResults do not contain any data in the corresponding properties.
To enable image results, invoke the enableImage() method from the ReaderDevice object:
readerDevice.enableImage(true);
To enable SVG results, invoke the enableImageGraphics() method on ReaderDevice object:
readerDevice. enableImageGraphics(true);
If a device disconnects due to low battery condition or manual cable disconnection, it can be detected by the onConnectionStateChanged() method of the ReaderDeviceListener interface.
The following table lists the various DMCC commands supported by the cmbSDK when using the built-in camera for barcode scanning.
GET/SET |
Command |
Parameter(s) |
Description |
Default value |
|
||
---|---|---|---|---|---|---|---|
GET/SET |
BATTERY.CHARGE |
|
Returns the current battery level of the device as a percentage. |
N/A |
|
||
|
BEEP |
|
Plays the audible beep (tone). |
N/A |
|
||
GET/SET |
BEEP.GOOD |
[0-3] [0-2] |
Sets the number of beeps (0-3) and the beep tone/pitch (0- 2, for low, medium, high). For the built-in camera, only a single beep with no pitch control is supported. Thus, 0 1 turns the beep off, 1 1 turns the beep on. |
1 1 (Turn beep on) |
|
||
GET/SET | CAMERA.ZOOM | 0-2 |
The possible values for the SET command are: 0 - normal (un-zoomed), 1 - zoom at level 1, 2 - zoom at level 2. This zoom level is used during scanning. When scanning ends it reset to 0. |
N/A | x | ||
GET/SET | CAMERA.ZOOM-PERCENT | [100-MAX] [100-MAX] |
Sets/Returns level 1 zoom (default 150% on Android, 200% on iOS), and level 2 zoom (default 300% on Android, 400% on iOS). Note: The camera needs to be started at least once from sdk to have a proper value for max capable zoom (MAX) |
N/A | x | ||
GET/SET |
CODABAR.CODESIZE |
ON min max |
Accepts any length Codabar. |
N/A |
X |
||
GET/SET |
C11.CHKCHAR |
ON | OFF |
Turns Code 11 check digit on/off. |
OFF |
X |
||
GET/SET |
C11.CHKCHAR-OPTION |
1 2 |
Requires single checksum. Requires double checksum. |
1 |
X |
||
GET/SET |
C11.CODESIZE |
ON min max |
Accepts any length Code 11. |
N/A |
X |
||
GET/SET |
C25.CODESIZE |
ON min max |
Accepts any length Code 25. |
N/A |
X |
||
GET/SET |
C39.ASCII |
ON | OFF |
Turns Code 39 extended ASCII on/off. |
OFF |
|
||
GET/SET |
C39.CODESIZE |
ON min max |
Accepts any length Code 39. |
N/A |
|
||
GET/SET |
C39.CHKCHAR |
ON | OFF |
Turns Code 39 check digit on/off |
OFF |
|
||
GET/SET |
C93.ASCII |
ON | OFF |
Turns Code 93 extended ASCII on/off |
OFF |
X |
||
GET/SET |
C93.CODESIZE |
ON min max |
Accepts any length Code 93. |
N/A |
|
||
GET/SET |
COM.DMCC-HEADER |
0 1 | Sets or gets the header option used in Extended mode. | 0 | |||
GET/SET |
COM.DMCC-RESPONSE | 0 1 |
DMCC response format. 1: Extended. |
0: Silent (default) | |||
|
CONFIG.DEFAULT |
|
Resets most of the camera API settings to default, except those noted as not resetting (see Appendix B). To reset all settings, use DEVICE.DEFAULT. |
N/A |
|
||
CONFIG.SAVE | Saves the current configuration to non-volatile memory (MX-1xxx only). Note that when an MX powers off or enters sleep mode, the last saved configuration is restored when the device wakes up. | N/A | |||||
CONFIG.RESTORE | Restores the saved configuration from non-volatile memory (MX-1xxx only). | N/A | |||||
GET/SET |
DATA.RESULT-TYPE |
|
Specifies results to be returned (sum for multiple values): |
1 |
|
||
GET/SET |
DATABAR.EXPANDED |
ON | OFF |
Turns the DataBar Expanded symbology on/off. |
OFF |
|
||
GET/SET |
DATABAR.LIMITED |
ON | OFF |
Turns the DataBar Limited symbology on/off. |
ON |
|
||
GET/SET |
DATABAR.GROUP DATABAR.RSS14 |
ON | OFF |
Turns the DataBar GROUP (before cmbSDK 2.4.1 known as RSS14) symbology on/off. |
ON |
X |
||
GET/SET |
DATABAR.RSS14STACK |
ON | OFF |
Turns the DataBar RSS14 Stacked symbology on/off. It is deprecated from cmbSDK v2.4.1, use DATABAR.GROUP instead. |
OFF |
X |
||
GET/SET |
DECODER.1D- SYMBOLORIENTATION |
0 |
Use omnidirectional scan orientation. |
1 |
|
||
GET/SET |
DECODER.EFFORT |
1-5 |
Sets the effort level for image analysis/decoding. The default is 2. Do not use 4-5 for online scanning. |
2 |
X |
||
GET/SET |
DECODER.MAX-SCAN- TIMEOUT |
1-120 |
Sets the timeout for the live-stream preview. When the timeout is reached, decoding is paused; the live-stream preview will remain on-screen. |
60 |
X |
||
GET | DECODER.MAX-THREADS | Returns the max number of CPU threads supported by the device. | N/A | X | |||
GET/SET | DECODER.THREADS-USED | [0-MAX] | Specify the max number of CPU threads that the scanner can use during the scanning process. | N/A | X | ||
|
DEVICE.DEFAULT |
|
Resets the device (including the camera API) settings to default (see Appendix B). |
N/A |
|
||
GET |
DEVICE.FIRMWARE-VER |
|
Gets the device firmware version. |
N/A |
|
||
GET |
DEVICE.ID |
|
Returns device ID assigned by Cognex to the scanning device. For a built-in camera, SDK returns 53. |
N/A |
|
||
GET/SET |
DEVICE.NAME |
|
Returns the name assigned to the device. By default, this is “MX-“ plus the last 6 digits of DEVICE.SERIAL-NUMBER. |
|
|
||
GET |
DEVICE.SERIAL- NUMBER |
|
Returns the serial number of the device. For a built-in camera, the SDK assigns a pseudo-random number. |
N/A |
|
||
GET |
DEVICE.TYPE |
|
Returns the device name assigned by Cognex to the scanning device. For a built-in camera, SDK returns “MX-Mobile”. |
N/A |
|
||
GET/SET |
FOCUS.FOCUSTIME |
0-10 |
Sets the camera’s auto-focus period (how often the camera should attempt to refocus). |
3 |
|
||
GET/SET |
I2O5.CHKCHAR |
ON | OFF |
Turns Interleaved 2 of 5 check digit on/off. |
OFF |
|
||
GET/SET |
I2O5.CODESIZE |
ON min max |
Accepts any length Interleaved 2 of 5. |
N/A |
X |
||
GET/SET |
IMAGE.FORMAT |
0 |
Scanner returns image result in bitmap format. |
1 (JPEG) |
|
||
GET/SET |
IMAGE.QUALITY |
10, 15, 20, ...90 |
Specifies JPEG image quality. |
50 |
|
||
GET/SET |
IMAGE.SIZE |
0 |
Scanner returns full size image. |
1 (1/4 size) |
|
||
GET/SET |
LIGHT.AIMER |
0-1 |
Disables/enables the aimer (when the scanner starts). |
Default based on cameraMode: 0: NoAimer and FrontCamera 1: PassiveAimer and ActiveAimer |
|
||
GET/SET | LIGHT.AIMER-TIMEOUT | 0-600 | Aimer Timeout in seconds. | N/A | |||
GET/SET |
LIGHT.INTERNAL- ENABLE |
ON | OFF |
Enables/disables illumination (when the scanner starts). |
OFF |
|
||
GET/SET |
MSI.CHKCHAR |
ON | OFF |
Turns MSI Plessey check digit on/off. |
OFF |
|
||
GET/SET |
MSI.CHKCHAR-OPTION |
0 |
Use mod 10 checksum |
0 |
|
||
GET/SET |
MSI.CODESIZE |
ON min max |
Accepts any length MSI Plessey. |
N/A |
X |
||
GET/SET |
SYMBOL.AZTECCODE |
ON | OFF |
Turns the Aztec Code symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.CODABAR |
ON | OFF |
Turns the Codabar symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.C11 |
ON | OFF |
Turns the Code 11 symbology on/off. |
OFF |
X |
||
GET/SET |
SYMBOL.C128 |
ON | OFF |
Turns the Code 128 symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.C25 |
ON | OFF |
Turns the Code 25 symbology on/off (standard). |
OFF |
|
||
GET/SET |
SYMBOL.C39 |
ON | OFF |
Turns the Code 39 symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.C93 |
ON | OFF |
Turns the Code 93 symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.COOP |
ON | OFF |
Turns the COOP symbology (Code 25 variant) on/off. |
OFF |
X |
||
GET/SET |
SYMBOL.DATAMATRIX |
ON | OFF |
Turns the Data Matrix symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.DATABAR |
ON | OFF |
Turns the DataBar symbologies on/off. Check also DATABAR:GROUP, DATABAR.LIMITED, DATABAR.EXPANDED to check which subtypes are read if Databar is turned on. |
OFF |
|
||
GET/SET |
SYMBOL.DOTCODE |
ON | OFF |
Turns the DotCode symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.IATA |
ON | OFF |
Turns the IATA symbology (Code 25 variant) on/off. |
OFF |
X |
||
GET/SET |
SYMBOL.INVERTED |
ON | OFF |
Turns the Inverted symbology (Code 25 variant) on/off. |
OFF |
X |
||
GET/SET |
SYMBOL.ITF14 |
ON | OFF |
Turns the ITF-14 symbology (Code 25 variant) on/off. |
OFF |
X |
||
GET/SET |
SYMBOL.UPC-EAN |
ON | OFF |
Turns the UPC-A, UPC-E, EAN-8, and EAN-13 symbologies on/off. |
OFF |
|
||
GET/SET |
SYMBOL.MATRIX |
ON | OFF |
Turns the Matrix symbology (Code 25 variant) on/off. |
OFF |
X |
||
GET/SET |
SYMBOL.MAXICODE |
ON | OFF |
Turns the MaxiCode symbology on/off. |
OFF |
X |
||
GET/SET |
SYMBOL.MSI |
ON | OFF |
Turns the MSI Plessey symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.PDF417 |
ON | OFF |
Turns the PDF417 symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.PLANET |
ON | OFF |
Turns the PLANET symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.POSTNET |
ON | OFF |
Turns the POSTNET symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.4STATE-IMB |
ON | OFF |
Turns the Intelligent Mail Barcode symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.4STATE-RMC |
ON | OFF |
Turns the Royal Mail Code symbology on/off. |
OFF |
|
||
GET/SET |
SYMBOL.QR |
ON | OFF |
Turns the QR and MicroQR symbologies on/off. |
OFF |
|
||
GET/SET |
TRIGGER.TYPE |
0 |
Single (not supported) |
2 (Manual) |
|
||
GET/SET |
UPC-EAN.EAN13 |
ON | OFF |
Turns the EAN-13 symbology on/off. |
ON |
X |
||
GET/SET |
UPC-EAN.EAN8 |
ON | OFF |
Turns the EAN-8 symbology on/off. |
ON |
X |
||
GET/SET |
UPC-EAN.UPC-A |
ON | OFF |
Turns the UPC-A symbology on/off. |
ON |
X |
||
GET/SET |
UPC-EAN.UPC-E |
ON | OFF |
Turns the UPC-E symbology on/off. |
ON |
X |
||
GET/SET |
UPC-EAN.UPCE1 |
ON | OFF |
Turns the UPC-E1 symbology on/off. |
OFF |
|
||
GET/SET |
UPC-EAN.SUPPLEMENT |
0 |
Turns off UPC supplemental codes (ignored) |
0 |
|
||
GET/SET | VIBRATION.GOOD | ON | OFF | Sets/gets whether to vibrate when a code is read (default is ON) | N/A |