/camera/camlib

To get this branch, use:
bzr branch http://darksoft.org/webbzr/camera/camlib

« back to all changes in this revision

Viewing changes to include/pfcam.h

  • Committer: Suren A. Chilingaryan
  • Date: 2011-02-13 01:33:37 UTC
  • Revision ID: csa@dside.dyndns.org-20110213013337-ibm4w4n5a3hu4k7u
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** \file pfcam.h
 
2
 *
 
3
 * This is the replacement for camdll.h. It will provide the API for
 
4
 * the property protocol only.
 
5
 *
 
6
 * This is (yet) work under construction.
 
7
 *
 
8
 */
 
9
 
 
10
#include "pftypes.h"  // Photonfocus data types
 
11
#include "api.h"
 
12
 
 
13
 
 
14
/*!
 
15
 * \mainpage PFLIB SDK Documentation
 
16
 * \version 1.0
 
17
 * \author Photonfocus AG
 
18
 * \date 02/2010
 
19
 *
 
20
 * \section intro   Introduction
 
21
 * 
 
22
 * The Photonfocus library 'PFLIB' enables an application programmer
 
23
 * to control a Photonfocus Camera's features without direct access to
 
24
 * the CameraLink (or other communication layer such as Gigabit Ethernet)
 
25
 * interface.
 
26
 * The access, in order to work with most of the frame grabbers, is
 
27
 * done by a separate COMDLL, which is a low level communication interface
 
28
 * to the frame grabber's RS232 emulation. This may be frame grabber specific,
 
29
 * and does not depend on the camera type.
 
30
 *
 
31
 * \note The API has changed from 0.x to 1.x. No 'old' function call
 
32
 *       is supported anymore. However, the 1.0 API is much simpler and
 
33
 *       flexible to handle.
 
34
 *
 
35
 * \section api   API Details
 
36
 *
 
37
 * The API interface uses the standard C convention (CDECL) interface.
 
38
 * Support for Visual Basic is not available.
 
39
 * The PFLIB is portable among different operating systems such as
 
40
 * Microsoft Windows, Linux, QNX, and other Unix versions, however,
 
41
 * this is not tested and we cannot give any support for an operating
 
42
 * system other than Microsoft Windows.
 
43
 *
 
44
 * This 1.0 version API was designed as generic as possible for any
 
45
 * device type. Therefore, we ask the reader not to be confused about
 
46
 * abstract terms as 'devices' and 'properties'. For legacy reasons,
 
47
 * the term 'camera' still appears here and there. We apologize for
 
48
 * the inconsistence.
 
49
 *
 
50
 * \subsection props   Property concept
 
51
 *
 
52
 * The device property concept (so forth 'Property') of the previous 0.x PFLIB
 
53
 * API has been refined such that all device properties are basically
 
54
 * controlled via pfDevice_GetProperty() and  pfDevice_SetProperty().
 
55
 *
 
56
 * New in this API is a tree hierarchy, that covers the following property
 
57
 * features:
 
58
 *
 
59
 * \li Properties have more extended types such as structs and arrays and
 
60
 *     can contain other Property members
 
61
 * \li Max and min values are encoded the same way in a parent/children
 
62
 *     hierarchy
 
63
 * \li Mode selections can be encoded in this tree concept as well
 
64
 *
 
65
 * \image html properties.png  "Property hierarchy"
 
66
 * \image latex properties.pdf   "Property" width=15cm
 
67
 *
 
68
 *
 
69
 * The architecture also allows to integrate user defined children types
 
70
 * to a data type via structs that allow signalling events to a specific GUI
 
71
 * element when Property was changed, etc.
 
72
 *
 
73
 * To keep the API and the library code as compact and efficient as possible,
 
74
 * the Property access happens via tokens. The token is obtained by 
 
75
 * pfProperty_ParseName() via a given name, which is defined in the name
 
76
 * space of a certain parent node. The top root node of a Property
 
77
 * hierarchy is always the device node which is obtained by pfDevice_GetRoot().
 
78
 *
 
79
 * Value passing is done via a runtime data type information capable structure
 
80
 * 'PFValue'. This structure contains a data union field and an associated
 
81
 * data type. The value is retrieved from the PFValue struct according
 
82
 * to the type field. The Property getter and setter functions of the library
 
83
 * perform a type check and return an error (#PFERR_PROPERTY_TYPE_MATCH) in
 
84
 * case of a mismatch.
 
85
 *
 
86
 * The following code sequence demonstrates how to set the exposure time
 
87
 * of a camera:
 
88
 *
 
89
 
 
90
\code
 
91
int setExposure(int port, float time)
 
92
{
 
93
        PFValue val;
 
94
        int error;
 
95
        TOKEN t_exp = pfProperty_ParseName(port, "ExposureTime"));
 
96
 
 
97
        if (t_exp == INVALID_TOKEN) return PFERR_PROPERTY_UNKNOWN;
 
98
 
 
99
        // Initialize Value:
 
100
        val.value.f = time;
 
101
        val.type = PF_FLOAT;
 
102
 
 
103
        error = pfDevice_SetProperty(port, t_exp, &val);
 
104
 
 
105
        return error;
 
106
}
 
107
\endcode
 
108
 
 
109
 
 
110
 *
 
111
 *
 
112
 * \subsection commonfunc Common function parameters
 
113
 *
 
114
 * Generally, the first parameter of a function whose name starts with
 
115
 * 'pfDevice_' is the current camera device handle. The struct members of
 
116
 * the camera object must NEVER be accessed directly, to preserve future
 
117
 * binary compatibility.
 
118
 *
 
119
 * If not documented otherwise, the function's return value is 
 
120
 * \li  < 0 on failure
 
121
 * \li == 0 on success
 
122
 * \li  > 0 a warning
 
123
 *
 
124
 * Functions which set a value may return #PFWARN_PROPERTY_MODIFIED, meaning
 
125
 * that the given parameter was not valid or not according to certain
 
126
 * constraints. All 'Event' children of this property should be queried via
 
127
 * pfProperty_Select(), because they may have changed.
 
128
 * In this case, the user should also read back the value that was passed
 
129
 * to pfSetProperty() which was possibly modified 'in place'.
 
130
 *
 
131
 *
 
132
 * \see ErrorHandling
 
133
 *
 
134
 */
 
