'
'
'
'
Imports System
Imports System.Text
Imports Microsoft.VisualBasic
Imports Matrox.MatroxImagingLibrary
Module Module1
Private Const IMAGE_FILE_TO_READ As String = MIL.M_IMAGE_PATH & "ExpiryDateAndLot.mim"
Private Const FONT_FILE_TO_IMPORT As String = MIL.M_CONTEXT_PATH & "ExpiryDateAndLotFont5x7.mdmrf"
Private Const STRING_DOT_DIAMETER As Double = 6.0
Private Const STRING_BOX_WIDTH As Double = 400
Private Const STRING_BOX_HEIGHT As Double = 100
Private ReadOnly EXPIRY_DATE_LENGTH As MIL_INT = 7
Private ReadOnly LOT_NUMBER_LENGTH As MIL_INT = 7
Private Const TEXT_MAX_SIZE As Integer = 128
Sub Main()
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilImage As MIL_ID = MIL.M_NULL
Dim MilOverlay As MIL_ID = MIL.M_NULL
Dim MilDmrContext As MIL_ID = MIL.M_NULL
Dim MilDmrResult As MIL_ID = MIL.M_NULL
Dim NumberOfStrings As MIL_INT = 0
Dim StringSize As MIL_INT = 0
Dim StringModelIndex As MIL_INT = 0
Dim Index As MIL_INT = 0
Dim StringResult As New StringBuilder(TEXT_MAX_SIZE + 1)
Dim PrintText As String
Console.Write(Constants.vbLf & "DOT MATRIX READER (SureDotOCR) MODULE:" & Constants.vbLf)
Console.Write("--------------------------------------" & Constants.vbLf + Constants.vbLf)
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MbufRestore(IMAGE_FILE_TO_READ, MilSystem, MilImage)
MIL.MdispSelect(MilDisplay, MilImage)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE)
MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, MilOverlay)
MIL.MdmrAlloc(MilSystem, MIL.M_DOT_MATRIX, MIL.M_DEFAULT, MilDmrContext)
MIL.MdmrAllocResult(MilSystem, MIL.M_DOT_MATRIX, MIL.M_DEFAULT, MilDmrResult)
MIL.MdmrImportFont(FONT_FILE_TO_IMPORT, MIL.M_DMR_FONT_FILE, MilDmrContext, MIL.M_DEFAULT, MIL.M_NULL, MIL.M_DEFAULT)
MIL.MdmrControl(MilDmrContext, MIL.M_STRING_ADD, MIL.M_DEFAULT)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(0), MIL.M_DEFAULT, MIL.M_STRING_RANK, 1, MIL.M_DEFAULT, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(0), MIL.M_DEFAULT, MIL.M_STRING_SIZE_MIN_MAX, LOT_NUMBER_LENGTH, LOT_NUMBER_LENGTH, MIL.M_NULL)
MIL.MdmrControl(MilDmrContext, MIL.M_STRING_ADD, MIL.M_DEFAULT)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_DEFAULT, MIL.M_STRING_RANK, 0, MIL.M_DEFAULT, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_DEFAULT, MIL.M_STRING_SIZE_MIN_MAX, EXPIRY_DATE_LENGTH, EXPIRY_DATE_LENGTH, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_POSITION_IN_STRING(0), MIL.M_ADD_PERMITTED_CHARS_ENTRY, MIL.M_FONT_LABEL(MIL.M_ANY), MIL.M_DIGITS, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_POSITION_IN_STRING(1), MIL.M_ADD_PERMITTED_CHARS_ENTRY, MIL.M_FONT_LABEL(MIL.M_ANY), MIL.M_DIGITS, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_POSITION_IN_STRING(2), MIL.M_ADD_PERMITTED_CHARS_ENTRY, MIL.M_FONT_LABEL(MIL.M_ANY), MIL.M_LETTERS_UPPERCASE, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_POSITION_IN_STRING(3), MIL.M_ADD_PERMITTED_CHARS_ENTRY, MIL.M_FONT_LABEL(MIL.M_ANY), MIL.M_LETTERS_UPPERCASE, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_POSITION_IN_STRING(4), MIL.M_ADD_PERMITTED_CHARS_ENTRY, MIL.M_FONT_LABEL(MIL.M_ANY), MIL.M_LETTERS_UPPERCASE, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_POSITION_IN_STRING(5), MIL.M_ADD_PERMITTED_CHARS_ENTRY, MIL.M_FONT_LABEL(MIL.M_ANY), MIL.M_DIGITS, MIL.M_NULL)
MIL.MdmrControlStringModel(MilDmrContext, MIL.M_STRING_INDEX(1), MIL.M_POSITION_IN_STRING(6), MIL.M_ADD_PERMITTED_CHARS_ENTRY, MIL.M_FONT_LABEL(MIL.M_ANY), MIL.M_DIGITS, MIL.M_NULL)
Console.Write("A Dot Matrix Reader (SureDotOCR) context was set up to read" & Constants.vbLf & "an expiry date and a lot number from a target image." & Constants.vbLf + Constants.vbLf)
MIL.MdmrControl(MilDmrContext, MIL.M_DOT_DIAMETER, STRING_DOT_DIAMETER)
MIL.MdmrControl(MilDmrContext, MIL.M_STRING_BOX_WIDTH, STRING_BOX_WIDTH)
MIL.MdmrControl(MilDmrContext, MIL.M_STRING_BOX_HEIGHT, STRING_BOX_HEIGHT)
MIL.MdmrPreprocess(MilDmrContext, MIL.M_DEFAULT)
MIL.MdmrRead(MilDmrContext, MilImage, MilDmrResult, MIL.M_DEFAULT)
MIL.MdmrGetResult(MilDmrResult, MIL.M_GENERAL, MIL.M_DEFAULT, MIL.M_STRING_NUMBER + MIL.M_TYPE_MIL_INT, NumberOfStrings)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_GREEN)
MIL.MdmrDraw(MIL.M_DEFAULT, MilDmrResult, MilOverlay, MIL.M_DRAW_STRING_CHAR_BOX, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_CYAN)
MIL.MdmrDraw(MIL.M_DEFAULT, MilDmrResult, MilOverlay, MIL.M_DRAW_STRING_CHAR_POSITION, MIL.M_DEFAULT, MIL.M_DEFAULT, MIL.M_DEFAULT)
If NumberOfStrings > 0 Then
Console.Write("Result: {0} strings have been read:" & Constants.vbLf + Constants.vbLf, NumberOfStrings)
For Index = 0 To NumberOfStrings - 1
MIL.MdmrGetResult(MilDmrResult, Index, MIL.M_GENERAL, MIL.M_STRING_MODEL_INDEX + MIL.M_TYPE_MIL_INT, StringModelIndex)
MIL.MdmrGetResult(MilDmrResult, Index, MIL.M_GENERAL, MIL.M_STRING + MIL.M_STRING_SIZE + MIL.M_TYPE_MIL_INT, StringSize)
MIL.MdmrGetResult(MilDmrResult, Index, MIL.M_GENERAL, MIL.M_STRING, StringResult)
Select Case StringModelIndex
Case 0
PrintText = String.Format(" LOT# : {0} ", StringResult)
MIL.MgraText(MIL.M_DEFAULT, MilOverlay, 20, 20 + Index * 20, PrintText)
Console.Write(" LOT# : {0}" & Constants.vbLf, StringResult)
Case 1
PrintText = String.Format(" EXP. : {0} ", StringResult)
MIL.MgraText(MIL.M_DEFAULT, MilOverlay, 20, 20 + Index * 20, PrintText)
Console.Write(" EXPIRY DATE: {0}" & Constants.vbLf, StringResult)
Case Else
Console.Write("Unexpected model index" & Constants.vbLf)
End Select
Next Index
Else
Console.Write("Error: no string found." & Constants.vbLf)
End If
Console.Write(Constants.vbLf & "Press <Enter> to end." & Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MdmrFree(MilDmrContext)
MIL.MdmrFree(MilDmrResult)
MIL.MbufFree(MilImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
End Module