Installing the SDK
- Download the setup, unzip it and run SDTBarcodeSetupCE.exe
- Follow the Setup Wizard instructions. When asked enter your Developer licnese key or leave the field blank to activate trial license on your computer. The one-time internet connection is required during installation.
- Once setup has finished the folder C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE will contain runtime components, documentation and sample applications with sourcecode for your reference.
Reading Barcodes from C# Windows Phone 8 Application using Camera
The described below sample application sourcecodes are located in C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE\Samples\WindowsPhone\SDTBrcScannerSampleWP.
- Install the SDK.
- In MS Visual Studio 2012 Create new Windows Phone Application: New Project->Visual C#->Smart Device->Windows Mobile 6 Professional->Device Application.
- Choose Windows Phone 8 as a target platform
- Modify MainPage.xaml Grid to contain the following controls definitions:
<Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock Text="SD-TOOLKIT BARCODE SDK SAMPLE" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/> </StackPanel> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <RadioButton x:Name="rb1DBarcodes" Content="1D Barcodes" HorizontalAlignment="Left" VerticalAlignment="Top" IsChecked="True"/> <RadioButton x:Name="rbQrcode" Content="QR-Code" HorizontalAlignment="Left" Margin="0,72,0,0" VerticalAlignment="Top"/> <RadioButton x:Name="rbDatamatrix" Content="Datamatrix" HorizontalAlignment="Left" Margin="0,149,0,0" VerticalAlignment="Top"/> <Button Content="SCAN" HorizontalAlignment="Left" Margin="0,238,0,0" VerticalAlignment="Top" Width="446" Height="101" Click="Button_Click"/> <TextBlock HorizontalAlignment="Left" Margin="0,344,0,0" TextWrapping="Wrap" Text="Results:" VerticalAlignment="Top"/> <TextBox x:Name="tbResults" Height="315" Margin="0,359,10,0" TextWrapping="Wrap" IsReadOnly="True" AcceptsReturn="True" VerticalAlignment="Top"/> </Grid> </Grid>
- Add project reference to SD-TOOLKIT Barcode Scanner runtime component located in C:\Program Files (x86)\SD-Toolkit\SDTBarcodeSDKWinCE\Redistributables\WindowsPhone8\ARM folder
- Double click on Scan button in XAML editor and add the following code to Button click event handler
private void Button_Click(object sender, RoutedEventArgs e) { if (rb1DBarcodes.IsChecked.Value) { SDTBarcodeScannerPage.StartScan(this, "YOUR DEVELOPER LICENSE", SDTBarcodeEngine.SDTBARCODETYPE_ALL_1D, false, new SDTBarcodeScannerWP.SDTBarcodeScannerPage.ScanCompletedEventHandler(MainPage_OnScanCompleted)); } else if (rbQrcode.IsChecked.Value) { SDTBarcodeScannerPage.StartScan(this, "YOUR DEVELOPER LICENSE", SDTBarcodeEngine.SDTBARCODETYPE_QRCODE, false, new SDTBarcodeScannerWP.SDTBarcodeScannerPage.ScanCompletedEventHandler(MainPage_OnScanCompleted)); } else if (rbDatamatrix.IsChecked.Value) { SDTBarcodeScannerPage.StartScan(this, "YOUR DEVELOPER LICENSE", SDTBarcodeEngine.SDTBARCODETYPE_DATAMATRIX, false, new SDTBarcodeScannerWP.SDTBarcodeScannerPage.ScanCompletedEventHandler(MainPage_OnScanCompleted)); } }
-
In MainPage.xaml.cs file and the following method to MainPage. This method will be called by SDTBarcodeScanner each time new barcode symbol will be recognized. Set ScanCompletedEventArgs property CanCloseScanner to true to close the Camera preview:
void MainPage_OnScanCompleted(object sender, ScanCompletedEventArgs e) { tbResults.Text = ""; for (int i = 0; i < e.Barcodes.Count; i++) { tbResults.Text += "[" + e.Barcodes[i].TypeName + "] " + e.Barcodes[i].ValueAsString; } e.CanCloseScanner = true; }
- Build and run the application on the Windows phone 8 device. When pressing Scan button you should be able to see camera preview.
Reading Barcodes from C# Windows Mobile Application
The described below sample application sourcecodes are located in C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE\Samples\SDTBarcodeARM.Net.Sample.
- Install the SDK.
- In MS Visual Studio Create new Device Application: New Project->Visual C#->Smart Device->Windows Mobile 6 Professional->Device Application.
- In form design view add button. Set Name property to buttonReadFile and Text property to Read File
- In form design view add button. Set Name property to buttonCaptureFromCamera and Text property to Capture From Camera
- In form design view add TextBox. Set Name property to textBoxResults. We will use it for showing recognition results.
- In the solution explorer click right mouse button on Project References and choose Add Reference... Point reference to the SDTBarcodeARM.Net.dll assembly.
- In form design view add openFileDialog.
- In form design view double click on the buttonReadFile button. It will add OnButtonClick event handler for button openFile. Modify the buttonReadFile_Click handler to be the following:
private void buttonReadFile_Click(object sender, EventArgs e) { textBoxResults.Text = ""; if (this.openFileDialog.ShowDialog() == DialogResult.OK) { using (SDTBarcodeEngine engine = new SDTBarcodeEngine("YOUR DEVELOPER LICENSE")) { engine.SetReadInputTypes(SDTBarcodeEngine.SDTBARCODETYPE_ALL_1D); engine.SetReadInputDirections(SDTBarcodeEngine.SDTREADDIRECTION_LTR | SDTBarcodeEngine.SDTREADDIRECTION_RTL); string filePath = openFileDialog.FileName; engine.ReadImageFile(filePath, 0); for (int resultIdx = 0; resultIdx < engine.GetResultsCount(); resultIdx++) { string value = engine.GetResultValue(resultIdx); textBoxResults.Text += value; textBoxResults.Text += "\r\n"; } } } }
- In form design view double click on the buttonCaptureFromCamera button. It will add OnButtonClick event handler for button openFile. Modify the buttonCaptureFromCamera_Click handler to be the following:
private void buttonCaptureFromCamera_Click(object sender, EventArgs e) { textBoxResults.Text = ""; using (SDTBarcodeEngine engine = new SDTBarcodeEngine("YOUR DEVELOPER LICENSE")) { engine.SetReadInputTypes(SDTBarcodeEngine.SDTBARCODETYPE_ALL_1D); engine.SetReadInputDirections(SDTBarcodeEngine.SDTREADDIRECTION_LTR | SDTBarcodeEngine.SDTREADDIRECTION_RTL); if (engine.ReadStillImageFromCamera(1280, 720, "Capture barcode") == 0) { for (int resultIdx = 0; resultIdx < engine.GetResultsCount(); resultIdx++) { string value = engine.GetResultValue(resultIdx); textBoxResults.Text += value; textBoxResults.Text += "\r\n"; } } } }
- Modify Windows CE Emulator properties to map Shared Folder to C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE\Images folder. It will reflect sample barcode images included in the SDK.
- Build and run the application in on attached device or emulator. Note that capture from camera functionality might not work on emulator.
Reading Barcodes from C++ Windows Mobile Application
The described below sample application source codes are located in C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE\Samples\SDTBarcodeSampleARMCpp.
- Install the SDK.
- In MS Visual Studio Create new Windows CE Project: Visual C++ -> Smart Device -> MFC Smart Device Application.
- Select platform SDKs to be added to current project
- Choose Application type: Dialog Based
- In resource editor modify main application dialog. Add new Button control. Set ID property, to IDC_BUTTON_OPEN_FILE.
- Add new EditBox control. Set ID to IDC_EDIT_RESULTS
- Click right mouse button on EditBox control and choose Add Variable. Set variable category: Value. Variable name: mResults
- Modify newelly created project properties to refer to the SDTBarcode header file and library.
C/C++ -> General-> Additional Include Directories: C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE\Include
Linker -> Input ->Additional Dependencies: SDTBarcode.lib
Linker -> General ->Additional Library Directories: C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE\lib\armv4 or C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE\lib\armv4 i
- Select Button. In properties go to Events tab and add Handler for BN_CLICKED command: OnBnClickedButtonOpenFile
- Inside OnBnClickedButtonOpenFile() method initialize BarcodeEngine passing your purchased developer license as a parameter.
void* pReader = SDTCreateBarcodeReaderW(L"your developer license");
- Read the image file
SDTReadImageFileW(pReader, L"\\Storage Card\\Ean13.jpg", 0);
- Show results in EditBox
CString l_sResult; for(int resultIdx = 0; resultIdx < SDTGetResultsCount(engine); resultIdx++) { LPCWSTR l_wsValue = SDTGetResultValueW(engine, resultIdx); l_sResult.Append(l_wsValue); l_sResult.Append(_T("\r\n")); } mResults.Format(_T("%s"), l_sResult); UpdateData(FALSE);
- Destroy Barcode Endine
SDTDestroyBarcodeReader(pReader); pReader = NULL;
- Modify Project Properties->Deployment->Additional Files to be: SDTBarcode.dll|X:\Out\DebugArmv4\|%CSIDL_PROGRAM_FILES%\SDTBarcodeARM.Sample.Cpp\|0
- Modify Windows CE Emulator properties to map Shared Folder to C:\Program Files\SD-Toolkit\SDTBarcodeSDKWinCE\Images folder. It will reflect sample barcode images included in the SDK.
- Build and run the application in on attached device or emulator.