135
 
 
136
 
 
137
// This trick is used for easy function wrapping..
 
138
#ifndef APIFUNC
 
139
#define APIFUNC(retval, name, parms)           \
 
140
        CAMDLL_API retval APIDECL pf##name parms;
 
141
#endif
 
142
 
 
143
 
 
144
/**
 
145
 * \defgroup PortAccess Port Access, Device Initialization
 
146
 *
 
147
 * This module contains the initialization routines for the
 
148
 * camera ports
 
149
 */
 
150
 
 
151
/**
 
152
 * \example example.c
 
153
 *
 
154
 * This example works with a HURRICANE-40 camera. 
 
155
 * For other cameras, check propertylist first and change code.\n
 
156
 * Propertylist: Start PFRemote1.0, press F1 for help, menu Camera Properties, select camera
 
157
 *
 
158
 */
 
159
 
 
160
/**
 
161
 * \example main.c
 
162
 *
 
163
 * A simple command line program to query and set properties.
 
164
 * 
 
165
 * \b Usage
 
166
 * \verbatim
 
167
   <programname>\endverbatim
 
168
 *                       Lists all top level properties of the device
 
169
 *
 
170
 * \verbatim
 
171
   <programname> <property_name> \endverbatim
 
172
 *
 
173
 *                       Query specified Property with name 'property'.
 
174
 *                       Children are displayed as well as its value,
 
175
 *                       if applicable.
 
176
 *
 
177
 * \verbatim
 
178
   <programname> <property> <value> \endverbatim
 
179
 *
 
180
 *                       Set specified Property with name 'property'
 
181
 *                       to value 'value'. Illegal values are caught.
 
182
 *
 
183
 *
 
184
 *
 
185
 */
 
186
 
 
187
/**
 
188
 * \addtogroup PortAccess
 
189
 * \{
 
190
 */
 
191
 
 
192
 
 
193
/** 
 
194
 *
 
195
 *  Init of all camera ports. This has to be called as first
 
196
 *
 
197
 * \param numOfPorts    Number of available camera ports
 
198
 * 
 
199
 * \return              0: successful\n
 
200
 *                      < 0: error
 
201
 *
 
202
 */
 
203
APIFUNC(int, PortInit, (int *numOfPorts))
 
