#include <mil.h>
#if M_MIL_USE_WINDOWS
#include <Windows.h>
#endif
#define BUFFERING_SIZE_MAX 20
typedef struct
{
MIL_ID MilImageDisp;
MIL_INT ProcessedImageCount;
MIL_INT CorruptImageCount;
} HookDataStruct;
void PrintCameraInfo(MIL_ID MilDigitizer);
MIL_INT MFTYPE ProcessingFunction(MIL_INT HookType,
MIL_ID HookId,
void* HookDataPtr);
int MosMain(void)
{
MIL_ID MilApplication;
MIL_ID MilSystem ;
MIL_ID MilDigitizer;
MIL_ID MilDisplay;
MIL_ID MilImageDisp;
MIL_ID MilGrabBufferList[BUFFERING_SIZE_MAX];
MIL_INT MilGrabBufferListSize;
MIL_INT ProcessFrameCount = 0;
MIL_INT DigProcessInProgress = M_FALSE;
MIL_INT SystemType = 0;
MIL_DOUBLE ProcessFrameRate = 0;
MIL_INT64 SourceDataFormat;
HookDataStruct UserHookData;
MIL_INT n = 0;
MappAllocDefault(M_DEFAULT, &MilApplication, &MilSystem, M_NULL, M_NULL, M_NULL);
MsysInquire(MilSystem, M_SYSTEM_TYPE, &SystemType);
if(SystemType != M_SYSTEM_GIGE_VISION_TYPE)
{
MosPrintf(MIL_TEXT("This example requires a M_GIGE_VISION system type.\n"));
MosPrintf(MIL_TEXT("Please change system type in milconfig.\n"));
MappFreeDefault(MilApplication, MilSystem, M_NULL, M_NULL, M_NULL);
return 0;
}
MdigAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_GC_MULTICAST_MASTER,
&MilDigitizer);
MdispAlloc(MilSystem, M_DEFAULT, MIL_TEXT("M_DEFAULT"), M_DEFAULT, &MilDisplay);
MdigInquire(MilDigitizer, M_SOURCE_DATA_FORMAT, &SourceDataFormat);
MbufAllocColor(MilSystem,
MdigInquire(MilDigitizer, M_SIZE_BAND, M_NULL),
MdigInquire(MilDigitizer, M_SIZE_X, M_NULL),
MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL),
MdigInquire(MilDigitizer, M_TYPE, M_NULL),
M_IMAGE+M_DISP+M_GRAB+M_PROC+SourceDataFormat,
&MilImageDisp);
MbufClear(MilImageDisp, M_COLOR_BLACK);
MdispSelect(MilDisplay, MilImageDisp);
MappControl(M_DEFAULT, M_ERROR, M_PRINT_DISABLE);
for(MilGrabBufferListSize = 0;
MilGrabBufferListSize<BUFFERING_SIZE_MAX; MilGrabBufferListSize++)
{
MbufAllocColor(MilSystem,
MdigInquire(MilDigitizer, M_SIZE_BAND, M_NULL),
MdigInquire(MilDigitizer, M_SIZE_X, M_NULL),
MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL),
MdigInquire(MilDigitizer, M_TYPE, M_NULL),
M_IMAGE+M_GRAB+M_PROC+SourceDataFormat,
&MilGrabBufferList[MilGrabBufferListSize]);
if (MilGrabBufferList[MilGrabBufferListSize])
{
MbufClear(MilGrabBufferList[MilGrabBufferListSize], M_COLOR_WHITE);
}
else
break;
}
MappControl(M_DEFAULT, M_ERROR, M_PRINT_ENABLE);
MosPrintf(MIL_TEXT("This example demonstrates the use of IP Multicast with GigE Vision"));
MosPrintf(MIL_TEXT(" devices.\n"));
MosPrintf(MIL_TEXT("It allocates a Multicast master digitizer that can read, write and"));
MosPrintf(MIL_TEXT(" grab from\n"));
MosPrintf(MIL_TEXT("a GigE Vision device.\n\n"));
MosPrintf(MIL_TEXT("This example must be used along with MulticastSlave.cpp connected to"));
MosPrintf(MIL_TEXT(" the same\n"));
MosPrintf(MIL_TEXT("GigE Vision device and running on another PC.\n\n"));
MosPrintf(MIL_TEXT("Press <Enter> to continue."));
MosGetch();
PrintCameraInfo(MilDigitizer);
UserHookData.MilImageDisp = MilImageDisp;
UserHookData.ProcessedImageCount = 0;
UserHookData.CorruptImageCount = 0;
MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize,
M_START, M_DEFAULT, ProcessingFunction, &UserHookData);
MosPrintf(MIL_TEXT("If the MulticastSlave program is already running on the other PC, it"));
MosPrintf(MIL_TEXT(" should\n"));
MosPrintf(MIL_TEXT("have detected that this device is controlled by a multicast master"));
MosPrintf(MIL_TEXT(" digitizer\n"));
MosPrintf(MIL_TEXT("and have started image acquisition.\n\n"));
MosPrintf(MIL_TEXT("If the MulticastSlave program is not yet started then it should be"));
MosPrintf(MIL_TEXT(" started now.\n"));
MosPrintf(MIL_TEXT("\nPress <Enter> to stop.\n"));
MosGetch();
MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize,
M_STOP, M_DEFAULT, ProcessingFunction, &UserHookData);
MdigInquire(MilDigitizer, M_PROCESS_FRAME_COUNT, &ProcessFrameCount);
MdigInquire(MilDigitizer, M_PROCESS_FRAME_RATE, &ProcessFrameRate);
MosPrintf(MIL_TEXT("\n\n%lld frames grabbed at %.1f frames/sec (%.1f ms/frame).\n"),
(long long)ProcessFrameCount, ProcessFrameRate, 1000.0/ProcessFrameRate);
MosPrintf(MIL_TEXT("Press <Enter> to end.\n\n"));
MosGetch();
while(MilGrabBufferListSize > 0)
MbufFree(MilGrabBufferList[--MilGrabBufferListSize]);
MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp);
return 0;
}
void PrintCameraInfo(MIL_ID MilDigitizer)
{
MIL_STRING DeviceVendor;
MIL_STRING DeviceModel;
MIL_STRING PixelFormat;
MIL_INT64 Width = 0, Height = 0;
MIL_INT Port = 0;
MIL_STRING MulticastAddress;
#if M_MIL_USE_WINDOWS
system("cls");
#endif
MdigInquire(MilDigitizer, M_CAMERA_VENDOR, DeviceVendor);
MdigInquire(MilDigitizer, M_CAMERA_MODEL, DeviceModel);
MdigInquireFeature(MilDigitizer, M_FEATURE_VALUE, MIL_TEXT("PixelFormat"), M_TYPE_STRING, PixelFormat);
MdigInquireFeature(MilDigitizer, M_FEATURE_VALUE, MIL_TEXT("Width"), M_TYPE_INT64, &Width);
MdigInquireFeature(MilDigitizer, M_FEATURE_VALUE, MIL_TEXT("Height"), M_TYPE_INT64, &Height);
MdigInquire(MilDigitizer, M_GC_STREAM_CHANNEL_MULTICAST_ADDRESS_STRING, MulticastAddress);
MdigInquire(MilDigitizer, M_GC_LOCAL_STREAM_PORT, &Port);
MosPrintf(MIL_TEXT("\n--------------------- Master digitizer connection status. "));
MosPrintf(MIL_TEXT("---------------------\n\n"));
MosPrintf(MIL_TEXT("Connected to %s %s\n"), DeviceVendor.c_str(), DeviceModel.c_str());
MosPrintf(MIL_TEXT("Device pixel format: %s\n"), PixelFormat.c_str());
MosPrintf(MIL_TEXT("Device AOI: %lld x %lld\n"), (long long)Width, (long long)Height);
MosPrintf(MIL_TEXT("IPv4 Multicast address: %s\n"), MulticastAddress.c_str());
MosPrintf(MIL_TEXT("Stream port: %lld\n\n"), (long long)Port);
}
#define STRING_LENGTH_MAX 20
#define STRING_POS_X 20
#define STRING_POS_Y 20
MIL_INT MFTYPE ProcessingFunction(MIL_INT HookType,
MIL_ID HookId,
void* HookDataPtr)
{
HookDataStruct *UserHookDataPtr = (HookDataStruct *)HookDataPtr;
MIL_ID ModifiedBufferId;
MIL_TEXT_CHAR Text[STRING_LENGTH_MAX]= {MIL_TEXT('\0'),};
MIL_INT IsFrameCorrupt = M_FALSE;
MdigGetHookInfo(HookId, M_MODIFIED_BUFFER+M_BUFFER_ID, &ModifiedBufferId);
MdigGetHookInfo(HookId, M_CORRUPTED_FRAME, &IsFrameCorrupt);
UserHookDataPtr->ProcessedImageCount++;
if(IsFrameCorrupt)
UserHookDataPtr->CorruptImageCount++;
MosSprintf(Text, STRING_LENGTH_MAX, MIL_TEXT("%lld"),
(long long)UserHookDataPtr->ProcessedImageCount);
MgraText(M_DEFAULT, ModifiedBufferId, STRING_POS_X, STRING_POS_Y, Text);
MbufCopy(ModifiedBufferId, UserHookDataPtr->MilImageDisp);
return 0;
}