1 | //==========================================================================//
|
---|
2 | // //
|
---|
3 | // C# - Interfaceclass for uEye_tools //
|
---|
4 | // //
|
---|
5 | // Copyright (C) 2005 -2010 //
|
---|
6 | // IDS - Imaging Development Systems GmbH //
|
---|
7 | // Dimbacherstr. 6-8 //
|
---|
8 | // D-74182 Obersulm-Willsbach //
|
---|
9 | // //
|
---|
10 | // The information in this document is subject to change without //
|
---|
11 | // notice and should not be construed as a commitment by IDS Imaging GmbH. //
|
---|
12 | // IDS Imaging GmbH does not assume any responsibility for any errors //
|
---|
13 | // that may appear in this document. //
|
---|
14 | // //
|
---|
15 | // This document, or source code, is provided solely as an example //
|
---|
16 | // of how to utilize IDS software libraries in a sample application. //
|
---|
17 | // IDS Imaging GmbH does not assume any responsibility for the use or //
|
---|
18 | // reliability of any portion of this document or the described software. //
|
---|
19 | // //
|
---|
20 | // General permission to copy or modify, but not for profit, is hereby //
|
---|
21 | // granted, provided that the above copyright notice is included and //
|
---|
22 | // included and reference made to the fact that reproduction privileges //
|
---|
23 | // were granted by IDS Imaging GmbH. //
|
---|
24 | // //
|
---|
25 | // IDS cannot assume any responsibility for the use, or misuse, of any //
|
---|
26 | // portion or misuse, of any portion of this software for other than its //
|
---|
27 | // intended diagnostic purpose in calibrating and testing IDS manufactured //
|
---|
28 | // image processing boards and software. //
|
---|
29 | // //
|
---|
30 | //==========================================================================//
|
---|
31 |
|
---|
32 |
|
---|
33 | using System;
|
---|
34 | using System.Runtime.InteropServices;
|
---|
35 |
|
---|
36 |
|
---|
37 | using System.Drawing;
|
---|
38 | using System.Collections;
|
---|
39 | using System.ComponentModel;
|
---|
40 | using System.Windows.Forms;
|
---|
41 | using System.Data;
|
---|
42 | using System.Text;
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 | /// <summary>
|
---|
47 | /// Zusammenfassung für uEye_tools.
|
---|
48 | /// </summary>
|
---|
49 | public class uEye_tools
|
---|
50 | {
|
---|
51 |
|
---|
52 | // ----------------------------------------Driver name-----------------------------------------
|
---|
53 | //
|
---|
54 | public const string DRIVER_DLL_NAME = "ueye_tools.dll";
|
---|
55 |
|
---|
56 |
|
---|
57 | // ----------------------------------------Color modes-----------------------------------------
|
---|
58 | //
|
---|
59 | public const Int32 IS_AVI_CM_RGB32 = 0; // RGB32
|
---|
60 | public const Int32 IS_AVI_CM_RGB24 = 1; // RGB24
|
---|
61 | public const Int32 IS_AVI_CM_Y8 = 6; // Y8
|
---|
62 | public const Int32 IS_AVI_CM_BAYER = 11; // Bayer
|
---|
63 |
|
---|
64 | // ----------------------------------------Events-----------------------------------------
|
---|
65 | //
|
---|
66 | public const Int32 IS_AVI_SET_EVENT_FRAME_SAVED = 1;
|
---|
67 |
|
---|
68 | // **********************************************
|
---|
69 | // return values/error codes
|
---|
70 | // **********************************************
|
---|
71 |
|
---|
72 | public const Int32 IS_AVI_NO_ERR = 0 ;
|
---|
73 | public const Int32 IS_AVI_ERR_INVALID_FILE = 301 ;
|
---|
74 | public const Int32 IS_AVI_ERR_NEW_FAILED = 302 ;
|
---|
75 | public const Int32 IS_AVI_ERR_CREATESTREAM = 303 ;
|
---|
76 | public const Int32 IS_AVI_ERR_PARAMETER = 304 ;
|
---|
77 | public const Int32 IS_AVI_ERR_NO_CODEC_AVAIL = 305 ;
|
---|
78 | public const Int32 IS_AVI_ERR_INVALID_ID = 306 ;
|
---|
79 | public const Int32 IS_AVI_ERR_COMPRESS = 307 ;
|
---|
80 | public const Int32 IS_AVI_ERR_DECOMPRESS = 308 ;
|
---|
81 | public const Int32 IS_AVI_ERR_CAPTURE_RUNNING = 309 ;
|
---|
82 | public const Int32 IS_AVI_ERR_CAPTURE_NOT_RUNNING = 310 ;
|
---|
83 | public const Int32 IS_AVI_ERR_PLAY_RUNNING = 311 ;
|
---|
84 | public const Int32 IS_AVI_ERR_PLAY_NOT_RUNNING = 312 ;
|
---|
85 | public const Int32 IS_AVI_ERR_WRITE_INFO = 313 ;
|
---|
86 | public const Int32 IS_AVI_ERR_INVALID_VALUE = 314 ;
|
---|
87 | public const Int32 IS_AVI_ERR_ALLOC_MEMORY = 315 ;
|
---|
88 | public const Int32 IS_AVI_ERR_INVALID_CM = 316 ;
|
---|
89 | public const Int32 IS_AVI_ERR_COMPRESSION_RUN = 317 ;
|
---|
90 | public const Int32 IS_AVI_ERR_INVALID_SIZE = 318 ;
|
---|
91 | public const Int32 IS_AVI_ERR_INVALID_POSITION = 319 ;
|
---|
92 | public const Int32 IS_AVI_ERR_INVALID_UEYE = 320 ;
|
---|
93 | public const Int32 IS_AVI_ERR_EVENT_FAILED = 321 ;
|
---|
94 |
|
---|
95 |
|
---|
96 | // ***********************************************
|
---|
97 | // exports from uEye_tools.dll
|
---|
98 | // ***********************************************
|
---|
99 |
|
---|
100 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_InitAVI",CallingConvention=CallingConvention.StdCall)] // isavi_InitAVI) (INT* pnAviID,HANDLE hf);
|
---|
101 | private static extern Int32 isavi_InitAVI(ref Int32 pnAviID,Int32 hu);
|
---|
102 |
|
---|
103 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_ExitAVI",CallingConvention=CallingConvention.StdCall)] //isavi_ExitAVI) (INT nAviID);
|
---|
104 | private static extern Int32 isavi_ExitAVI (Int32 nAviID);
|
---|
105 |
|
---|
106 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_OpenAVI",CallingConvention=CallingConvention.StdCall)] //isavi_OpenAVI) (INT nAviID, const char* strFileName);
|
---|
107 | private static extern Int32 isavi_OpenAVI (Int32 nAviID, byte[] strFileName);
|
---|
108 |
|
---|
109 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_StartAVI",CallingConvention=CallingConvention.StdCall)] // isavi_StartAVI) (INT nAviID);
|
---|
110 | private static extern Int32 isavi_StartAVI (Int32 nAviID);
|
---|
111 |
|
---|
112 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_StopAVI",CallingConvention=CallingConvention.StdCall)] // isavi_StopAVI) (INT nAviID);
|
---|
113 | private static extern Int32 isavi_StopAVI (Int32 nAviID);
|
---|
114 |
|
---|
115 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_AddFrame",CallingConvention=CallingConvention.StdCall)] // isavi_AddFrame (INT nAviID,char *pcImageMem);
|
---|
116 | private static extern Int32 isavi_AddFrame (Int32 nAviID, IntPtr pcImageMem);
|
---|
117 |
|
---|
118 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_SetFrameRate",CallingConvention=CallingConvention.StdCall)] // isavi_SetFrameRate (INT nAviID,double fr);
|
---|
119 | private static extern Int32 isavi_SetFrameRate (Int32 nAviID,double fr);
|
---|
120 |
|
---|
121 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_SetImageQuality",CallingConvention=CallingConvention.StdCall)] // isavi_SetImageQuality (INT nAviID,Int32 q);
|
---|
122 | private static extern Int32 isavi_SetImageQuality (Int32 nAviID,Int32 q);
|
---|
123 |
|
---|
124 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_GetAVISize",CallingConvention=CallingConvention.StdCall)] // isavi_GetAVISize (INT nAviID,Single *size);
|
---|
125 | private static extern Int32 isavi_GetAVISize(Int32 nAviID,ref Single size);
|
---|
126 |
|
---|
127 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_GetAVIFileName",CallingConvention=CallingConvention.StdCall)] // isavi_GetAVIFileName (INT nAviID, char* strName);
|
---|
128 | private static extern Int32 isavi_GetAVIFileName (Int32 nAviID, byte[] strName);
|
---|
129 |
|
---|
130 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_SetImageSize",CallingConvention=CallingConvention.StdCall)] // isavi_SetImageSize) (INT nAviID,INT cMode, Int32 Width, Int32 Height, Int32 PosX, Int32 PosY, Int32 LineOffset);
|
---|
131 | private static extern Int32 isavi_SetImageSize (Int32 nAviID,Int32 cMode, Int32 Width, Int32 Height, Int32 PosX, Int32 PosY, Int32 LineOffset);
|
---|
132 |
|
---|
133 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_GetnCompressedFrames",CallingConvention=CallingConvention.StdCall)] // isavi_GetnCompressedFrames (INT nAviID,unsigned Int32 *nFrames);
|
---|
134 | private static extern Int32 isavi_GetnCompressedFrames (Int32 nAviID,ref UInt32 nFrames);
|
---|
135 |
|
---|
136 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_GetnLostFrames",CallingConvention=CallingConvention.StdCall)] // isavi_GetnLostFrames (INT nAviID,unsigned Int32 *nLostFrames);
|
---|
137 | private static extern Int32 isavi_GetnLostFrames (Int32 nAviID,ref UInt32 nLostFrames);
|
---|
138 |
|
---|
139 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_ResetFrameCounters",CallingConvention=CallingConvention.StdCall)] // isavi_ResetFrameCounters (INT nAviID);
|
---|
140 | private static extern Int32 isavi_ResetFrameCounters (Int32 nAviID);
|
---|
141 |
|
---|
142 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_CloseAVI",CallingConvention=CallingConvention.StdCall)] // isavi_CloseAVI (INT nAviID);
|
---|
143 | private static extern Int32 isavi_CloseAVI (Int32 nAviID);
|
---|
144 |
|
---|
145 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_InitEvent",CallingConvention=CallingConvention.StdCall)] // isavi_InitEvent (INT nAviID, HANDLE hEv, INT which);
|
---|
146 | private static extern Int32 isavi_InitEvent (Int32 nAviID, Int32 hEv, Int32 which);
|
---|
147 |
|
---|
148 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_EnableEvent",CallingConvention=CallingConvention.StdCall)] // isavi_EnableEvent (INT nAviID, INT which);
|
---|
149 | private static extern Int32 isavi_EnableEvent (Int32 nAviID, Int32 which);
|
---|
150 |
|
---|
151 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_DisableEvent",CallingConvention=CallingConvention.StdCall)] // isavi_DisableEvent (INT nAviID, INT which);
|
---|
152 | private static extern Int32 isavi_DisableEvent (Int32 nAviID, Int32 which);
|
---|
153 |
|
---|
154 | [DllImport(DRIVER_DLL_NAME ,EntryPoint="isavi_ExitEvent",CallingConvention=CallingConvention.StdCall)] // isavi_ExitEvent (INT nAviID, INT which);
|
---|
155 | private static extern Int32 isavi_ExitEvent (Int32 nAviID, Int32 which);
|
---|
156 |
|
---|
157 | // internal variables
|
---|
158 | private Int32 m_hAvi; // internal avi container handle
|
---|
159 |
|
---|
160 | // constructor
|
---|
161 | public uEye_tools()
|
---|
162 | {
|
---|
163 | m_hAvi = 0;
|
---|
164 | }
|
---|
165 |
|
---|
166 | //********************************************************************************************
|
---|
167 | // Helper functions
|
---|
168 | //********************************************************************************************
|
---|
169 |
|
---|
170 | // ------------------------------ GetStringFromByte --------------------------
|
---|
171 | //
|
---|
172 | private string GetStringFromByte(byte[] pByte, Int32 nStart, Int32 nLength )
|
---|
173 | {
|
---|
174 | Int32 i=0;
|
---|
175 | char[] pChars = new char[nLength];
|
---|
176 | for ( i=0; i<nLength; i++)
|
---|
177 | {
|
---|
178 | pChars[i] = Convert.ToChar(pByte[nStart+i]);
|
---|
179 | }
|
---|
180 | string strResult = new string(pChars);
|
---|
181 | return strResult;
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | // ------------------------- IsuEyeOpen -----------------
|
---|
186 | //
|
---|
187 | public bool IsOpen()
|
---|
188 | {
|
---|
189 | if ( m_hAvi == 0 )
|
---|
190 | return false;
|
---|
191 | else
|
---|
192 | return true;
|
---|
193 | }
|
---|
194 |
|
---|
195 |
|
---|
196 | //*************************************************************************
|
---|
197 | // Function wrappers
|
---|
198 | //*************************************************************************
|
---|
199 |
|
---|
200 | // --------------------- init avi---------------------
|
---|
201 | //
|
---|
202 |
|
---|
203 | public Int32 InitAVI(Int32 hu )
|
---|
204 | {
|
---|
205 | Int32 ret = 0;
|
---|
206 | Int32 AviID = 0;
|
---|
207 |
|
---|
208 | ret = isavi_InitAVI(ref AviID, hu);
|
---|
209 | if ( ret == IS_AVI_NO_ERR )
|
---|
210 | m_hAvi = AviID;
|
---|
211 |
|
---|
212 | return ret;
|
---|
213 | }
|
---|
214 |
|
---|
215 | // --------------------- ExitAvi -----------------------
|
---|
216 | //
|
---|
217 | public Int32 ExitAVI()
|
---|
218 | {
|
---|
219 | Int32 ret = 0;
|
---|
220 | ret = isavi_ExitAVI(m_hAvi);
|
---|
221 | if ( ret == IS_AVI_NO_ERR )
|
---|
222 | m_hAvi = 0;
|
---|
223 |
|
---|
224 | return ret;
|
---|
225 | }
|
---|
226 |
|
---|
227 | // --------------------- OPenAvi -----------------------
|
---|
228 | //
|
---|
229 | public Int32 OpenAVI( byte[] strFileName)
|
---|
230 | {
|
---|
231 | Int32 ret = 0;
|
---|
232 |
|
---|
233 | ret = isavi_OpenAVI (m_hAvi, strFileName);
|
---|
234 |
|
---|
235 | return ret;
|
---|
236 | }
|
---|
237 |
|
---|
238 | // --------------------- StartAvi -----------------------
|
---|
239 | //
|
---|
240 | public Int32 StartAVI()
|
---|
241 | {
|
---|
242 | Int32 ret = 0;
|
---|
243 |
|
---|
244 | ret = isavi_StartAVI (m_hAvi);
|
---|
245 |
|
---|
246 | return ret;
|
---|
247 | }
|
---|
248 |
|
---|
249 | // --------------------- StopAvi -----------------------
|
---|
250 | //
|
---|
251 | public Int32 StopAVI()
|
---|
252 | {
|
---|
253 | Int32 ret = 0;
|
---|
254 |
|
---|
255 | ret = isavi_StopAVI (m_hAvi);
|
---|
256 |
|
---|
257 | return ret;
|
---|
258 | }
|
---|
259 |
|
---|
260 | // --------------------- CloseAVI -----------------------
|
---|
261 | //
|
---|
262 | public Int32 CloseAVI ()
|
---|
263 | {
|
---|
264 | Int32 ret = 0;
|
---|
265 |
|
---|
266 | ret = isavi_CloseAVI (m_hAvi);
|
---|
267 |
|
---|
268 | return ret;
|
---|
269 | }
|
---|
270 |
|
---|
271 |
|
---|
272 | // --------------------- AddFrame -----------------------
|
---|
273 | //
|
---|
274 | public Int32 AddFrame(IntPtr pcImageMem)
|
---|
275 | {
|
---|
276 | Int32 ret = 0;
|
---|
277 |
|
---|
278 | ret = isavi_AddFrame (m_hAvi, pcImageMem);
|
---|
279 |
|
---|
280 | return ret;
|
---|
281 | }
|
---|
282 |
|
---|
283 | // --------------------- SetFrameRate -----------------------
|
---|
284 | //
|
---|
285 | public Int32 SetFrameRate(double fr)
|
---|
286 | {
|
---|
287 | Int32 ret = 0;
|
---|
288 |
|
---|
289 | ret = isavi_SetFrameRate (m_hAvi, fr);
|
---|
290 |
|
---|
291 | return ret;
|
---|
292 | }
|
---|
293 |
|
---|
294 |
|
---|
295 | // --------------------- SetImageQuality -----------------------
|
---|
296 | //
|
---|
297 | public Int32 SetImageQuality(Int32 q)
|
---|
298 | {
|
---|
299 | Int32 ret = 0;
|
---|
300 |
|
---|
301 | ret = isavi_SetImageQuality (m_hAvi, q);
|
---|
302 |
|
---|
303 | return ret;
|
---|
304 | }
|
---|
305 |
|
---|
306 | // --------------------- GetAVISize -----------------------
|
---|
307 | //
|
---|
308 | public Int32 GetAVISize(ref Single size)
|
---|
309 | {
|
---|
310 | Int32 ret = 0;
|
---|
311 |
|
---|
312 | ret = isavi_GetAVISize (m_hAvi,ref size);
|
---|
313 |
|
---|
314 | return ret;
|
---|
315 | }
|
---|
316 |
|
---|
317 | // --------------------- GetAVIFileName -----------------------
|
---|
318 | //
|
---|
319 | public Int32 GetAVIFileName(byte[] strFileName)
|
---|
320 | {
|
---|
321 | Int32 ret = 0;
|
---|
322 |
|
---|
323 | ret = isavi_GetAVIFileName (m_hAvi,strFileName);
|
---|
324 |
|
---|
325 | return ret;
|
---|
326 | }
|
---|
327 |
|
---|
328 | // --------------------- SetImageSize -----------------------
|
---|
329 | //
|
---|
330 | public Int32 SetImageSize(Int32 cMode, Int32 Width, Int32 Height, Int32 PosX, Int32 PosY, Int32 LineOffset)
|
---|
331 | {
|
---|
332 | Int32 ret = 0;
|
---|
333 |
|
---|
334 | ret = isavi_SetImageSize (m_hAvi, cMode, Width, Height, PosX, PosY, LineOffset);
|
---|
335 |
|
---|
336 | return ret;
|
---|
337 | }
|
---|
338 |
|
---|
339 | // --------------------- GetnCompressedFrames -----------------------
|
---|
340 | //
|
---|
341 | public Int32 GetnCompressedFrames(ref UInt32 nFrames)
|
---|
342 | {
|
---|
343 | Int32 ret = 0;
|
---|
344 |
|
---|
345 | ret = isavi_GetnCompressedFrames (m_hAvi,ref nFrames);
|
---|
346 |
|
---|
347 | return ret;
|
---|
348 | }
|
---|
349 |
|
---|
350 | // --------------------- GetnLostFrames -----------------------
|
---|
351 | //
|
---|
352 | public Int32 GetnLostFrames(ref UInt32 nLostFrames)
|
---|
353 | {
|
---|
354 | Int32 ret = 0;
|
---|
355 |
|
---|
356 | ret = isavi_GetnLostFrames (m_hAvi,ref nLostFrames);
|
---|
357 |
|
---|
358 | return ret;
|
---|
359 | }
|
---|
360 |
|
---|
361 | // --------------------- ResetFrameCounters -----------------------
|
---|
362 | //
|
---|
363 | public Int32 ResetFrameCounters()
|
---|
364 | {
|
---|
365 | Int32 ret = 0;
|
---|
366 |
|
---|
367 | ret = isavi_ResetFrameCounters (m_hAvi);
|
---|
368 |
|
---|
369 | return ret;
|
---|
370 | }
|
---|
371 |
|
---|
372 |
|
---|
373 | // --------------------- InitEvent -----------------------
|
---|
374 | //
|
---|
375 | public int InitEvent(Int32 hEv, Int32 which)
|
---|
376 | {
|
---|
377 | Int32 ret = 0;
|
---|
378 | ret = isavi_InitEvent( m_hAvi, hEv, which );
|
---|
379 |
|
---|
380 | return ret;
|
---|
381 | }
|
---|
382 |
|
---|
383 | // --------------------- EnableEvent -----------------------
|
---|
384 | //
|
---|
385 | public Int32 EnableEvent(Int32 which)
|
---|
386 | {
|
---|
387 | Int32 ret = 0;
|
---|
388 |
|
---|
389 | ret = isavi_EnableEvent (m_hAvi,which);
|
---|
390 |
|
---|
391 | return ret;
|
---|
392 | }
|
---|
393 |
|
---|
394 | // --------------------- DisableEvent -----------------------
|
---|
395 | //
|
---|
396 | public Int32 DisableEvent(Int32 which)
|
---|
397 | {
|
---|
398 | Int32 ret = 0;
|
---|
399 |
|
---|
400 | ret = isavi_DisableEvent (m_hAvi,which);
|
---|
401 |
|
---|
402 | return ret;
|
---|
403 | }
|
---|
404 |
|
---|
405 | // --------------------- ExitEvent -----------------------
|
---|
406 | //
|
---|
407 | public Int32 ExitEvent(Int32 which)
|
---|
408 | {
|
---|
409 | Int32 ret = 0;
|
---|
410 |
|
---|
411 | ret = isavi_ExitEvent (m_hAvi,which);
|
---|
412 |
|
---|
413 | return ret;
|
---|
414 | }
|
---|
415 |
|
---|
416 | }
|
---|
417 |
|
---|
418 |
|
---|
419 |
|
---|