204
 
 
205
        
 
206
/** 
 
207
 *
 
208
 *  Get information about a port (manufacturer, name, etc)
 
209
 *
 
210
 * \param port          Port number of the camera
 
211
 *
 
212
 * \param manu          Name of the manufacturer of this port
 
213
 *
 
214
 * \param mBytes        Lenght of (manu+1)
 
215
 *
 
216
 * \param name          Name of the manufacturer of this port
 
217
 *
 
218
 * \param nBytes        Lenght of (name+1)
 
219
 *
 
220
 * \param version       Version of CLALLSERIAL (0 if no ClAllSerial port)\n
 
221
 *                      1 : CL_DLL_VERSION_NO_VERSION   Not a CL dll\n
 
222
 *                      2 : CL_DLL_VERSION_1_0          Oct 2000 compliant\n
 
223
 *                      3 : CL_DLL_VERSION_1_1          Oct 2001 compliant\n
 
224
 
 
225
 * \param type          Type of this port\n
 
226
 *                      0 : ClAllSerial port\n
 
227
 *                      1 : port with clser.dll at pfremote directory\n
 
228
 *                      2 : USB port\n
 
229
 *                      3 : RS-232 port\n
 
230
 * 
 
231
 * \return              0: successful\n
 
232
 *                      < 0: error
 
233
 *
 
234
 */
 
235
APIFUNC(int, PortInfo, (int port, char *manu, int *mBytes, char *name, int *nBytes, int *version, int *type))
 
236
 
 
237
 
 
238
/**
 
239
 * Check if required baud rate is possible. The camera port must be opened, before checking the required baud rate
 
240
 * 
 
241
 * \param port          Port number of the camera
 
242
 *
 
243
 * \param baudrate      Baud rate to check (eg. 57600)
 
244
 *                       
 
245
 * \return              1: baud rate suporrted\n
 
246
 *                      0: baud rate not supported\n
 
247
 *                      < 0: error.
 
248
 */
 
249
APIFUNC(int, IsBaudRateSupported, (int port, int baudrate))
 
250
 
 
251
        
 
252
/**
 
253
 * Get current baud rate
 
254
 * 
 
255
 * \param port          Port number of the camera
 
256
 *
 
257
 * \param baudrate      Baud rate
 
258
 *                       
 
259
 * \return              0: successful\n
 
260
 *                      < 0: error.\n
 
261
 */
 
262
APIFUNC(int, GetBaudRate, (int port, int *baudrate))
 
263
 
 
264
 
 
265
/**
 
266
 * Set baud rate. The camera port must be opened, before setting the baud rate
 
267
 * 
 
268
 * \param port          Port number of the camera
 
269
 *
 
270
 * \param baudrate      Baud rate to set (eg. 57600)
 
271
 *                       
 
272
 * \return              0: successful\n
 
273
 *                      < 0: error.\n
 
274
 */
 
275
APIFUNC(int, SetBaudRate, (int port, int baudrate))
 
276
 
 
277
 
 
278
/**
 
279
 * Open Device
 
280
 * 
 
281
 * \param port          Port number of the camera
 
282
 *                       
 
283
 * \return              0: successful\n
 
284
 *                      < 0: error\n
 
285
 *                      A value > 0 means, the device was opened, but
 
286
 *                      some non blocking failure was detected (bad
 
287
 *                      device identity, etc.). In this case, some int index
 
288
 *                      device features may not be accessible, but the
 
289
 *                      it can be normally fixed via an update.
 
290
 */
 
291
APIFUNC(int, DeviceOpen, (int port))    
 
292
 
 
293
        
 
294
/**
 
295
 * Close device communication.
 
296
 * This should be called at the end of an application,
 
297
 * when the device is no longer accessed.
 
298
 *
 
299
 * \param port          Port number of the camera
 
300
 *
 
301
 * \return              0: success\n
 
302
 *                      < 0: error\n
 
303
 */
 
304
APIFUNC(int, DeviceClose, (int port))
 
305
 
 
306
/* \} */
 
307
 
 
308
 
 
309
////////////////////////////////////////////////////////////////////////////
 
310
// Prototyping NEW API (1.0)
 
311
////////////////////////////////////////////////////////////////////////////
 
312
 
 
313
// DLL top level stuff
 
314
 
 
315
APIFUNC(const char *, DeviceGetDllVersion, (int port, int *major, int *minor))  
 
316
 
 
317
////////////////////////////////////////////////////////////////////////////
 
318
// PROPERTY API
 
319
 
 
320
/**
 
321
 * \defgroup PropControl Generic Device property control
 
322
 *
 
323
 * This contains the function set necessary to control arbitrary
 
324
 * device properties.
 
325
 * 
 
326
 */
 
