Programmer's Guide for Xamarin Wrapper for Scanner SDK

Overview

This section provides step-by-step instructions on developing Xamarin Framework based Scanner applications for Android and iOS with Microsoft Visual Studio 2019.


Development Environment

Please refer the instructions provided below for configuring development environment in the respective platform.

Microsoft Windows

macOS


Create Xamarin iOS Project

Open Visual Studio 2019, navigate to File → New Solution → iOS → App → Single View App and create the iOS application by following the wizard.

Figure 1: Select Project Type

Provide an App Name and the Organization Identifier.

Figure 2: iOS Project Configuration

Provide a Project Name and create the project.

Figure 3: Project Details

Add references to the 'ZebraBarcodeNativeLibrary.dll' and 'ZebraBarcodeScannerSDK.dll' Zebra libraries by right click on References → Add References → .Net Assembly → Browse

Figure 4: Project References

Update the 'Info.plist' as described here.

Add following entries under “Required background modes” property:

  • App communicates with an accessory
  • App communicates using CoreBluetooth

Figure 5: Project plist for iOS

Add following entries under “Supported external accessory protocols” property to support CS4070:

  • com.zebra.scanner.SSI
  • com.motorolasolutions.scanner
  • com.motorolasolutions.CS4070_ssi

Figure 6: Project plist for iOS (for CS4070)

Add following entries under “Supported external accessory protocols” property to support CS6080:

  • com.zebra.scanner.SSI
  • com.motorolasolutions.scanner
  • com.motorolasolutions.CS4070_ssi
  • com.zebra.scanner.CS6080_ssi

Figure 7: Project plist for iOS (for CS6080)

Add “NSBluetoothAlwaysUsageDescription” property:

  • To add this property, open 'Info.plist' file through XCode
  • Right click on 'Info.plist' file and select Open With → Xcode
Figure 8: Project plist property update

Select “Privacy- Bluetooth Always Usage Description” property and add “Bluetooth is used to discover, connect and communicate with nearby devices” as the property value. Save and close the opened Xcode file.

Figure 9: Usage Description

Create Xamarin Forms iOS Project

Open Visual Studio 2019 IDE, navigate to File → New Solution → Multiplatform → App → Blank Forms App and create the iOS application by following the wizard.

Figure 10: Project Type

Provide an App Name and the Organization Identifier.

Figure 11: Project Configuration

Provide a Project Name and create the project.

Figure 12: Project Details

Add references to the 'ZebraBarcodeNativeLibrary.dll' and 'ZebraBarcodeScannerSDK.dll' Zebra libraries by right click on Dependencies → Add References → .Net Assembly → Browse

Figure 13: Project References

Update the 'Info.plist' as described here.

Add following entries under 'Required background modes' property:

  • App communicates with an accessory
  • App communicates using CoreBluetooth

Figure 14: Project plist for iOS

Add following entries under “Supported external accessory protocols” property to support CS4070:

  • com.zebra.scanner.SSI
  • com.motorolasolutions.scanner
  • com.motorolasolutions.CS4070_ssi

Figure 15: Project plist for iOS (for CS4070)

Add following entries under “Supported external accessory protocols” property to support CS6080:

  • com.zebra.scanner.SSI
  • com.motorolasolutions.scanner
  • com.motorolasolutions.CS4070_ssi
  • com.zebra.scanner.CS6080_ssi

Figure 16: Project plist for iOS (for CS6080)

Add “NSBluetoothAlwaysUsageDescription” property

  • To add this property, open 'Info.plist' file through XCode
  • Right click on 'Info.plist' file and select Open With → Xcode

Figure 17: Project plist property update

Select “Privacy - Bluetooth Always Usage Description” property and add “Bluetooth is used to discover, connect and communicate with nearby devices” as the property value. Save and close the opened Xcode file.

Figure 18: Usage Description

Create Xamarin Android Project

Open Visual Studio 2019, navigate to File → New Solution → Android → App → Android App and create the Android application by following the wizard.

