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
-
Install Visual Studio 2019 on Windows computer
https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio?view=vs-2019 -
Follow instruction in the provided link below to configure Xamarin.Android
https://docs.microsoft.com/en-us/xamarin/android/get-started/installation/windows -
Additionally, follow instructions below in linking to a MAC which is mandatory requirement.
https://docs.microsoft.com/en-us/xamarin/ios/get-started/installation/windows/connecting-to-mac/
Follow instruction in the provided link below to configure Xamarin.iOS.
https://docs.microsoft.com/en-us/xamarin/ios/get-started/installation/windows/?pivots=windowsmacOS
-
Follow instructions in the provided link to install Visual Studio 2019 on Mac OS. Make sure to select “iOS + Xamarin.Forms” workload during the installation.
https://docs.microsoft.com/en-us/visualstudio/mac/installation?view=vsmac-2019
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.
Provide an App Name and the Organization Identifier.
Provide a Project Name and create the project.
Add references to the 'ZebraBarcodeNativeLibrary.dll' and 'ZebraBarcodeScannerSDK.dll' Zebra libraries by right click on References → Add References → .Net Assembly → Browse
Update the 'Info.plist' as described here.
Add following entries under “Required background modes” property:
- App communicates with an accessory
- App communicates using CoreBluetooth
Add following entries under “Supported external accessory protocols” property to support CS4070:
- com.zebra.scanner.SSI
- com.motorolasolutions.scanner
- com.motorolasolutions.CS4070_ssi
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
Add “NSBluetoothAlwaysUsageDescription” property:
- To add this property, open 'Info.plist' file through XCode
- Right click on 'Info.plist' file and select Open With → Xcode
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.
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.
Provide an App Name and the Organization Identifier.
Provide a Project Name and create the project.
Add references to the 'ZebraBarcodeNativeLibrary.dll' and 'ZebraBarcodeScannerSDK.dll' Zebra libraries by right click on Dependencies → Add References → .Net Assembly → Browse
Update the 'Info.plist' as described here.
Add following entries under 'Required background modes' property:
- App communicates with an accessory
- App communicates using CoreBluetooth
Add following entries under “Supported external accessory protocols” property to support CS4070:
- com.zebra.scanner.SSI
- com.motorolasolutions.scanner
- com.motorolasolutions.CS4070_ssi
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
Add “NSBluetoothAlwaysUsageDescription” property
- To add this property, open 'Info.plist' file through XCode
- Right click on 'Info.plist' file and select Open With → Xcode
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.
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.
Provide an App Name and the Organization Identifier.
Provide a Project Name and create the project.
Add references to the 'ZebraAndroidScannerLibrary.dll' and 'ZebraBarcodeScannerSDK.dll' Zebra libraries by right click on References → Add References → .Net Assembly → Browse
Update AndroidManifest.xml with required permissions.
Add following permissions under 'Required Permissions'
- Bluetooth
- BluetoothAdmin
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.
Provide an App Name and the Organization Identifier.
Provide a Project Name and create the project.
Add references to the 'ZebraAndroidScannerLibrary.dll' and 'ZebraBarcodeScannerSDK.dll' Zebra libraries by right click on Dependencies → Add References → .Net Assembly → Browse
Update 'AndroidManifest.xml' with required permissions.
Add following permissions under 'Required Permissions'
- Bluetooth
- BluetoothAdmin
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.
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 |
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();