327
 
 
328
/**
 
329
 * \addtogroup PropControl
 
330
 * \{
 
331
 */
 
332
 
 
333
        
 
334
/**
 
335
 * Get root namespace descriptor token of current device
 
336
 *
 
337
 * This function always returns a valid token.
 
338
 
 
339
 * \param port  Port number of the camera 
 
340
 * 
 
341
 * \return      The root descriptor token
 
342
 *
 
343
 **/
 
344
APIFUNC(TOKEN, Device_GetRoot, (int port))
 
345
 
 
346
 
 
347
/**
 
348
 * Select a property in the property and feature hierarchy.
 
349
 *
 
350
 * This function is used to query a property inside the property hierarchy
 
351
 * which is organized in a tree. A property can have children and has always
 
352
 * a parent, except if it is the root node.
 
353
 *
 
354
 * Quick overview: To select the first child of a node, use:
 
355
 *
 
356
 * \code
 
357
     child = pfProperty_Select(port, node, node); \endcode
 
358
 *
 
359
 * To select the next children of that node:
 
360
 *
 
361
 * \code
 
362
     next = pfProperty_Select(port, node, child); \endcode
 
363
 *
 
364
 * \param port          Port number of the camera 
 
365
 * \param parent        The parent node to be queried 
 
366
 * \param prev          The node whose following (next) node shall be selected
 
367
 *                      If the parent node is specified, its first children is
 
368
 *                      selected.
 
369
 *
 
370
 * \return              The next or children token, if existing, INVALID_TOKEN
 
371
 *                      otherwise.
 
372
 **/
 
373
APIFUNC(TOKEN, Property_Select, (int port, TOKEN parent, TOKEN prev))
 
374
 
 
375
        
 
376
/**
 
377
 * Get a property handle (TOKEN) by name.
 
378
 *
 
379
 * \param port          Port number of the camera * 
 
380
 * \param propname      Pointer to a string containing the property name
 
381
 * 
 
382
 * \return              The TOKEN of the property. If not existing, INVALID_TOKEN.
 
383
 *
 
384
 **/    
 
385
APIFUNC(TOKEN, Property_ParseName, (int port, const char *propname))
 
386
        
 
387
 
 
388
/**
 
389
 * Get the name of a property by token
 
390
 *
 
391
 * \param port          Port number of the camera
 
392
 * \param p             The token of the property whose name is to be
 
393
 *                      queried
 
394
 *
 
395
 * \return              Pointer to the constant property string
 
396
 * 
 
397
 **/
 
398
APIFUNC(const char *, Property_GetName, (int port, TOKEN p))
 
399
 
 
400
 
 
401
/**
 
402
 * Get the property data type by token
 
403
 *
 
404
 * \param port          Port number of the camera
 
405
 * \param p             The property token whose type are to be queried
 
406
 *
 
407
 * \return              The type of the property 
 
408
 *
 
409
 **/
 
410
APIFUNC(PropertyType, Property_GetType, (int port, TOKEN p))
 
411
 
 
412
        
 
413
/**
 
414
 * Get the property flags by token
 
415
 *
 
416
 * \param port          Port number of the camera
 
417
 * \param p             The property token whose flags are to be queried
 
418
 *
 
419
 * \return              The property flags
 
420
 *
 
421
 **/
 
422
APIFUNC(unsigned long, Property_GetFlags, (int port, TOKEN p))
 
423
 
 
424
 
 
425
/**
 
426
 * Get the value of a property.
 
427
 *
 
428
 * By default, a property value is owned by the caller, i.e. in case of
 
429
 * a dynamic string property, the caller is responsible for allocating the
 
430
 * proper memory and initializing the PFValue pointer field.
 
431
 * In case of a static string property, the string is owned by the
 
432
 * library, so the PFValue does not need to be initialized. See also
 
433
 * PFValue documentation.
 
434
 *
 
435
 * \param port          Port number of the camera
 
436
 * \param p             The property token whose value is to be requested
 
437
 * \param value         Pointer to a PFValue which contains the property value
 
438
 *                      after successful return of this function. Note that
 
439
 *                      in case of a non static string property, the property
 
440
 *                      value must be initialized first.
 
441
 *
 
442
 * \return              A standard return code
 
443
 *
 
444
 **/
 
445
APIFUNC(int, Device_GetProperty, (int port, TOKEN p, PFValue *value))
 