Figure 19: Project Type

Provide an App Name and the Organization Identifier.

Figure 20: Project Configuration

Provide a Project Name and create the project.

Figure 21: Project Details

Add references to the 'ZebraAndroidScannerLibrary.dll' and 'ZebraBarcodeScannerSDK.dll' Zebra libraries by right click on References → Add References → .Net Assembly → Browse

Figure 22: Project References

Update AndroidManifest.xml with required permissions.

Figure 23: Project References

Add following permissions under 'Required Permissions'

  • Bluetooth
  • BluetoothAdmin

Figure 24: Setting Permissions

Create Xamarin Forms Android Project

Open Visual Studio 2019 IDE, navigate to File → New Solution → Multiplatform → App → Blank Forms App and create the Android application by following the wizard.

Figure 25: Project Type

Provide an App Name and the Organization Identifier.

Figure 26: Project Configuration

Provide a Project Name and create the project.

Figure 27: Project Details

Add references to the 'ZebraAndroidScannerLibrary.dll' and 'ZebraBarcodeScannerSDK.dll' Zebra libraries by right click on Dependencies → Add References → .Net Assembly → Browse

Figure 28: Project References

Update 'AndroidManifest.xml' with required permissions.

Figure 29: Project References

Add following permissions under 'Required Permissions'

  • Bluetooth
  • BluetoothAdmin

Figure 30: Setting Permissions

Wrapper APIs

Namespace

Import the Scanner SDK namespace before making API calls.


using ZebraBarcodeScannerSDK;

Query SDK Version

Version information could be queried as follows.


//Create an instance of the ScannerSDK
ScannerSDK scannerSdk = new ScannerSDK();
    
//Get the scanner SDK version
string version = scannerSdk.Version;    

Set Operation Mode

Set the operation mode of the reader.


//Create an instance of the Scanners
Scanners scanners = scannerSdk.ScannerManager;
    
//Set Operation Mode for Scanner SDK
scanners.SetOperationMode(OpMode.OPMODE_MFI);    

Supports following operation modes,

iOS

  • OPMODE_MFI
  • OPMODE_BTLE
  • OPMODE_MFI_BTLE

Android

  • OPMODE_SSI
  • OPMODE_SNAPI
  • OPMODE_BTLE

Enable Available Scanner Detection

Enable or Disable enable available scanner detection.


//Enable available scanner detection for SDK.
scanners.EnableAvailableScannersDetection(true);
    
// Disable available scanner detection for SDK.
scanners.EnableAvailableScannersDetection(false);    

Subscribe for Events

Subscribe for events which want for SDK user.


//Subscribe to scanner appearance and scanner disappearance events.
scanners.SubscribeForEvents((int)Notifications.EVENT_SCANNER_APPEARANCE | (int)Notifications.EVENT_SCANNER_DISAPPERANCE)

