Imports Vintasoft.Barcode
Imports Vintasoft.Barcode.BarcodeInfo
Imports Vintasoft.Barcode.SymbologySubsets
Imports Vintasoft.Imaging
Class HIBCLICExample
''' <summary>
''' Generates and recognizes HIBC LIC 128 Primary barcode.
''' </summary>
Public Shared Sub TestHibcLic128PrimaryBarcode()
' create HIBC LIC Primary data
Dim primaryData As New HibcLicPrimaryDataStructure("A123", "BJC5D6E7", 1)
' create HIBC LIC barcode value
Dim barcodeValue As New HibcLicValueItem(primaryData)
' create barcode writer
Using writer As New BarcodeWriter()
' encode ISBT 128 Data Matrix barcode to writer settings
BarcodeSymbologySubsets.HIBCLIC128.Encode(barcodeValue, writer.Settings)
' generate barcode image
Using barcodeImage As VintasoftBitmap = writer.GetBarcodeAsVintasoftBitmap()
' recognize barcode value
Dim recognizedValue As HibcLicValueItem = Recognize(barcodeImage)
' check value
If barcodeValue.ToString() <> recognizedValue.ToString() Then
Throw New ApplicationException()
End If
' privt value
PrintValue(recognizedValue)
End Using
End Using
End Sub
''' <summary>
''' Generates and recognizes HIBC LIC 128 Secondary barcode.
''' </summary>
Public Shared Sub TestHibcLic128SecondaryBarcode()
' create HIBC LIC Secondary data
Dim secondaryData As New HibcLicSecondaryDataStructure("200116", "YYMMDD", "10X3", Nothing)
' create HIBC LIC barcode value, used lick characer 'G' - check character from primary data
Dim barcodeValue As New HibcLicValueItem(secondaryData, "G"C)
' create barcode writer
Using writer As New BarcodeWriter()
' encode ISBT 128 Data Matrix barcode to writer settings
BarcodeSymbologySubsets.HIBCLIC128.Encode(barcodeValue, writer.Settings)
' generate barcode image
Using barcodeImage As VintasoftBitmap = writer.GetBarcodeAsVintasoftBitmap()
' recognize barcode value
Dim recognizedValue As HibcLicValueItem = Recognize(barcodeImage)
' check value
If barcodeValue.ToString() <> recognizedValue.ToString() Then
Throw New ApplicationException()
End If
' privt value
PrintValue(recognizedValue)
End Using
End Using
End Sub
''' <summary>
''' Generates and recognizes HIBC LIC Data Matrix barcode.
''' </summary>
Public Shared Sub TestHibcLicDataMatrixBarcode()
' create HIBC LIC Primary data
Dim primaryData As New HibcLicPrimaryDataStructure("A123", "BJC5D6E7", 1)
' create HIBC LIC Secondary data
Dim secondaryData As New HibcLicSecondaryDataStructure("210116", "YYMMDD", "10X3", Nothing)
' Additional Supplemental Data - date of manufacture
Dim manufactureDateAdditionalData As New HibcLicManufactureDateAdditionalDataStructure(DateTime.Now)
' Additional Supplemental Data - quantity
Dim quantityAdditionalData As New HibcLicQuantityAdditionalDataStructure(100)
' Additional Supplemental Data - quantity
Dim serialNumberAdditionalData As New HibcLicSerialNumberAdditionalDataStructure("77DEFG45")
' create HIBC LIC barcode value
Dim barcodeValue As New HibcLicValueItem(primaryData, secondaryData, manufactureDateAdditionalData, serialNumberAdditionalData, quantityAdditionalData)
' create barcode writer
Using writer As New BarcodeWriter()
' encode ISBT 128 Data Matrix barcode to writer settings
BarcodeSymbologySubsets.HIBCLICDataMatrix.Encode(barcodeValue, writer.Settings)
' generate barcode image
Using barcodeImage As VintasoftBitmap = writer.GetBarcodeAsVintasoftBitmap()
' recognize barcode value
Dim recognizedValue As HibcLicValueItem = Recognize(barcodeImage)
' check value
If barcodeValue.ToString() <> recognizedValue.ToString() Then
Throw New ApplicationException()
End If
' privt value
PrintValue(recognizedValue)
End Using
End Using
End Sub
''' <summary>
''' Recognizes the HIBC LIC barcode from image.
''' </summary>
''' <param name="barcodeImage">The barcode image.</param>
Private Shared Function Recognize(barcodeImage As VintasoftBitmap) As HibcLicValueItem
' create barcode reader
Using reader As New BarcodeReader()
reader.Settings.ScanDirection = ScanDirection.Vertical Or ScanDirection.Horizontal
reader.Settings.AutomaticRecognition = True
' specify that HIBC LIC barcodes must be recognizeds
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.HIBCLIC128)
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.HIBCLIC39)
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.HIBCLICAztecCode)
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.HIBCLICDataMatrix)
reader.Settings.ScanBarcodeSubsets.Add(BarcodeSymbologySubsets.HIBCLICQRCode)
' recognize barcodes
Dim info As IBarcodeInfo = reader.ReadBarcodes(barcodeImage)(0)
' return HIBC LIC value
Return DirectCast(info, HibcLicBarcodeInfo).HibcLicValue
End Using
End Function
''' <summary>
''' Prints HIBC LIC barcode value.
''' </summary>
''' <param name="value">The recognized value.</param>
Private Shared Sub PrintValue(value As HibcLicValueItem)
' print value
Console.WriteLine("Barcode value: " & value.ToString())
If value.PrimaryDataStructure IsNot Nothing AndAlso value.SecondaryDataStructure IsNot Nothing Then
Console.WriteLine("Data structure: Primary + Secondary")
ElseIf value.PrimaryDataStructure IsNot Nothing Then
Console.WriteLine("Data structure: Primary")
Else
Console.WriteLine("Data structure: Secondary")
End If
If value.PrimaryDataStructure IsNot Nothing Then
Console.WriteLine(String.Format("LIC: {0}", value.PrimaryDataStructure.Lic))
Console.WriteLine(String.Format("Product ID: {0}", value.PrimaryDataStructure.Pcn))
Console.WriteLine(String.Format("Unit of Measure: {0}", value.PrimaryDataStructure.UnitOfMeasureID))
End If
If value.SecondaryDataStructure IsNot Nothing Then
If value.SecondaryDataStructure.ExpiryDateString IsNot Nothing Then
Console.WriteLine(String.Format("Expiry date: {0} ({1}={2})", value.SecondaryDataStructure.ExpiryDate.ToShortDateString(), value.SecondaryDataStructure.ExpiryDateStringFormat, value.SecondaryDataStructure.ExpiryDateString))
End If
If value.SecondaryDataStructure.LotNumber IsNot Nothing Then
Console.WriteLine(String.Format("Lot number: {0}", value.SecondaryDataStructure.LotNumber))
End If
If value.SecondaryDataStructure.SerialNumber IsNot Nothing Then
Console.WriteLine(String.Format("Serial number: {0}", value.SecondaryDataStructure.SerialNumber))
End If
If value.PrimaryDataStructure Is Nothing Then
Console.WriteLine(String.Format("Link character: {0}", value.LinkCharacter))
End If
End If
If value.AdditionalData IsNot Nothing Then
For Each additionalData As HibcLicAdditionalDataStructure In value.AdditionalData
If TypeOf additionalData Is HibcLicSerialNumberAdditionalDataStructure Then
Console.WriteLine(String.Format("Serial number: {0}", DirectCast(additionalData, HibcLicSerialNumberAdditionalDataStructure).SerialNumber))
End If
If TypeOf additionalData Is HibcLicManufactureDateAdditionalDataStructure Then
Console.WriteLine(String.Format("Manufacture date: {0}", DirectCast(additionalData, HibcLicManufactureDateAdditionalDataStructure).ManufactureDate.ToShortDateString()))
End If
If TypeOf additionalData Is HibcLicExpiryDateAdditionalDataStructure Then
Console.WriteLine(String.Format("Expiry date: {0}", DirectCast(additionalData, HibcLicExpiryDateAdditionalDataStructure).ExpiryDate.ToShortDateString()))
End If
If TypeOf additionalData Is HibcLicQuantityAdditionalDataStructure Then
Console.WriteLine(String.Format("Quantity: {0}", DirectCast(additionalData, HibcLicQuantityAdditionalDataStructure).Quantity))
End If
Next
End If
Console.WriteLine(String.Format("Check character: {0}", value.CheckCharacter))
End Sub
End Class