446
 
 
447
        
 
448
/**
 
449
 * Get the value of a property by string
 
450
 *
 
451
 *
 
452
 * \param port          Port number of the camera
 
453
 * \param p             The property token whose value is to be requested
 
454
 * \param outs          Pointer to a string which contains the property value
 
455
 *                      string conversion after successful return of this function.
 
456
 *                      The caller must reserve a string of the length of the
 
457
 *                      expected value string.
 
458
 * \param len           Length of the string that was reserved by caller
 
459
 *
 
460
 * \note                This function only applies to simple datatypes, resp.
 
461
 *                      only displays debugging information about some
 
462
 *                      complex data types.
 
463
 *
 
464
 * \return              The standard return code
 
465
 *
 
466
 **/
 
467
APIFUNC(int, Device_GetProperty_String, (int port, TOKEN p, char *outs, int len))       
 
468
 
 
469
 
 
470
/**
 
471
 * Set the value of a property.
 
472
 *
 
473
 * \param port          Port number of the camera
 
474
 * \param p             The property token whose value is to be requested
 
475
 * \param value         Pointer to a PFValue containing the value to be set.
 
476
 *
 
477
 * \return              The standard return code
 
478
 *
 
479
 **/
 
480
APIFUNC(int, Device_SetProperty, (int port, TOKEN p, PFValue *value))
 
481
 
 
482
        
 
483
/**
 
484
 * Set the value of a property by string.
 
485
 *
 
486
 * This function parses a string and tries to match it to the
 
487
 * specified property. 
 
488
 *
 
489
 * \param port          Port number of the camera
 
490
 * \param p             The property token whose value is to be set
 
491
 * \param string        Pointer to a string containing the value to be set.
 
492
 *
 
493
 * \return              The standard return code
 
494
 *
 
495
 **/
 
496
APIFUNC(int, Device_SetProperty_String, (int port, TOKEN p, const char *string))        
 
497
 
 
498
 
 
499
/* \} */
 
500
 
 
501
////////////////////////////////////////////////////////////////////////////
 
502
/* Non exposed low level burst read/write commands */
 
503
APIFUNC(int, Write, (int port, unsigned short addr, const unsigned char *buf, unsigned int size))
 
504
APIFUNC(int, Read, (int port, unsigned short addr, unsigned char *buf, int size))
 
505
 
 
506
/**
 
507
 * \defgroup Misc Auxiliary and miscellaneous functions/macros
 
508
 *
 
509
 * Auxiliary functions for handling & reporting errors.
 
510
 *
 
511
 */
 
512
 
 
513
/**
 
514
 * \defgroup ErrorHandling Error Handling
 
515
 *
 
516
 * Auxiliary functions for handling & reporting errors.
 
517
 *
 
518
 */
 
519
 
 
520
/**
 
521
 * \ingroup ErrorHandling
 
522
 * 
 
523
 **/
 
524
 
 
525
/**
 
526
 * Verbose error string query of an error code.
 
527
 *
 
528
 * \param error          The error code returned by a function.
 
529
 *
 
530
 * \return               Pointer to a constant string containing the error
 
531
 *                       message to the specified error code.
 
532
 *
 
533
 **/
 
534
APIFUNC(const char *, GetErrorString, (int error))
 
535
 
 
536
 
 
537
/**
 
538
 * \defgroup Aux Auxiliary functions
 
539
 *
 
540
 *
 
541
 */
 
542
 
 
543
/** \ingroup Aux
 
544
 *
 
545
 */
 
546
 
 
547
APIFUNC(int, Value_ToString, (PFValue *val, char *outs, int len))
 
548
 
 
549
        
 
550
/** \ingroup Aux
 
551
 * Sets camera feedback function
 
552
 *
 
553
 * The feedback function must return a value = 0, if the caller should
 
554
 * proceed. For example, a GUI based feedback routine may allow the user
 
555
 * to cancel the procedure by hitting the ESC key.
 
556
 * If the procedure was cancelled, the caller returns #PFERR_CANCEL.
 
557
 *
 
558
 * \param func pointer to a feedback function of type FeedbackFuncP
 
559
 *             If equal 0, the default dummy routine (no feedback) is set.
 
560
 * \return     the previous feedback function pointer
 
561
 */
 
562
APIFUNC(FeedbackFuncP, SetFeedback, (int port, FeedbackFuncP func))
 
563