Available events.

  • EVENT_SCANNER_APPEARANCE
  • EVENT_SCANNER_DISAPPERANCE
  • EVENT_SESSION_ESTABLISHMENT
  • EVENT_SESSION_TERMINATION
  • EVENT_BARCODE
  • EVENT_RAW_DATA
  • Get Available Scanner List

    Query available scanner list as follows.

    If operation mode set to “OPMODE_MFI” SDK will return scanners which are paired with the device via MFI mode.

    If operation mode set to “OPMODE_BTLE” SDK will return scanners which are discoverable to the device.

    
    //Get available scanners list
    List<Scanner> discoveredScannerList = scanners.GetAvailableScanners();    
    
    

    Connect/Disconnect Scanner

    Connect to the first available scanner.

    
    //Connect to a given scanner
    discoveredScannerList[0].Connect();          
    
    

    Disconnect a scanner.

    
    //Disconnect from a given scanner
    discoveredScannerList[0].Disconnect();       
    
    

    Enable/Disable Bluetooth scanner discovery

    This will enable/disable Bluetooth scanner discovery process.

    
    //Enable automatic scanner re-connection. 'scanner' is a connected Scanner object
    scanner. EnableAutoReconnection(true);
            
    //Disable automatic scanner re-connection. 'scanner' is a connected Scanner object 
    scanner. EnableAutoReconnection(false);    
    
    

    Enable/Disable Scanner

    Enable the connected barcode scanner.

    
    //Enable connected barcode scanner. 'scanner' is a connected Scanner object
    scanner.EnableScanner(); 
    
    

    Disable the connected barcode scanner.

    
    //Disable connected barcode scanner. 'scanner' is a connected Scanner object
    scanner.DisableScanner();       
    
    

    Enable Scanner Auto Re-Connection

    This will enable/Disable automatic re-connection of the scanner.

    
    //Enable automatic scanner re-connection. 'scanner' is a connected Scanner object
    scanner.EnableAutoReconnection(true)
        
    //Disable automatic scanner re-connection. 'scanner' is a connected Scanner object 
    scanner.EnableAutoReconnection(false)    
    
    

    Get Scanner Asset Information

    Connected scanner Asset information can retrieve through this API.

    
    //Get scanner asset information from a connected scanner
    AssetInformation assetInformation = scanner.ScannerAssetInformation();
        
    Console.WriteLine("Configuration name :" + assetInformation.ConfigurationName);
    Console.WriteLine("Serial number :" + assetInformation.SerialNumber);
    Console.WriteLine("Model number :" + assetInformation.ModelNumber);
    Console.WriteLine("Firmware version :" + assetInformation.FirmwareVersion);
    Console.WriteLine("Manufactured date" + assetInformation.ManufacturedDate);                                  
    
    

    Enable/Disable pick list mode

    This will enable/disable pick list mode.

    
    //Enable pick list mode
    scanner.EnablePickListMode();
    
    //Disable pick list mode
    scanner.DisablePickListMode();
    
    

    Enable/Disable Symbology

    This will enable /disable symbology. Table 1 includes symbology attribute values.

    
    //Enable/Disable symbology 
    void SymbologyEnableDisable(string[] symbologyIdList, bool symbologyStatus)
    {
        string symbologyIdAttributeList = "";
        foreach (string symblogyId in symbologyIdList)
        {
            symbologyIdAttributeList += "<attribute><id>" + symblogyId + "</id><datatype>F</datatype><value>" + symbologyStatus + "</value></attribute>";
        }
    
        string inXml = "<inArgs>" + 
                            <scannerID>" + connectedScanner.Id + "</scannerID>" +
                            "<cmdArgs>" +
                                "<arg-xml>" +
                                    "<attrib_list>" +
                                        symbologyIdAttributeList +
                                    "</attrib_list>" +
                                "</arg-xml>" +
                            "</cmdArgs>" +
                        "</inArgs>";
    
        connectedScanner.ExecuteCommand(OpCode.RSM_ATTRIBUTE_SET, inXml);
    }
    
    //Symbology list. Refer Table 1 for symbology attribute values
    string[] symbologyIdList = { "1", "2", "8" };
    
    // Enable symbology
    SymbologyEnableDisable(symbologyIdList, true);
    
    // Disable symbology
    SymbologyEnableDisable(symbologyIdList, false);
    
    

    Table 1: Symbology Attribute Values

    Description Attribute Values
    UPC-A 1
    UPC-E 2
    UPC-E1 12
    EAN-8/JAN8 4
    EAN-13/JAN13 3
    Bookland EAN 83
    Code 128 8
    UCC/EAN-128 14
    Code 39 0
    Code 93 9
    Code 11 10
    Interleaved 2 of 5 6
    Discrete 2 of 5 5
    Chinese 2 of 5 408
    Codabar 7
    MSI 11
    Data Matrix 292
    PDF 15
    ISBT 128 84

    This will disable all symbologies.

    
    //Disable all symbologies 
    scanner.DisableAllSymbologies();
    
    

    LED Blink On/Off

    This code snippet will start/stop blinking LED on the reader.

    
    // Blink On
    string inXml = "<inArgs><scannerID>" + connectedScanner.Id + "</scannerID><cmdArgs><arg-int>85</arg-int></cmdArgs></inArgs>";
    connectedScanner.ExecuteCommand(OpCode.RSM_SET_ACTION, inXml);
    
    // Blink Off
    string inXml1 = "<inArgs><scannerID>" + connectedScanner.Id + "</scannerID><cmdArgs><arg-int>90</arg-int></cmdArgs></inArgs>";
    connectedScanner.ExecuteCommand(OpCode.RSM_SET_ACTION, inXml);
    
    

    Get Battery Statistics

    This will get battery statistics. Listing following attribute IDs in inXml, then battery statics data will be retrieved in outXml.

    Table 2: Battery Statics Attribute Values

    Description Attribute Values
    Manufacture Date 30018
    Serial Number 30030
    Model Number 30017
    Firmware Version 30019
    Design Capacity 30029
    State of Heath Meter 30023
    Charge Cycle Consumed 30021
    Full Charge Capacity 30020
    State of Charge 30012
    Remaining Capacity 30027
    Charge Status 30026
    Remaining Time To Complete Charging 30023
    Voltage 30010
    Current 30011
    Temperature Present 30016
    Temperature Highest 30024
    Temperature Lowest 30025
    
    // Get battery statistics
    void getBatteryStatistics(string[] batteryStatisticsAttributesIDs)
    {
        string batteryStatusAttributes = "";
        for (int i = 0; i < batteryStatisticsAttributesIDs.Length; i++)
        {
            if (i == batteryStatisticsAttributesIDs.Length - 1)
            {
                batteryStatusAttributes += batteryStatisticsAttributesIDs[i];
            }
            else    
            {
                batteryStatusAttributes += batteryStatisticsAttributesIDs[i] + ",";
            }
        }
    
        //In put xml
        string inXml = "" + 
                            "" + connectedScanner.Id + "" +
                            "" +
                                "" +
                                    "" +
                                        batteryStatusAttributes +
                                    "" +
                                "" +
                            "" +
                        "";
    
        //Out put result 
        string outXml = connectedScanner.ExecuteCommand(OpCode.RSM_ATTRIBUTE_GET, inXml);
        Console.WriteLine("Get Battery Statistics Result : ", outXml);
    }
    
    // Refer Table 2 for battery statics attribute ids 
    string[] batteryStatusAttributesIdList = {"30018","30030","30017","30019","30029"};
    
    getBatteryStatistics(batteryStatusAttributesIdList);
    
    

    Firmware Update Event

    
    // Subscribe for the FirmwareUpdate event
    scanners.FirmwareUpdate += FirmwareUpdate;
    
    // Event handler for firmware update.
    private async void firmwareUpdateEvent(FirmwareUpdateEvent firmwareUpdateEvent)
    {
        int maxRecord = firmwareUpdateEvent.MaxRecords;
        int currentRecord = firmwareUpdateEvent.CurrentRecord;
        double total = Convert.ToDouble(maxRecord);
        double current = Convert.ToDouble(currentRecord);
        double percentage = ((current / total) * 100);
    
        Console.WriteLine("Firmware update percentage " + percentage);
    }
    
    

    Read Weight

    This APIs Only support for the MP6000/MP7000 scanners which connected through SNAPI mode. This will Enable/Disable scale, Reset scale, Zero scale and Read weight.

    
    //Enable the scale
    String status = scanner.ScaleEnable();
        
    //Disable the scale
    String status = scanner.ScaleDisable();
        
    //Reset the scale
    String status = scanner.ResetScale();
        
    //Set zero scale
    String status = scanner.ZeroScale();
        
    //Read Weight
    WeightInfo weight = scanner.ReadWeight();