CMB SDK iOS
Cognex Mobile Barcode iOS SDK

Introduction

The CMB SDK can be used to connect to Cognex Barcode readers and perform operations on these systems. You can retrieve read results, images, image graphics and read statistics. The SDK also allows you to configure your system or change individual settings. Refer to the DMCC Command Reference document for a complete list of DMCC commands that you can send to a Cognex system.

The SDK package contains a sample application that shows you the basic concepts and how to use the SDK.

Quick Start

The CMB SDK comprises the iOS SDK lib files and their documentation. The library files are available for iOS 10.1.

Using the DataMan SDK library

To use the DataMan SDK for an iOS project, you will need to add the following files to your XCode project:

After adding the files, make sure, that the libDataManSDK.a file is present in the Project Settings > Build Phases > Link Binary With Libraries section.

Creating and Initializing CDMDataManSystem

First of all use the following header file to access the DataMan SDK classes:

#import "DataManSDK.h"

For communication with each DataMan device, you will need to create a CDMDataManSystem object. Here is a sample code showing how to connect to a device using its IP address.

CDMDataManSystem *dataManSystem;
dataManSystem = [CDMDataManSystem dataManSystemWithHostname:@"10.86.80.71" withPort:23 withDelegate:self];

To connect to an External Accessory device, like the MX-1000, you will need to include the DataMan External Accessory Protocol identifier in the Info.plist of your project:

<key>UISupportedExternalAccessoryProtocols</key>
<array>
<string>com.cognex.dmcc</string>
</array>

Then you can enumerate the available connected devices with:

NSArray* connectedAccessories = [[CDMEADiscoverer sharedDiscoverer] compatibleAccessories];

To initialize CDMDataManSystem object for a connected device:

CDMDataManSystem *dataManSystem;
if (connectedAccessories.count > 0)
dataManSystem = [CDMDataManSystem dataManSystemWithAccessory:connectedAccessories[0] delegate:self];

Next, the result types needs to be specified:

[dataManSystem setResultTypes:(kCDMResultTypeImage | kCDMResultTypeImageGraphics | kCDMResultTypeReadXml | kCDMResultTypeReadString)];

To connect, the connect method will be called:

[dataManSystem connect];

To send commands to the device and retrieve their responses through the DataMan SDK, you can use the sendCommand method:

[self.dataManSystem sendCommand:@"TRIGGER ON" withCallback:^(CDMResponse *response){
if (response.status == DMCC_STATUS_NO_ERROR) {
// command has succeed.
} else {
// handle error
}
}];
[self.dataManSystem sendCommand:@"GET TRAINED-CODE.INFO" withCallback:^(CDMResponse *response){
if (response.status == DMCC_STATUS_NO_ERROR) {
if ([response.payload isEqualToString:@"Untrained"]) {
// device is untrained
} else {
// device is trained
}
}
}];

Receiving messages from a CDMDataManSystem

To receive messages from a DataMan system, you will need to implement the CDMDataManSystemDelegate protocol and pass the class as a delegate when initializing the DataMan system. Here is a skeleton implementation of the delegate methods. Note that only the first four methods are required, the rest are optional methods.

- (void)dataManSystemDidConnect:(CDMDataManSystem *)dataManSystem
{
NSLog(@"CDMAppDelegate dataManSystemDidConnect");
}
- (void)dataManSystemDidDisconnect:(CDMDataManSystem *)dataManSystem withError:(NSError *)error
{
if(error)
{
NSLog(@"dataManSystemDidDisconnect with error: %@", [error description]);
}
else
{
NSLog(@"dataManSystemDidDisconnect");
}
}
- (void)dataManSystemDidMissHeartbeatResponse:(CDMDataManSystem *)dataManSystem
{
NSLog(@"dataManSystemDidMissHeartbeatResponse");
}
- (void)dataManSystem:(CDMDataManSystem *)dataManSystem didReceiveReadString:(NSString *)readString withId:(int)resultId
{
NSLog(@"didReceiveReadString:%@ withId: %d", readString, resultId);
}
- (void)dataManSystem:(CDMDataManSystem *)dataManSystem didReceiveImage:(UIImage *)image withId:(int)resultId
{
NSLog(@"didReceiveImage");
}