1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| #include "tisgrabber.h"
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <Windows.h>
#include <tchar.h>
int main ()
{
char jpgfile[256];
int i,nbi;
HGRABBER hGrabber;
COLORFORMAT format;
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
OVERLAPPED o;
DWORD dwEvtMask;
DWORD ModemStat;
TCHAR *pcCommPort = TEXT("COM1");
clock_t t0, t01, t02, t1, t2,tmin=1000,tmax=0;
nbi=50;
// Initialize the DCB structure.
//SecureZeroMemory(&dcb, sizeof(DCB));
dcb.DCBlength = sizeof(DCB);
hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // default security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL ); // hTemplate must be NULL for comm devices
if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}
fSuccess = GetCommState(hCom, &dcb);
if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}
dcb.BaudRate = 4800; // baud rate
dcb.ByteSize = 8; // data size, xmit and rcv
dcb.Parity = NOPARITY; // parity bit
dcb.StopBits = ONESTOPBIT; // stop bit
dcb.fRtsControl = RTS_CONTROL_ENABLE; //RTS enabled
fSuccess = SetCommState(hCom, &dcb);
if (!fSuccess)
{
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (2);
}
// Set the event mask.
fSuccess = SetCommMask(hCom, EV_CTS);
if (!fSuccess)
{
// Handle the error.
printf("SetCommMask failed with error %d.\n", GetLastError());
return(3);
}
// Create an event object for use by WaitCommEvent.
o.hEvent = CreateEvent(
NULL, // default security attributes
TRUE, // manual-reset event
FALSE, // not signaled
NULL // no name
);
// Initialize the rest of the OVERLAPPED structure to zero.
o.Internal = 0;
o.InternalHigh = 0;
o.Offset = 0;
o.OffsetHigh = 0;
t0 = clock();
if( IC_InitLibrary(0) == IC_SUCCESS )
{
printf ("InitLibrary OK !\n");
hGrabber = IC_CreateGrabber();
if( hGrabber )
{
printf ("CreateGrabber OK !\n");
if( IC_OpenVideoCaptureDevice(hGrabber,"DFx 41AU02.AS") == IC_SUCCESS )
{
printf ("device open !\n");
IC_ShowPropertyDialog (hGrabber) ;
format = IC_GetFormat (hGrabber) ;
printf ("current format = %d\n",(int)format);
format = RGB24;
printf ("new format = %d\n",(int)format);
if(IC_SetFormat (hGrabber,format)==IC_SUCCESS)
{
printf ("SetFormat OK\n");
if(IC_PrepareLive (hGrabber,0)==IC_SUCCESS)
{
printf ("PrepareLive OK\n");
if(IC_StartLive (hGrabber,0)==IC_SUCCESS)
{
printf ("StartLive OK\n");
t01 = clock();
i=1;
while (i<nbi)
{
retry: if (WaitCommEvent(hCom, &dwEvtMask, &o))
{
if (dwEvtMask & EV_CTS)
{
GetCommModemStatus(hCom,&ModemStat);
if (ModemStat == MS_CTS_ON)
goto retry;
}
}
else
{
DWORD dwRet = GetLastError();
if ( ERROR_IO_PENDING == dwRet)
printf("I/O is pending...\n");
else
printf("Wait failed with error %d.\n", GetLastError());
return(1);
}
t1 = clock();
if (IC_SnapImage (hGrabber,1000)==IC_SUCCESS)
{
printf ("SnapImage OK\n");
sprintf(jpgfile, "C:\\testcamera%d.jpg", i);
if (IC_SaveImage (hGrabber,jpgfile,FILETYPE_JPEG,50) == IC_SUCCESS)
printf ("SaveImage OK %d\n",i);
else
{
printf ("SaveImage NOK\n");
return(1);
}
}
else
{
printf ("SnapImage NOK\n");
return(1);
}
t2 = clock();
if ((t2-t1)>tmax) tmax=t2-t1;
if ((t2-t1)<tmin) tmin=t2-t1;
i++;
}
t02 = clock();
printf("max duration per picture =%f\n",(float) tmax/CLOCKS_PER_SEC);
printf("min duration per picture =%f\n",(float) tmin/CLOCKS_PER_SEC);
printf("mean duration per picture =%f\n",(float) (t02-t01)/(nbi*CLOCKS_PER_SEC));
}
else printf ("StartLive NOK\n");
}
else printf ("PrepareLive NOK\n");
}
else printf ("SetFormat NOK\n");
IC_CloseVideoCaptureDevice( hGrabber );
}
else printf ("device not open !\n");
IC_ReleaseGrabber( &hGrabber );
}
else printf ("hGrabber not created !\n");
IC_CloseLibrary();
}
return 0;
} |
Partager