cognex mobile barcode sdk for android (v2.3.x)
TRANSCRIPT
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 1/37
CognexMobileBarcodeSDKforAndroid(v2.3.x)
BarcodeScanningwithaSmartphoneorTablet
Thedifferencesinthecapabilitiesofsmartphonesasbarcodescanningdevicesresultinauserexperiencedifferentfrompurpose-builtscanners,impactingthedesignofthemobilebarcodescanningapplication.Byfollowingafewsimpleguidelines,youcandevelopapplicationswiththecmbSDKthatworkthesamewaywhenusinganMXMobileTerminalorthebuilt-incameraofamobiledevice.
Toinitiatebarcodescanningwithoutadedicatedhardwaretrigger,seeMobileDeviceTriggering.Toaimforbarcodescanningwithasmartphonethatdoesnothaveanaimer,seeMobileDeviceAiming.Tochoosethemostsuitableorientationforbarcodescanning,seeMobileDeviceOrientation.ToreducetheCPUusageofthemobiledevicewhenitperformsimageanalysisandbarcodedecoding,seeOptimizingMobileDevicePerformance.
CmbSDKemploysadefaultsetofoptionsforbarcodereadingwiththebuilt-incameraofthemobiledevice.However,cmbSDKdoesnotimplementsavedconfigurationsforthecamerareader.Thismeansthateverytimeanapplicationstartsthatusesthecamerareader,itstartswiththedefaultsettingsofthecamerareader.Foralistofthedefaultsettings,seetheAppendix.
Overview
CognexMobileBarcodeSDK(cmbSDK)isatoolfordevelopingmobilebarcodescanningapplications.CmbSDKisbasedonCognex'sDataMantechnologyandtheManateeWorksBarcodeScanningSDKanditallowsyoutocreatebarcodescanningapplicationsformobiledevices.MobiledevicesusedforbarcodescanningrangefromsmartphonestotheMXSeriesindustrialbarcodereaders.CmbSDKabstractsthedevicethroughaReaderDeviceconnectionlayer.Oncetheapplicationestablishesitsconnectionwiththereader,asingle,unifiedAPIisusedasinterfacetoconfigurethedevice,e liminatingtheneedtowritetoomuchconditionalcode.
CmbSDKprovidestwobasicReaderDeviceconnectionlayers:
MXreaderforbarcodescanningwithdevicesliketheMX-1000andMX-1502Camerareaderforbarcodescanningwiththebuilt-incameraofthemobiledevice
BarcodeScanningwithanMXMobileTerminal
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 2/37
ThecmbSDKsupportsCognex’sMXSeriesMobileTerminalsandsomeoftheirfeaturesusingcmbSDKarethefollowing:
Hardwaret rigger:MXMobileTerminalsincludetwobuilt-intriggersforbarcodescanning.Theyalsosupportapistolgripwithtriggerthatisanoptionalaccessory.Illuminat ionandaiming:MXMobileTerminalshavebuilt-inilluminationandaiming,makingitunnecessarytohavealivepreviewonthesmartphone'sscreen.Conf igurat ions:YoucanexportandimportconfigurationsetstoMXMobileTerminalsusingCognex’sDataManSetupToolforWindows,theQuickSetupmobileapplicationorcmbSDK.Youcanhavemultiplescanningapplications,eachofwhichrequiresadifferentsetofdevicesettings.High-capacitybat tery:MXMobileTerminalshaveanintegratedbatterythatpowerstheMXscanningengineandthemobiledevice.TheoptionalpistolgripincludesasecondbatterythatdoublesthepowercapacityoftheMXMobileTerminal.
DebuggingonMXMobileTerminal
Normallyyouconnectyourmobiledevice(phoneortablet)toyourPCviatheUSBorlightningporttostartdebugging.IfanMXMobileTerminalisattachedtoyourmobiledeviceviatheUSBorlightningportwhileyourapplicationisrunning,youneedtodebugyourapplicationviaWi-Fi.
DebuggingonAndroid:
TodebugusingAndroidStudio,connectyourAndroiddeviceviaUSBtoyourPCandmakesureyoucanrunanddebugyourapplicationusingtheUSBcable.ToConnectyourAndroiddevicetoWi-Fi,makesurethatAndroidToolsareinstalledbesideyourIDE.
1. Type"adbtcpip5555"tosetthedevice'sportto5555intheterminal.2. Getthemobiledevice'sIPaddressbytyping"adbshellip-f inet addrshow
wlan0"orfinditmanuallyinthesettingsmenuofyourmobiledevice.3. Type"adbconnect device_ip:5555"toconnecttoyourmobiledevice.Thisprompts
amessageifitisconnectedsuccessfully.4. DisconnecttheUSBcablefromyourmobiledevice.5. ConnectyourmobiledevicetotheMXMobileTerminalandproceedtodebugyour
appasifitwasconnectedviacable.
Note:AfteryouconnectyourmobiledevicetotheMXMobileTerminal,Wi-Ficonnectionmightbelost.IftheWi-Ficonnectionislost,repeatstep3.
6. Whenyouaredone,type"adb-sdevice_ip:5555usb"toswitchyourdevicebacktoUSBconnectionmode.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 3/37
CAUTION:Leavingthewirelessdebuggingoptionenabledisnotrecommendedasanyoneinyournetworkcanconnecttoyourdeviceindebug,evenifyouareindatanetwork.DoitonlywhenyouareconnectedtoatrustedWiFianddisconnectwhenyouaredone.
BarcodeScanningwithaSmartphone
MobileDeviceTriggering
Withoutahardwaretrigger,mobiledevicesmustusealternativemethodstoinitiatebarcodescanning.ThecmbSDKsupportsthreemethodstotriggerbarcodescanning:
Applicat ionorworkf lowdrivent rigger:Theapplicationcodeorthebusinesslogic/workflowoftheapplicationinvokesthescanningmodule.Insimpleprogrammingterms,itiscallingafunctionlikestartScanner().Virtualt rigger:Tostartorstopthescanningprocesstheapplicationprovidesabuttononthescreen.Dependingontheapplicationdesign,youneedtopressandholdthevirtualbuttontokeepthescannerrunning,thisinvokesthescanningmodule.Simulatedt rigger:Pressoneofthevolume-downbuttonstostartorstopthescanningprocessjustlikewhenyoupullatriggeronapurpose-builtscanner.
MobileDeviceAiming
Thebuilt-incameraprovidesalive-streampreviewonthedisplayofthemobiledeviceforbarcodeaiming.Repositionthemobiledeviceuntilthebarcodeappearsinthefie ldofviewofthebuilt-incameraandtheapplicationdecodesit.CmbSDKprovidesabuilt-inpreviewcontrolthatcanbedisplayedinpartialorfullscreen,andineitherportraitorlandscapeorientation.
ThecmbSDKalsosupportspassiveaimers:devicesattachedtothemobiledeviceoritscasethatusetheLEDflashofthedeviceasalightsourcetoprojectanaimingortargetingpattern.Themobiledevicecanprojectanaimerpatternsimilartoapurpose-builtscannersolive-previewisnotneeded.However,byusingtheLEDflashasanaimer,generalscanningilluminationisnotavailable.
MobileDeviceOrientat ion
ThecmbSDKsupportsportraitorientation,landscapeorientationandauto-rotationforboththepresentationofthebarcodepreviewandthescandirection.Mobiledevicescanscanmostbarcodesregardlessoftheorientationoftheapplicationand/orthemobiledevice.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 4/37
PORTRAIT ORLANDSCAPE PORTRAIT ONLY
Mostbarcodescanbescannedineither
portraitorlandscapeorientation.
Mostwelldefinedandmoderatelysizedbarcodescanbescannedinaportrait
orientation,whichisthemostnaturalwaytoholdthemobiledevice.
Example:QR,DataMatrix,Maxicode.
Long,dense,orpoorlyformedbarcodesareeasiertoscaninalandscapeorientation,whichisof
OptimizingMobileDevicePerformance
Mobiledevicesareanidealplatformforbarcodedecoding.ThecmbSDKisoptimizedformobileenvironment,butimageanalysisandbarcodedecodingisstillaCPUintensiveactivity.Sincetheseprocessessharethemobiledevice'sCPUwiththemobileoperatingsystem(OS),services,andotherapplications,theseprocessesoptimizeyourbarcodescanningapplicationandlimitittoonlyusingthefeaturesofthecmbSDKthattheyneed.
Tooptimizeyourapplication:
Enabledecodingonlyforthebarcodetypestheapplicationneedstoscan.ThecmbSDKsupportsthedecodingofalmost40differentbarcodetypesandsubtypes,enablingallresultsinlowperformanceandunexpectederrors.Donotenablecertainsymbologiesand/oradvancedfeaturesatthesametime.Optimizeyourcameraresolution.Bydefault,thecmbSDKusesHDimagesforbarcodedecoding.Useanappropriatedecodereffortlevel.ThecmbSDKhasaconfigurableeffortlevelthatcontrolshowaggressivelyitperformsimageanalysis.ThecmbSDKusesadefaultvalue(level2)thatissufficientformostbarcodes.Usingahigherlevelcanresultinbetterdecodingofpoorerqualitybarcodes,resultinginslowerperformance.
Nobarcodesymbologiesareenabledbydefault,whenthecmbSDKisinitializedforusewiththemobiledevice'sbuilt-incamera.
UsingcmbSDK
InstallingcmbSDK
InstallingtheAndroidcmbSDK
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 5/37
Note:cmbSDKiscompatiblewithAndroidStudio.
1. DownloadtheCognexMobileBarcodeSDKforAndroidfromtheCognexMobileBarcodeScannerSolutionspage.
2. StartAndroidStudioandaddtheSDKAARfile asamoduletoyourproject:
1. Rightclickyourappmodule,selectNew>Module>Import.JAR/.AARPackage,andclickNext .
2. BrowsethecmbSDK.AARfile intheFilenamefie ld,andclickFinish.
3. Afterthenewmoduleisavailable,rightclickyourappmodule,selecttheOpenModuleSet t ings,andchoosetheDependenciestab.
4. Clickthe+signatthetopoftheDeclaredDependenciesdialogboxandselectthe3Moduledependency.
5. SelectcmbsdklibfromthepopupwindowandclickOK,makingthecmbsdklibmoduleavailableundertheDependenciestab.
6. InstalltheMXConnectapplicationfromthePlayStoretocommunicatewithMXmobileterminals.
InstallingtheiOScmbSDK:
1. InstallthelatestXCodeforiOSDevelopment.2. DownloadtheCognexMobileBarcodeSDKforiOS.
LicensingcmbSDK
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 6/37
TousecmbSDKforbarcodescanningwithamobiledevicewithoutanMXmobileterminal,youneedtoinstallalicensekey.Ifthelicensekeyismissing,asteriskswillappearinsteadofscannedresults.
ContactyourCognexSalesRepresentativeforinformationonhowtoobtainalicensekey,including30-daytriallicenses.
Android:
1. Afterobtainingyourlicensekey,addthefollowinglineintheAndroidManifest.xmlfileofyourapplicationundertheapplicationtag:
<meta-dataandroid:name="MX_MOBILE_LICENSE"android:value="YOUR_MX_MOBILE_LICENSE"/>
2. ReplaceYOUR_MX_MOBILE_LICENSEwithyourlicensekey.
<applicationandroid:allowBackup="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher"android:supportsRtl="true"android:theme="@style/AppTheme"><activityandroid:name=".ScannerActivity"android:configChanges="orientation|screenSize"><intent-filter><actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/></intent-filter></activity>
<meta-dataandroid:name="MX_MOBILE_LICENSE"android:value="g/9ytJzcja+sxt4DTEDxR4hp6sZh9bmL97vUx+EE9uY="/>
</application>
YoucanalsoaddthelicensekeybycopyingthetextbelowwhenyoucreatenewinstancefromReaderDevice.
casePhoneCamera:readerDevice=ReaderDevice.getPhoneCameraDevice(this,param_cameraMode,PreviewOption.DEFAULTS,null,"SDK_KEY");
iOS:
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 7/37
Afterobtainingyourlicensekey,additasaStringinyourapplication'sInfo.plistfile underthekeyMX_MOBILE_LICENSE.
Migrat ingfromaDataManSDKforMXReaderstocmbSDK
1. InstalltheMXConnectapplicationfromthePlaystore.ThisappenablesyourmobilephonetoseamlesslyconnecttoCognexMXreaders.
2. InstallcmbSDKtoyourproject.
3. UseDataManSystem.createDataManSystemForMXDevice()factorymethodtocreateaDatamanSystemobject.
4. Remove:
AllDataManSystem.createDataManSystemOverUsb()methodsfromyourproject.AllDataManSystem.createDataManSystemOverUsbAccessory()methodsfromyourproject.USB_DEVICE-ATTACHEDandUSB_ACCESSORY_ATTACHEDIntentfiltersandmeta-datafromtheAndroidManifest.xmlfile .USBandaccessorydescriptorxmlfilesfromtheXMLfolder.
Writ ingaMobileApplicat ion
CmbSDKprovidesahigh-level,abstractinterfaceforsupportedscanningdevices:theMXmobileterminalsandthecameraofthemobilephone.
TheprimaryinterfacebetweenyourapplicationandthebarcodescanningdeviceistheReaderDeviceclass.TheReaderDeviceclassrepresentsanabstractionlayertothe
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 8/37
device,handlingallcommunicationandnecessaryhardwaremanagement,suchasscanningwithasmartphone.
PerformthefollowingstepstousecmbSDK:
1. CreateaninstancefromtheReaderDeviceclasswiththetypeofscanningdeviceyouwanttouse(MXreaderorcamerareader).
2. ConnecttotheReaderDeviceinstanceyoucreated.
3. ConfiguretheReaderDeviceinstance,ifnecessary.
4. Startscanning.
Initializationandconnectionneedtobeperformedonlyonceinyourapplication.
MXmobileterminalsneedtobereconfigurediftheybecomedisconnectedduetoforexampletimingoutordrainedbattery.Toavoidthis,youcansavetheconfiguration.YourapplicationcanusebothanMXmobileterminalandcamerascanning.Inthiscaseyouhavetoestablishanewconnectiontoadifferentdeviceafterdisconnectingfromthecurrentdevice.Youcancheckoursampleappfordemonstrationtoseehowitworks.
Sett ingupanApplicat iontoUsecmbSDKforAndroid
PerformthefollowingstepstosetupandstartusingcmbSDK:
1. Importthefollowingpackagemembers,orjusttheclassesyouuse:
importcom.cognex.dataman.sdk.*importcom.cognex.mobile.barcode.sdk.*
2. BuildyourUIaccordingtoyourneeds,butconsideringthefollowingaspects:
Youhavetodecideifyouyouwanttoshowpartialorafullscreen(thatisthedefault)camerapreview.YouneedaViewGroupcontainertousepartialpreview,forexampleRelat iveLayout .Noadditionalcontainerisneededforfullscreenpreview.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 9/37
Oursampleapp(thatyoucanfindinthecmbSDKbundle)isusingfullscreenpreview.Tochangethesampleapptousepartialview,addthefollowingRelat iveLayout attheendofConst raintLayoutinact ivity_scanner.xmlfile .UsethislayoutadaViewGroupparameterinreaderdeviceconstructor(getPhoneCameraDevice)whenreaderdeviceisinitialized.
<RelativeLayoutandroid: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"/>
Todisplaythelastscannedimage,anImageViewcontainerisneeded.Todisplaythescannedresultasatext,aTextViewisneeded.
3. Setupthefollowinginterfacestomonitortheconnectionstateofthereaderandreceiveinformationaboutthereadcode:
publicclassScannerActivityextendsAppCompatActivityimplementsOnConnectionCompletedListener,ReaderDeviceListener,ActivityCompat.OnRequestPermissionsResultCallback{....
//Theconnectmethodhascompleted,hereyoucanseewhethertherewasanerrorwithestablishingtheconnectionornot@OverridepublicvoidonConnectionCompleted(ReaderDevicereaderDevice,Throwableerror){//Ifwehavevalidconnectionerrorparamwillbenull,//otherwisehereiserrorthatinformusaboutissuethatwehavewhileconnectingtoreaderdeviceif(error!=null){
//askforCameraPermissionifnecessaryif(errorinstanceofCameraPermissionException)ActivityCompat.requestPermissions(((ScannerActivity)this),newString[]{Manifest.permission.CAMERA},REQUEST_PERMISSION_CODE);
updateUIByConnectionState();}}
//Thisiscalledwhenaconnectionwiththeself.readerDevicehasbeenchanged.//ThereaderDeviceisusableonlyinthe"ConnectionState.Connected"state@OverridepublicvoidonConnectionStateChanged(ReaderDevicereader){clearResult();if(reader.getConnectionState()==ConnectionState.Connected){//Wejustconnected,sonowconfigurethedevicehowwewantitconfigureReaderDevice();
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 10/37
}
isScanning=false;updateUIByConnectionState();}
//Thisiscalledafterscanninghascompleted,eitherbydetectingabarcode,cancelingthescanbyusingtheon-screenbuttonorahardwaretriggerbutton,orifthescanningtimed-out@OverridepublicvoidonReadResultReceived(ReaderDevicereaderDevice,ReadResultsresults){clearResult();
if(results.getSubResults()!=null&&results.getSubResults().size()>0){for(ReadResultsubResult:results.getSubResults()){createResultItem(subResult);}}elseif(results.getCount()>0){createResultItem(results.getResultAt(0));}
isScanning=false;btnScan.setText("STARTSCANNING");resultListAdapter.notifyDataSetChanged();}
//ThisiscalledwhenaMX-1xxxdevicehasbecameavailable(USBcablewasplugged,orMXdevicewasturnedon),//orwhenaMX-1xxxthatwaspreviouslyavailablehasbecomeunavailable(USBcablewasunplugged,turnedoffduetoinactivityorbatterydrained)@OverridepublicvoidonAvailabilityChanged(ReaderDevicereader){if(reader.getAvailability()==Availability.AVAILABLE){connectToReaderDevice();}elseif(reader.getAvailability()==Availability.UNAVAILABLE){AlertDialog.Builderalert=newAlertDialog.Builder(this);alert.setTitle("Devicebecameunavailable").setPositiveButton("OK",null).create().show();}}
4. InstantiateaReaderDeviceobject.
UsingtheMXReader
InitializeaReaderDeviceobjectforMXreadersusingthefollowingfactorymethod:
caseMX:readerDevice=ReaderDevice.getMXDevice(this);
//ListenwhenaMXdevicehasbecameavailable/unavailable
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 11/37
if(!availabilityListenerStarted){readerDevice.startAvailabilityListening();availabilityListenerStarted=true;}
TheavailabilityoftheMXmobileterminalcanchangewhenthedeviceturnsonoroff,oriftheUSBcablegetsconnectedordisconnected.YoucanhandlethosechangesusingthefollowingReaderDeviceListenerinterfacemethod:
publicvoidonAvailabilityChanged(ReaderDevicereader);
UsingtheCameraReader
YouarerecommendedtouseanMXmobileterminaltoscanbarcodes.However,cmbSDKalsosupportsusingthebuilt-incameraofamobiledevice.Thisincludesthesupportofoptionalexternalaimersorillumination,andthecustomizationofthelive-streampreview'sappearance.
Toscanbarcodesusingthebuilt-incameraofamobiledevice,initializetheReaderDeviceobjectusingthegetPhoneCameraDevicestaticmethod.Thecamerareaderhasseveraloptionswheninitialized.Thefollowingparametersarerequired:
ContextCameraModePreviewOptionViewGroupRegistrationKeyCustomData
TheContextparameterprovidesareferencetotheactivityyouarecurrentlyin.
TheCameraModeparameterisoftypeCameraModedefinedinCameraMode.javaanditacceptsoneofthevalueslistedinthefollowingtable.
Thesemodesprovidethefollowingdefaultsettingsforthereader:
Thezoomfeatureisavailableandabuttontocontrolitisvisibleonthelive-streampreview(ifdisplayed).Thesimulatedhardwaretrigger(volumecontrolbuttons)isdisabled.WhenstartScanning()iscalled,thedecodingprocessisstarted.
Basedontheselectedmode,additionalilluminationoptionsandbehaviorsareset,alsolistedinthetable.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 12/37
VALUE DESCRIPT ION ILLUMINATIONLIVE-
STREAMPREVIEW
NO_AIMER
Initializesthereadertousealive-streampreviewonthemobiledevice
screensotheusercanpositionthe
barcodewithinthecamera’sfieldofviewfordetectionanddecoding.Usethismodeifthe
mobiledevicedoesnothaveanaiming
accessory.
Illuminationisavailableandabuttontocontrolitisvisibleonthelive-stream
preview.Displayed
Ifcommandsaresenttothe
readerforaimercontrol,theyare
ignored.
PASSIVE_AIMER
Initializesthereadertouseapassiveaimer.Nolive-
streampreviewisavailableonthe
devicescreeninthismode,sinceanaimingpatternis
projected.
Illuminationisnotavailable,andthelive-streampreviewdoesnothaveanilluminationbutton.
NotDisplayed
Ifcommandsaresenttothereaderforillumination
control,theyareignoredbecauseitisassumedinthismodethatthebuilt-inLEDofthemobiledeviceisbeingusedforthe
aimer.
Initializesthereadertousethefrontcameraofthe
mobiledevice,ifavailable.Usethisconfigurationwith
Thefrontcameraisused.
Illuminationisnotavailableandthe
live-stream
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 13/37
FRONT_CAMERAcarebecausemostfrontfacingcamerasdonothaveauto
focusandillumination,and
providesignificantlylowerresolution
images.Illuminationisnotavailablein
thismode.
previewdoesnothaveanilluminationbutton.
Displayed
Ifcommandsaresenttothe
readerforaimerorillumination
control,theyareignored.
ThePreviewOptionparameterisoftype PreviewOptiondefinedinPreviewOpt ion.java,andisusedtochangethereader’sdefaultvaluesoroverridedefaultsderivedfromtheselectedCameraMode.Youcanspecifythefollowingoptions:
VALUE DESCRIPT ION
DEFAULTS AcceptalldefaultssetbytheCameraMode.
NO_ZOOM_BUTTONHidesthezoombuttononthelive-stream
preview,preventingtheuserfromadjustingthezoomofthemobiledevice
camera.
NO_ILLUMINATION_BUTTONHidestheilluminationbuttononthelive-streampreview,preventingtheuserfrom
togglingtheillumination.
HARDWARE_TRIGGER
Enablesasimulatedhardwaretrigger(thevolumedownbutton)forstartingscanningonthemobiledevice.Thisbuttononly
startsscanningwhenpressed,itdoesnotneedtobeheldlikeapurpose-builtscanner’strigger,andpressingita
secondtimedoesnotstopthescanningprocess.
PAUSED
Ifusingalive-streampreview,thepreviewisdisplayedwhenthe
startScanning()methodiscalled,butthereaderdoesnotstartdecodinguntiltheuserpressestheon-screenbuttonto
startthescanningprocess.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 14/37
ALWAYS_SHOWForcesalive-streampreviewtobedisplayedevenifanaimingmodeis
selected(forexampleCameraMode==PASSIVE_AIMER).
HIGH_RESOLUTION
Usesthedevicecamerainhigherresolution,changingthedefault
1280x720resolutionto1920x1080ondevicesthatsupportit,andtothedefaultresolutionondevicesthatdonotsupport
it.Thiscanhelpwithscanningsmallbarcodes,butincreasesthedecodingtimeasthereismoredatatoprocessin
eachframe.
HIGH_FRAME_RATEUsesthedevice'scamerain60FPS
insteadofthedefault30FPStoprovideasmoothercamerapreview.
SHOW_CLOSE_BUTTON Showclosebuttoninpartialview.
TheViewGroup(optional)parameterspecifiesthecontainerforthelive-streampreview.Iftheparameterisleftnull,afullscreenpreviewisused.
TheRegistrationKey(optional)parameterisusedtolicenseyourSDKwithlicensekeythatyouhave
TheCustomData(optional)parameterisusedforcustomtracking
Example
Createareaderwithnoaimer,nozoombutton,andusingasofttrigger:
readerDevice=ReaderDevice.getPhoneCameraDevice(this,CameraMode.NO_AIMER,PreviewOption.NO_ZOOM_BUTTON|PreviewOption.PAUSED);
Thisstartsapreviewwiththescannerpausedandasofttriggerbuttontotogglescanning.Afterpressingthesofttriggerbutton,theexpectedpreviewlookisthis:
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 15/37
Theviewfinderintheimagehasanactivescanningsurfaceasaresultofhavingsetactivesymbologies.Formoredetails,seeEnablingSymbologies.
Request ingCameraPermissionforPhoneCameraScanner
FromAndroid6.0andaboveyouneedtorequestpermissionfromtheusertoaccessthebuilt-incameraofthemobiledevice.
Ifthecameracannotbeopenedduetopermissionissues,theonConnectionCompleted(readerDevice,error)callbackcontainsaCameraPermissionExceptionintheerrorparameter.YoucancheckforthisexceptiontypewiththeinstanceofoperatorandrequestpermissionwithintheActivity.
if(errorinstanceofCameraPermissionException)ActivityCompat.requestPermissions(((ScannerActivity)this),newString[]{Manifest.permission.CAMERA},REQUEST_PERMISSION_CODE);
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 16/37
YouneedtoimplementtheActivityCompat.OnRequestPermissionResultCallbackinterfaceinyourActivitytocatchtheuserpermissionresult.TohandleuserresponseinonRequestPermissionResult(…),youcanusethefollowingcodetoretryconnectingtothephonecamera:
@OverridepublicvoidonRequestPermissionsResult(intrequestCode,@NonNullString[]permissions,@NonNullint[]grantResults){//Checkresultfrompermissionrequest.Ifitisallowedbytheuser,connecttoreaderDeviceif(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.Builderbuilder=newAlertDialog.Builder(this).setMessage("YouneedtoallowaccesstotheCamera").setPositiveButton("OK",newDialogInterface.OnClickListener(){@OverridepublicvoidonClick(DialogInterfacedialogInterface,inti){ActivityCompat.requestPermissions(ScannerActivity.this,newString[]{Manifest.permission.CAMERA},REQUEST_PERMISSION_CODE);}}).setNegativeButton("Cancel",null);AlertDialogdialog=builder.create();dialog.show();}}}}
Connect ingtotheReaderDevice
Beforeconnecting,settheReaderDeviceListenerobjecttoreceiveevents:
readerDevice.setReaderDeviceListener(this);
Fordetails,seestep3inSettingupyouapplicationto-usetheCognexMobileBarcodeSDKforAndroid.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 17/37
Additionally,youcanenablesendingthelasttriggeredimageandSVGfromthereader:
readerDevice.enableImage(true);readerDevice.enableImageGraphics(true);
Invoketheconnectmethodafterinitializ ingtheReaderDeviceandsettingalistenermethodtohandleresponsesfromthereader.TheconnectmethodtakesOnConnectionCompletedListenerasparameter:
//MakesurethedeviceisturnedONandreadyreaderDevice.connect(ScannerActivity.this);
ThefollowinglistenermethodsarecalledwiththenewReaderDevicestatusinformation:
publicvoidonConnectionStateChanged(ReaderDevicereader);publicvoidonConnectionCompleted(ReaderDevicereader,Throwableerr)
TheonConnectionCompletedmethodpassedasaparameterofconnectisalsoinvokedastheconnectionprocesscompletes.Iftherewasaconnectionerror,thismethodprovidesaThrowableobject.
ScanningBarcodes
Afterconnectingtothescanningdevice,youmayneedtochangesomeofitssettings.CmbSDKprovidesasetofhigh-levelanddevice-independentAPIsforsettingandretrievingthecurrentconfigurationofthedevice.
YoucanstartscanningbarcodeswithaproperlyconfiguredreaderbycallingthestartScanningmethodfromyourReaderDeviceclass:
readerDevice.startScanning();
IfusinganMXmobileterminal,youcanpressatriggerbuttononthedevicetoturnthescanneronandreadabarcode.Ifusingthecamerareader,cmbSDKstartsthecamera,displaystheconfiguredlive-streampreview,andbeginsanalyzingtheframesfromthevideostream,lookingforaconfiguredbarcodesymbology.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 18/37
Youcanstopscanningwiththefollowing:
readerDevice.stopScanning();
Scanningstopsunderoneofthefollowingconditions:
Thereaderfoundanddecodedabarcode.Youreleasedthetriggerorpressedthestopbuttononthelive-streampreviewscreen.Thecamerareadertimedoutwithoutfindingabarcode.TheapplicationcallsthestopScanning()method.
Whenabarcodeisdecodedsuccessfully,youreceiveaReadResultsiterableresultcollectionobjectintheReaderDevicelistenermethod.TheonReadResultReceivedlistenermethodisinvokedeitherbecausethereaderdecodedabarcodeorthescanningprocesswascomplete.
Example
//Thisiscalledafterscanninghascompleted,eitherbydetectingabarcode,cancelingthescanbyusingtheon-screenbuttonorahardwaretriggerbutton,orifthescanningtimed-out@OverridepublicvoidonReadResultReceived(ReaderDevicereaderDevice,ReadResultsresults){clearResult();
if(results.getSubResults()!=null&&results.getSubResults().size()>0){for(ReadResultsubResult:results.getSubResults()){createResultItem(subResult);}}elseif(results.getCount()>0){createResultItem(results.getResultAt(0));}
isScanning=false;btnScan.setText("STARTSCANNING");resultListAdapter.notifyDataSetChanged();}
EnablingSymbologies
CmbSDKdoesnotenableanysymbologiesbydefaultforbarcodereadingwiththebuilt-incameraofthemobiledevice.Youmustenableallbarcodesymbologiesyourapplicationneedstoscantoachieveoptimalscanningperformance.Formoredetails,see
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 19/37
OptimizingMobileDevicePerformance.
IndividualsymbologiescanbeenabledusingthefollowingmethodoftheReaderDeviceclass:
publicvoidsetSymbologyEnabled(finalSymbologysymbology,finalbooleanenable,finalOnSymbologyListenerlistener)readerDevice.setSymbologyEnabled(Symbology.DATAMATRIX,true,null);readerDevice.setSymbologyEnabled(Symbology.UPC_EAN,true,null);
AllsymbologiesusedforthesymbologyparameterinthismethodcanbefoundinReaderDevice.java.
Examples
/*EnableQRscanning*/readerDevice.setSymbologyEnabled(Symbology.QR,true,null);
Youcanalsousethesamemethodtodisablesymbologies:
/*DisableCode25scanning*/readerDevice.setSymbologyEnabled(Symbology.C25,false,null);
YoucanimplementthemethodforOnSymbologiesListenertochecktheresultofthesymbologychange:
@OverridepublicvoidonSymbologyEnabled(ReaderDevicereader,Symbologysymbology,Booleanenabled,Throwableerror){if(error!=null){/*Unsuccessfulprobablythesymbologyisunsupportedbythecurrentdevice,orthereisaproblemwiththeconnectionbetweenthereaderDeviceandMXdevice*/}else{//Success}}
Illuminat ionControl
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 20/37
Ifyourreaderdeviceisequippedwithilluminationlights,youcancontrolthem:whenscanningstarts,youcanturnthemonoroff.UsethefollowingmethodofyourReaderDeviceobject:
readerDevice.setLightsOn(true,null);
YoucanimplementtheinterfacemethodforOnLightsListener,whichisthesecondparameterofthemethod.
publicclassScannerActivityextendsAppCompatActivityimplements....OnLightsListener....{....@OverridepublicvoidonLightsOnCompleted(ReaderDevicereader,Booleanon,Throwableerror){if(error!=null){//Unsuccessful}else{//Success}}}
Notalldevicesanddevicemodessupportilluminationcontrol.
CameraZoomSett ings
Ifthebuilt-incameraofamobiledeviceisusedasthereaderdevice,youcanconfigurezoomlevelsandhowtheyareused.Therearethreezoomlevels:
normal:notzoomed(100%)level1zoom(150%onAndroidbydefault)level2zoom(300%onAndroidbydefault)
TheSETCAMERA.ZOOM-PERCENT[100-MAX][100-MAX]commandisforconfiguringhowfarthetwolevelszoominpercentage.100isnotzoomedandMAX(goesupto1000)zoomsasfarasthedeviceiscapableof.Thefirstargumentisusedforsettinglevel1zoom,andthesecondforlevel2zoom.
YoucancheckthecurrentzoomsettingwiththeGETCAMERA.ZOOM-PERCENTcommand,whichreturnstwovalues:level1andlevel2zoom.
Example
readerDevice.getDataManSystem().sendCommand("SETCAMERA.ZOOM-PERCENT250500");
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 21/37
Note:ThecameraneedstobestartedwithincmbSDKatleastoncetohaveavalidmaximumzoomlevel.Itmeansthatifyousetthezoomlevelto1000andthedevicecanonlygoupto600,theGETCAMERA.ZOOM-PERCENTcommandreturns1000aslongascameraisnotopened,butitreturns600afterwards.
GET/SETCAMERA.ZOOM0-2isanothercommandthatsetsthezoomlevelorreturnstheactualsetting.PossiblevaluesfortheSETcommandare:
0-normal(notzoomed)1-level1zoom2-level2zoom
Youcancallthiscommandbeforeorevenduringscanning,andthezoomgoesuptotheconfiguredlevel.Ifscanningisfinished,thevalueisresettonormalbehavior(0).
Example
readerDevice.getDataManSystem().sendCommand("SETCAMERA.ZOOM2");
CameraOverlayCustomizat ion
Whenusingthemobiledevice'scamera,cmbSDKallowsyoutoseethecamerapreviewinsideapreviewcontainerorinfullscreen.Thispreviewalsocontainsacustomizableoverlay.ThecmbSDKcameraoverlayfeaturesbuttonsforzooming,flashingandclosingthescanner,andaprogressbarindicatingthescantimeout.
TousethelegacycameraoverlayoriginallyusedincmbSDKv2.0.xandManateeWorksSDK,usethispropertyfromMWOverlaybeforeinitializ ingthereaderDevice:
MWOverlay.overlayMode=MWOverlay.OverlayMode.OM_LEGACY;
Thecustomizationofthelegacycameraoverlayislimited,soitisrecommendedtousethecmbSDKoverlay.
WhenusingthecmbSDKoverlay:
1. CopythelayoutfilesfromtheResources/layoutdirectoryintoyourprojectandmodifythem.Usecmb_scanner_part ial_view.xmlifscanningisstartedinsideacontainer(partialview),andusecmb_scanner_view.xmlifscanningisstartedinfullscreen.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 22/37
2. Modifythelayoutaccordingtoyourneeds.Forexample,youcanchangethesizes,positionsorcoloroftheviews,removeviewsandaddyourownviews,likeanoverlayimage.
CmbSDKaccessestheviewsituses(zoom,flash,closebuttons,theviewusedfordrawinglinesonthecorners,andtheprogressbar)withtheandroid:tagattribute.Donotchangetheandroid:tagattribute,otherwisecmbSDKcannotrecognizetheviewsandcontinuestofunctionasiftheyareremoved.
BoththecmbSDKandthelegacyoverlayallowyoutochangetheimagesusedonthezoomandflashbuttonsifyourimageshavethesamenameasthenamescmbSDKuses.YoucanfindtheimagesandnamesusedincmbSDKintheResources/drawable-mdpianddrawable-hdpidirectories.Whiletheotherresolutionsareoptional,thesetwodirectoriesmustcontainyourimageswiththecorrectnamessothatcmbSDKdisplaystheproperimages.
BoththecmbSDKandthelegacyoverlayallowyoutochangethecolorandwidthoftherectanglethatisdisplayedwhenabarcodeisdetected,orthecolorandwidthoftheviewfinderrectangle.MakesuretochangecolorsaftervalidconnectiontoreaderDevice.
Example:
MWOverlay.locationLineColor=Color.YELLOW;MWOverlay.locationLineWidth=6;
MWOverlay.viewportLineColor=Color.YELLOW;MWOverlay.viewportLineWidth=6;
AdvancedConfigurat ionusingDataManControlCommands
CognexscanningdevicesimplementDataManControlCommands(DMCC)forconfiguringandcontrollingthedevice.Everyfeatureofthedevicecanbecontrolledusingthistext-basedlanguage.TheAPIprovidesamethodforsendingDMCCcommandstothedevice.Commandsexistbothforsettingandqueryingconfigurationproperties.
TheAppendixincludesthecompleteDMCCreferenceforthecamerareader.
TheDMCCsforMXmobileterminalsandothersupporteddevicescanbefoundintheirrespectivemanualsavailablethroughSetupTool.
ThefollowingexamplesshowdifferentDMCCsenttothedeviceformoreadvancedconfiguration.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 23/37
Examples
//ChangethescandirectiontoomnidirectionalreaderDevice.getDataManSystem().sendCommand("SETDECODER.1D-SYMBOLORIENTATION0",ScannerActivity.this);//Changelive-streampreview'sscanningtimeoutto10secondsreaderDevice.getDataManSystem().sendCommand("SETDECODER.MAX-SCAN-TIMEOUT10",ScannerActivity.this);
YoucanalsoinvokeDMCCquerycommandsandreceivetheirresponseintheOnResponseReceivedListener.onResponseReceived()method.
//GetthetypeofdeviceconnectedreaderDevice.getDataManSystem().sendCommand("GETDEVICE.NAME",newOnResponseReceivedListener(){@OverridepublicvoidonResponseReceived(DataManSystemdataManSystem,DmccResponsedmccResponse){if(dmccResponse.getError()!=null){//UnsuccessfulLog.e("DMCC_ERR",“GETDEVICE.NAMEfailed”,dmccResponse.getError());}else{//Success-Usethefollowingresultfields://intmResponseId=dmccResponse.getResponseId();//StringmPayLoad=dmccResponse.getPayLoad();//byte[]mBinaryData=dmccResponse.getBinaryData();}});}
Resett ingtheConfigurat ion
CmbSDKincludesamethodforresettingthedevicetoitsdefaultsettings(notthefactorydefaults).IncaseofanMXmobileterminal,thisisthesavedconfiguration.Incaseofabuilt-incamera,thesearethedefaultsidentifiedintheAppendix,wherenosymbologiesareenabled.Thismethodofresettingthedeviceisthefollowing:
readerDevice.resetConfig(null);
WhenusinganMXmobileterminal,therearethreestatesthatwecandistinguish:
FactorydefaultsSavedconfiguration:whenthereweredifferentconfigurationssetonthedeviceandCONFIG.SAVEDMCCwascalled.Sessionconfiguration:whenyoumakechangesonthesavedconfiguration,the
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 24/37
changesarevaliduntiltheMXMobileTerminalisrebooted.Ifitisrebooted,ithasthesavedconfigurationstate.
YoucanmonitorthecompletionofthisasyncmethodusingtheOnResetConfigListenerinterface,whichisanoptionalparameter.
publicclassScannerActivityextendsActivityimplements....OnResetConfigListener....{....@OverridepublicvoidonResetConfigCompleted(ReaderDevicereader,Throwableerror){if(error!=null){//Unsuccessful}else{//Success}}
WorkingwithResults
Whenabarcodeissuccessfullyread,theonReadResultReceivedmethodcreatesandreturnsaReadResultobject.Incaseofhavingmultiplebarcodessuccessfullyreadonasingleimageorframe,multipleReadResultobjectsarereturnedintheReadResultobject.
TheReadResultclasshaspropertiesdescribingtheresultofabarcoderead:
isGoodRead()(boolean):te llswhetherthereadwassuccessfulornotget ReadSt ring()(String):thedecodedbarcodeasastringget Image()(Bitmap):theimage/framethatthedecoderprocessedget ImageGraphics()(String):theboundarypathofthebarcodeasSVGdataget Xml()(String):therawXMLthatthedecoderreturnedget Symbology(Symbology):thesymbologytypeofthebarcode.ThisenumisdefinedinReaderDevice.java.
Whenascanningendswithnosuccessfulread,aReadResultisreturnedwiththegoodReadpropertysettofalse.
ToenabletheimageandimageGraphicspropertiesbeingfilledintheReadResultobject,setthecorrespondingenableImage()and/orenableImageGraphics()propertiesoftheReaderDeviceobject.
Toaccesstherawbytesfromthescannedbarcode,youcanusetheXMLproperty.ThebytesarestoredasaBase64Stringunderthe"full_string"tag.TheexampleshowshowyoucanuseanXMLparsertoextracttherawbytesfromtheXMLproperty.
Example
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 25/37
try{XmlPullParserFactoryfactory=XmlPullParserFactory.newInstance();factory.setNamespaceAware(true);XmlPullParserxpp=factory.newPullParser();
Stringtag="";
//therawbyteswillbestoredinthisvariablebyte[]bytes;
xpp.setInput(newStringReader(result.getXml()));inteventType=xpp.getEventType();while(eventType!=XmlPullParser.END_DOCUMENT){if(eventType==XmlPullParser.START_TAG){tag=xpp.getName();}elseif(eventType==XmlPullParser.TEXT&&tag.equals("full_string")){Stringbase64String=xpp.getText();//Getthebytesfromthebase64stringherebytes=Base64.decode(base64String,Base64.DEFAULT);break;}elseif(eventType==XmlPullParser.END_TAG&&tag.equals("full_string")){tag="";break;}eventType=xpp.next();}}catch(Exceptione){e.printStackTrace();}
ImageResults
TheimageandSVGresultsaredisabledbydefault,whichmeansthatwhenscanning,theReadResultsdonotcontainanydatainthecorrespondingproperties.
Toenableimageresults,invoketheenableImage()methodfromtheReaderDeviceobject:
readerDevice.enableImage(true);
ToenableSVGresults,invoketheenableImageGraphics()methodonReaderDeviceobject:
readerDevice.enableImageGraphics(true);
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 26/37
HandlingDisconnects
Ifadevicedisconnectsduetolowbatteryconditionormanualcabledisconnection,itcanbedetectedbytheonConnectionStateChanged()methodoftheReaderDeviceListenerinterface.
Note:TheonAvailabilityChanged()methodofReaderDeviceListenerisalsocalledwhenthedevicebecomesphysicallyunavailable.Itmeansthat(re)connectionisnotpossible.AlwayscheckthegetAvailability()methodoftheReaderDeviceobjectbeforetryingtocalltheconnect()method.
Appendix-DMCCfortheCameraReader
Appendix-DMCCfortheCameraReader
ThefollowingtableliststhevariousDMCCcommandssupportedbythecmbSDKwhenusingthebuilt-incameraforbarcodescanning.
ManyofthesecommandsarealsosupportedbytheMXmobileterminals.CommandsthatareuniquetothecamerareaderareindicatedassuchwithanXinthelastcolumn.
GET/SET COMMAND PARAMETER(S) DESCRIPT ION DEFAULT VALUE
GET/SET BATTERY.CHARGE Returnsthe
currentbatterylevelofthedeviceasapercentage.
BEEP Playstheaudiblebeep(tone).
Setsthenumberofbeeps(0-3)andthebeep
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 27/37
GET/SET BEEP.GOOD [0-3][0-2]
tone/pitch(0-2,forlow,medium,high).Forthebuilt-incamera,
onlyasinglebeepwithnopitchcontrolis
supported.Thus,01turnsthebeepoff,11turnsthe
beepon.
11(Turnbeepon)
GET/SET CAMERA.ZOOM 0-2
ThepossiblevaluesfortheSETcommandare:0-
normal(un-zoomed),1-
zoomatlevel1,2-zoomatlevel2.Thiszoomlevelis
usedduringscanning.Whenscanningendsit
resetto0.
GET/SET CAMERA.ZOOM-PERCENT
[100-MAX][100-MAX]
Sets/Returnslevel1zoom(default150%onAndroid,200%oniOS),
andlevel2zoom(default300%onAndroid,400%on
iOS).Note:Thecamera
needstobestartedatleastoncefromsdktohaveapropervalueformaxcapablezoom
(MAX)
GET/SET CODABAR.CODESIZE ONminmaxOFFminmax
AcceptsanylengthCodabar.Setsmin/maxlengthofacceptedCodabar.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 28/37
GET/SET C11.CHKCHAR ON|OFF TurnsCode11checkdigiton/off.
GET/SET C11.CHKCHAR-OPTION 12
Requiressinglechecksum.
Requiresdoublechecksum.
GET/SET C11.CODESIZE ONminmaxOFFminmax
AcceptsanylengthCode11.Setsmin/maxlengthof
acceptedCode11.
GET/SET C25.CODESIZE ONminmaxOFFminmax
AcceptsanylengthCode25.Setsmin/maxlengthof
acceptedCode25.
GET/SET C39.ASCII ON|OFFTurnsCode39extendedASCII
on/off.
GET/SET C39.CODESIZE ONminmaxOFFminmax
AcceptsanylengthCode39.Setsmin/maxlengthof
acceptedCode39.
GET/SET C39.CHKCHAR ON|OFF TurnsCode39checkdigiton/off
GET/SET C93.ASCII ON|OFFTurnsCode93extendedASCII
on/off
GET/SET C93.CODESIZE ONminmaxOFFminmax
AcceptsanylengthCode93.Setsmin/maxlengthof
acceptedCode93.
Setsorgetsthe
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 29/37
GET/SET COM.DMCC-HEADER 01 headeroptionusedinExtended
mode.
GET/SET COM.DMCC-RESPONSE 01DMCCresponse
format.1:Extended.
0:Silent(default)
CONFIG.DEFAULT
ResetsmostofthecameraAPI
settingstodefault,exceptthosenotedasnotresetting(seeAppendixB).Toresetallsettings,
useDEVICE.DEFAULT.
CONFIG.SAVE
Savesthecurrentconfigurationtonon-volatile
memory(MX-1xxxonly).NotethatwhenanMXpowersofforenterssleepmode,thelast
savedconfigurationis
restoredwhenthedevicewakesup.
CONFIG.RESTORE
Restoresthesaved
configurationfromnon-volatile
memory(MX-1xxxonly).
GET/SET DATA.RESULT-TYPE01248
Specifiesresultstobereturned(sumformultiple
values):0-None
1-Textstringresult(default)2-XMLresults4-XMLstats
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 30/37
8-Scanimage(seeIMAGE.*commands)
GET/SET DATABAR.EXPANDED ON|OFFTurnstheDataBar
Expandedsymbologyon/off.
GET/SET DATABAR.LIMITED ON|OFFTurnstheDataBar
Limitedsymbologyon/off.
GET/SET DATABAR.RSS14 ON|OFFTurnstheDataBarRSS14symbology
on/off.
GET/SET DATABAR.RSS14STACK ON|OFFTurnstheDataBarRSS14Stacked
symbologyon/off.
GET/SET DECODER.1D-SYMBOLORIENTATION
0123
Useomnidirectionalscanorientation.Usehorizontaland
verticalscanorientation.
Useverticalscanorientation.
Usehorizontalscanorientation.
GET/SET DECODER.EFFORT 1-5
Setstheeffortlevelforimage
analysis/decoding.Thedefaultis2.
Donotuse4-5foronlinescanning.
GET/SET DECODER.MAX-SCAN-TIMEOUT 1-120
Setsthetimeoutforthelive-streampreview.Whenthe
timeoutisreached,
decodingispaused;thelive-streampreviewwillremainon-
screen.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 31/37
GET DECODER.MAX-THREADS
ReturnsthemaxnumberofCPU
threadssupportedbythedevice.
GET/SET DECODER.THREADS-USED [0-MAX]
SpecifythemaxnumberofCPUthreadsthatthescannercanuse
duringthescanningprocess.
DEVICE.DEFAULT
Resetsthedevice(includingthecameraAPI)
settingstodefault(seeAppendixB).
GET DEVICE.FIRMWARE-VER Getsthedevicefirmwareversion.
GET DEVICE.ID
ReturnsdeviceIDassignedbyCognextothe
scanningdevice.Forabuilt-incamera,SDKreturns53.
GET/SET DEVICE.NAME
Returnsthenameassignedtothe
device.Bydefault,thisis“MX-“plusthelast6digitsofDEVICE.SERIAL-
NUMBER.
“MX-“+thelastsixdigits
DEVICE.SERIAL-
GET DEVICE.SERIAL-NUMBER
Returnstheserialnumberofthe
device.Forabuilt-incamera,theSDKassignsapseudo-random
number.
ReturnsthedevicenameassignedbyCognextothe
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 32/37
GET DEVICE.TYPE scanningdevice.Forabuilt-incamera,SDKreturns“MX-Mobile”.
GET/SET FOCUS.FOCUSTIME 0-10
Setsthecamera’sauto-focusperiod(howoftenthecamerashouldattempttorefocus).
GET/SET I2O5.CHKCHAR ON|OFFTurnsInterleaved2of5checkdigit
on/off.
GET/SET I205.CODESIZE ONminmaxOFFminmax
AcceptsanylengthInterleaved
2of5.Setsmin/maxlengthofaccepted
Interleaved2of5.
GET/SET IMAGE.FORMAT012
Scannerreturnsimageresultinbitmapformat.ScannerreturnsimageresultinJPEGformat.
ScannerreturnsimageresultinPNGformat.
GET/SET IMAGE.QUALITY 10,15,20,...90 SpecifiesJPEGimagequality.
GET/SET IMAGE.SIZE0123
Scannerreturnsfullsizeimage.Scannerreturns1/4sizeimage.Scannerreturns1/16sizeimage.Scannerreturns1/62sizeimage.
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 33/37
GET/SET LIGHT.AIMER 0-1Disables/enablestheaimer(whenthescannerstarts).
DefaultbasedoncameraMode:0:
1:PassiveAimerand
GET/SET LIGHT.AIMER-TIMEOUT 0-600 AimerTimeoutinseconds.
GET/SET LIGHT.INTERNAL-ENABLE ON|OFF
Enables/disablesillumination(when
thescannerstarts).
GET/SET MSI.CHKCHAR ON|OFF TurnsMSIPlesseycheckdigiton/off.
GET/SET MSI.CHKCHAR-OPTION
012345
Usemod10checksum
Usemod10mod10checksumUsemod11
checksum(IBMalgorithm)
Usemod11mod10checksum(IBM
algorithm)Usemod11
checksum(NCRalgorithm)
Usemod11mod10checksum(NCR
algorithm)
GET/SET MSI.CODESIZE ONminmaxOFFminmax
AcceptsanylengthMSIPlessey.
Setsmin/maxlengthof
acceptedMSIPlessey.
GET/SET SYMBOL.AZTECCODE ON|OFFTurnstheAztecCodesymbology
on/off.
GET/SET SYMBOL.CODABAR ON|OFF TurnstheCodabar
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 34/37
symbologyon/off.
GET/SET SYMBOL.C11 ON|OFF TurnstheCode11symbologyon/off.
GET/SET SYMBOL.C128 ON|OFFTurnstheCode128symbology
on/off.
GET/SET SYMBOL.C25 ON|OFFTurnstheCode25symbologyon/off
(standard).
GET/SET SYMBOL.C39 ON|OFF TurnstheCode39symbologyon/off.
GET/SET SYMBOL.C93 ON|OFF TurnstheCode93symbologyon/off.
GET/SET SYMBOL.COOP ON|OFFTurnstheCOOP
symbology(Code25variant)on/off.
GET/SET SYMBOL.DATAMATRIX ON|OFFTurnstheData
Matrixsymbologyon/off.
GET/SET SYMBOL.DATABAR ON|OFF
TurnstheDataBarExpandedand
Limitedsymbologies
on/off.
GET/SET SYMBOL.DOTCODE ON|OFF TurnstheDotCodesymbologyon/off.
GET/SET SYMBOL.IATA ON|OFFTurnstheIATA
symbology(Code25variant)on/off.
GET/SET SYMBOL.INVERTED ON|OFFTurnstheInvertedsymbology(Code25variant)on/off.
GET/SET SYMBOL.ITF14 ON|OFFTurnstheITF-14symbology(Code
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 35/37
25variant)on/off.
GET/SET SYMBOL.UPC-EAN ON|OFF
TurnstheUPC-A,UPC-E,EAN-8,and
EAN-13symbologies
on/off.
GET/SET SYMBOL.MATRIX ON|OFFTurnstheMatrixsymbology(Code25variant)on/off.
GET/SET SYMBOL.MAXICODE ON|OFFTurnstheMaxiCode
symbologyon/off.
GET/SET SYMBOL.MSI ON|OFFTurnstheMSI
Plesseysymbologyon/off.
GET/SET SYMBOL.PDF417 ON|OFF TurnsthePDF417symbologyon/off.
GET/SET SYMBOL.PLANET ON|OFF TurnsthePLANETsymbologyon/off.
GET/SET SYMBOL.POSTNET ON|OFFTurnsthePOSTNETsymbologyon/off.
GET/SET SYMBOL.4STATE-IMB ON|OFFTurnsthe
IntelligentMailBarcode
symbologyon/off.
GET/SET SYMBOL.4STATE-RMC ON|OFFTurnstheRoyalMailCode
symbologyon/off.
GET/SET SYMBOL.QR ON|OFFTurnstheQRand
MicroQRsymbologies
on/off.
012
Single(notsupported)
Presentation(notsupported)
Manual(default)
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 36/37
GET/SET TRIGGER.TYPE 345
Burst(notsupported)Self(not
supported)Continuous
GET/SET UPC-EAN.EAN13 ON|OFF TurnstheEAN-13symbologyon/off.
GET/SET UPC-EAN.EAN8 ON|OFF TurnstheEAN-8symbologyon/off.
GET/SET UPC-EAN.UPC-A ON|OFF TurnstheUPC-Asymbologyon/off.
GET/SET UPC-EAN.UPC-E ON|OFF TurnstheUPC-Esymbologyon/off.
GET/SET UPC-EAN.UPCE1 ON|OFF TurnstheUPC-E1symbologyon/off.
GET/SET UPC-EAN.SUPPLEMENT
01234
TurnsoffUPCsupplemental
codes(ignored)TurnsonUPCsupplemental
codes(required)Required2digitsupplemental.Required5digitsupplemental.Notrequired.
GET/SET VIBRATION.GOOD ON|OFFSets/getswhethertovibratewhenacodeisread(defaultisON)
Precaut ions
Precaut ions
t it le:CognexMobileBarcodeSDKforAndroid(v2.3.x);ver:2.6.x 37/37
ObservetheseprecautionswheninstallingtheCognexproduct,toreducetheriskofinjuryorequipmentdamage:
Toreducetheriskofdamageormalfunctionduetoover-voltage,linenoise,electrostaticdischarge(ESD),powersurges,orotherirregularitiesinthepowersupply,routeallcablesandwiresawayfromhigh-voltagepowersources.Changesormodificationsnotexpresslyapprovedbythepartyresponsibleforregulatorycompliancecouldvoidtheuser’sauthoritytooperatetheequipment.Cableshieldingcanbedegradedorcablescanbedamagedorwearoutmorequicklyifaservicelooporbendradiusistighterthan10Xthecablediameter.Thebendradiusmustbeginatleastsixinchesfromtheconnector.Thisdeviceshouldbeusedinaccordancewiththeinstructionsinthismanual.Allspecificationsareforreferencepurposeonlyandmaybechangedwithoutnotice.