#include <mil.h>
#define IMAGE_FILE M_IMAGE_PATH MIL_TEXT("Code.mim")
#define BARCODE_REGION_TOP_LEFT_X 256L
#define BARCODE_REGION_TOP_LEFT_Y 80L
#define BARCODE_REGION_SIZE_X 290L
#define BARCODE_REGION_SIZE_Y 60L
#define DATAMATRIX_REGION_TOP_LEFT_X 8L
#define DATAMATRIX_REGION_TOP_LEFT_Y 312L
#define DATAMATRIX_REGION_SIZE_X 118L
#define DATAMATRIX_REGION_SIZE_Y 105L
#define STRING_LENGTH_MAX 64L
int MosMain(void)
{
MIL_ID MilApplication,
MilSystem,
MilDisplay,
MilImage,
MilOverlayImage,
DataMatrixRegion,
DataMatrixCode,
BarCodeRegion,
Barcode,
CodeResults;
MIL_INT BarcodeStatus;
MIL_INT DataMatrixStatus;
MIL_DOUBLE AnnotationColor = M_COLOR_GREEN, AnnotationBackColor = M_COLOR_GRAY;
MIL_INT n;
MIL_TEXT_CHAR OutputString [STRING_LENGTH_MAX];
MIL_TEXT_CHAR BarcodeString [STRING_LENGTH_MAX];
MIL_TEXT_CHAR DataMatrixString[STRING_LENGTH_MAX];
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, &MilDisplay, M_NULL, M_NULL);
MbufRestore(IMAGE_FILE, MilSystem, &MilImage);
MdispSelect(MilDisplay, MilImage);
MdispControl(MilDisplay, M_OVERLAY, M_ENABLE);
MdispInquire(MilDisplay, M_OVERLAY_ID, &MilOverlayImage);
McodeAllocResult(MilSystem, M_DEFAULT, &CodeResults);
MosPrintf(MIL_TEXT("\n1D and 2D CODE READING:\n"));
MosPrintf(MIL_TEXT("-----------------------\n\n"));
MosPrintf(MIL_TEXT("This program will decode a linear Code 39 and a DataMatrix code.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue.\n\n"));
MosGetch();
MbufChild2d(MilImage, BARCODE_REGION_TOP_LEFT_X, BARCODE_REGION_TOP_LEFT_Y,
BARCODE_REGION_SIZE_X, BARCODE_REGION_SIZE_Y, &BarCodeRegion);
McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, &Barcode);
McodeModel(Barcode, M_ADD, M_CODE39, M_NULL, M_DEFAULT, M_NULL);
McodeRead(Barcode, BarCodeRegion, CodeResults);
McodeGetResult(CodeResults, M_STATUS+M_TYPE_MIL_INT, &BarcodeStatus);
if (BarcodeStatus == M_STATUS_READ_OK)
{
McodeGetResult(CodeResults, M_STRING, BarcodeString);
MgraColor(M_DEFAULT, AnnotationColor);
MgraBackColor(M_DEFAULT, AnnotationBackColor);
MosSprintf(OutputString, STRING_LENGTH_MAX, MIL_TEXT("\"%s\""), BarcodeString);
MgraText(M_DEFAULT, MilOverlayImage, BARCODE_REGION_TOP_LEFT_X+10,
BARCODE_REGION_TOP_LEFT_Y+80, MIL_TEXT(" 1D linear 39 bar code: "));
MgraText(M_DEFAULT, MilOverlayImage, BARCODE_REGION_TOP_LEFT_X+200,
BARCODE_REGION_TOP_LEFT_Y+80, OutputString);
MgraRect(M_DEFAULT, MilOverlayImage,
BARCODE_REGION_TOP_LEFT_X, BARCODE_REGION_TOP_LEFT_Y,
BARCODE_REGION_TOP_LEFT_X+BARCODE_REGION_SIZE_X,
BARCODE_REGION_TOP_LEFT_Y+BARCODE_REGION_SIZE_Y);
}
McodeFree(Barcode);
MbufFree(BarCodeRegion);
MbufChild2d(MilImage, DATAMATRIX_REGION_TOP_LEFT_X, DATAMATRIX_REGION_TOP_LEFT_Y,
DATAMATRIX_REGION_SIZE_X, DATAMATRIX_REGION_SIZE_Y, &DataMatrixRegion);
McodeAlloc(MilSystem, M_DEFAULT, M_DEFAULT, &DataMatrixCode);
McodeModel(DataMatrixCode, M_ADD, M_DATAMATRIX, M_NULL, M_DEFAULT, M_NULL);
McodeControl(DataMatrixCode, M_FOREGROUND_VALUE, M_FOREGROUND_WHITE);
McodeRead(DataMatrixCode, DataMatrixRegion, CodeResults);
McodeGetResult(CodeResults, M_STATUS + M_TYPE_MIL_INT, &DataMatrixStatus);
if (DataMatrixStatus == M_STATUS_READ_OK)
{
McodeGetResult(CodeResults, M_STRING, DataMatrixString);
MgraColor(M_DEFAULT, AnnotationColor);
MgraBackColor(M_DEFAULT, AnnotationBackColor);
for (n=0; DataMatrixString[n] != MIL_TEXT('\0'); n++)
if ((DataMatrixString[n] < MIL_TEXT('0')) || (DataMatrixString[n] > MIL_TEXT('Z')))
DataMatrixString[n] = MIL_TEXT(' ');
MosSprintf(OutputString, STRING_LENGTH_MAX, MIL_TEXT("\"%s\" "), DataMatrixString);
MgraText(M_DEFAULT,
MilOverlayImage,
DATAMATRIX_REGION_TOP_LEFT_X,
DATAMATRIX_REGION_TOP_LEFT_Y+120,
MIL_TEXT(" 2D Data Matrix code: "));
MgraText(M_DEFAULT, MilOverlayImage, DATAMATRIX_REGION_TOP_LEFT_X+200,
DATAMATRIX_REGION_TOP_LEFT_Y+120, OutputString);
MgraRect(M_DEFAULT, MilOverlayImage,
DATAMATRIX_REGION_TOP_LEFT_X, DATAMATRIX_REGION_TOP_LEFT_Y,
DATAMATRIX_REGION_TOP_LEFT_X+DATAMATRIX_REGION_SIZE_X,
DATAMATRIX_REGION_TOP_LEFT_Y+DATAMATRIX_REGION_SIZE_Y);
}
McodeFree(DataMatrixCode);
MbufFree(DataMatrixRegion);
McodeFree(CodeResults);
if ( (DataMatrixStatus == M_STATUS_READ_OK) && (BarcodeStatus == M_STATUS_READ_OK) )
MosPrintf(MIL_TEXT("Decoding was successful and the strings were ")
MIL_TEXT("written under each code.\n"));
else
MosPrintf(MIL_TEXT("Decoding error found.\n"));
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
MbufFree(MilImage);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, M_NULL, M_NULL);
return 0;
}