/DeviceAdapters/PVCAMPI/PVCAMUtils.cpp

https://github.com/astraw/micromanager1.3 · C++ · 255 lines · 195 code · 13 blank · 47 comment · 12 complexity · ad60f162e00979a274784f8005173414 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // FILE: PVCAMUtils.cpp
  3. // PROJECT: Micro-Manager
  4. // SUBSYSTEM: DeviceAdapters
  5. //-----------------------------------------------------------------------------
  6. // DESCRIPTION: PVCAM universal camera module
  7. // COPYRIGHT: University of California, San Francisco, 2006
  8. // LICENSE: This file is distributed under the BSD license.
  9. // License text is included with the source distribution.
  10. //
  11. // This file is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty
  13. // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. //
  15. // IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  16. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
  18. // AUTHOR: Nenad Amodaj, nenad@amodaj.com, 06/30/2006
  19. //
  20. // NOTE: The code here was copied almost verbatim from the PVCAM
  21. // SDK example code (Copyright Roper Scientific)
  22. //
  23. // CVS: $Id: PVCAMUtils.cpp 336 2007-07-06 21:27:30Z nenad $
  24. #pragma warning (disable : 4800)
  25. #ifdef WIN32
  26. #define WIN32_LEAN_AND_MEAN
  27. #include <windows.h>
  28. #endif
  29. #ifdef WIN32
  30. #include "../../../3rdparty/RoperScientific/Windows/PvCam_micromax/master.h"
  31. #include "../../../3rdparty/RoperScientific/Windows/PvCam_micromax/pvcam.h"
  32. #else
  33. #ifdef __APPLE__
  34. #define __mac_os_x
  35. #include <PVCAM/master.h>
  36. #include <PVCAM/pvcam.h>
  37. #endif
  38. #endif
  39. #include "PVCAMUtils.h"
  40. /*****************************************************************************
  41. *
  42. * SetLongParam_PvCam
  43. *
  44. * Description ::
  45. * This routine sets a parameter in PvCam, it takes care of data type for
  46. * the user, by taking a long from the user.
  47. *
  48. *-----------------------------------------------------------------------------
  49. */
  50. bool SetLongParam_PvCam
  51. ( int16 handle,
  52. uns32 pvcam_cmd,
  53. long value
  54. )
  55. {
  56. bool status = false;
  57. union {
  58. double dtmp;
  59. uns8 ubytetmp;
  60. int16 stmp;
  61. uns16 ustmp;
  62. int32 ltmp;
  63. uns32 ultmp;
  64. uns32 etmp;
  65. boolean btmp;
  66. int8 bytetmp;
  67. } temp; /* temp variable for values, which can be any data type. */
  68. bool avail; /* PvCam available variable. */
  69. uns16 DataType; /* PvCam data type variable. */
  70. uns16 access; /* PvCam access variable. */
  71. bool fcn_status; /* status of function. */
  72. uns32 count; /* number of values in variable */
  73. fcn_status = (bool)pl_get_param( handle, pvcam_cmd, ATTR_AVAIL, (void*)&temp );
  74. avail = (bool)temp.btmp;
  75. if (fcn_status && avail)
  76. {
  77. pl_get_param( handle, pvcam_cmd, ATTR_TYPE,
  78. (void*)&DataType );
  79. pl_get_param( handle, pvcam_cmd, ATTR_COUNT,
  80. (void*)&count);
  81. pl_get_param( handle, pvcam_cmd, ATTR_ACCESS,
  82. (void*)&access );
  83. /* Make sure this is a valid parameter to set. */
  84. if (access == ACC_READ_WRITE)
  85. {
  86. status = true;
  87. switch (DataType)
  88. {
  89. case TYPE_INT8 : /* signed char */
  90. temp.bytetmp = (char) value;
  91. pl_set_param(handle, pvcam_cmd, (void *)&temp.bytetmp);
  92. break;
  93. case TYPE_UNS8 : /* unsigned char */
  94. temp.ubytetmp = (unsigned char) value;
  95. pl_set_param(handle, pvcam_cmd, (void *)&temp.ubytetmp);
  96. break;
  97. case TYPE_INT16 : /* short */
  98. temp.stmp = (short) value;
  99. pl_set_param(handle, pvcam_cmd, (void *)&temp.stmp);
  100. break;
  101. case TYPE_UNS16 : /* unsigned short */
  102. temp.ustmp = (unsigned short) value;
  103. pl_set_param(handle, pvcam_cmd, (void *)&temp.ustmp);
  104. break;
  105. case TYPE_INT32 : /* long */
  106. temp.ltmp = (long) value;
  107. pl_set_param(handle, pvcam_cmd, (void *)&temp.ltmp);
  108. break;
  109. case TYPE_UNS32 : /* unsigned long */
  110. temp.ultmp = (unsigned long) value;
  111. pl_set_param(handle, pvcam_cmd, (void *)&temp.ultmp);
  112. break;
  113. case TYPE_FLT64 : /* double */
  114. temp.dtmp = (double) value;
  115. pl_set_param(handle, pvcam_cmd, (void *)&temp.dtmp);
  116. break;
  117. case TYPE_BOOLEAN : /* Boolean value */
  118. temp.btmp = (boolean) value;
  119. pl_set_param(handle, pvcam_cmd, (void *)&temp.btmp);
  120. break;
  121. case TYPE_ENUM : /* Can be treat as unsigned long */
  122. temp.ultmp = (unsigned long) value;
  123. pl_set_param(handle, pvcam_cmd, (void *)&temp.ultmp);
  124. break;
  125. default:
  126. /* ptrs not supported yet. */
  127. case TYPE_VOID_PTR : /* ptr to void */
  128. case TYPE_VOID_PTR_PTR :/* void ptr to a ptr. */
  129. case TYPE_CHAR_PTR : /* char */
  130. status = false;
  131. break;
  132. }
  133. }
  134. }
  135. return(status);
  136. } /* end SetLongParam_PvCam */
  137. /*****************************************************************************
  138. *
  139. * GetLongParam_PvCam
  140. *
  141. * Description ::
  142. * This routine gets a parameter in PvCam, it takes care of data type for
  143. * the user by returning it in a long.
  144. *
  145. *-----------------------------------------------------------------------------
  146. */
  147. bool GetLongParam_PvCam
  148. ( int16 handle,
  149. uns32 pvcam_cmd,
  150. long *value
  151. )
  152. {
  153. bool status = false;
  154. union {
  155. double dtmp;
  156. uns8 ubytetmp;
  157. int16 stmp;
  158. uns16 ustmp;
  159. int32 ltmp;
  160. uns32 ultmp;
  161. uns32 etmp;
  162. boolean btmp;
  163. int8 bytetmp;
  164. } temp; /* temp variable for values, which can be any data type. */
  165. bool avail; /* PvCam available variable. */
  166. uns16 DataType; /* PvCam data type variable. */
  167. uns16 access; /* PvCam access variable. */
  168. bool fcn_status; /* status of function. */
  169. uns32 count; /* number of values in variable */
  170. fcn_status = (bool)pl_get_param( handle, pvcam_cmd, ATTR_AVAIL, (void*)&temp );
  171. avail = (bool)temp.btmp;
  172. if (fcn_status && avail)
  173. {
  174. pl_get_param( handle, pvcam_cmd, ATTR_TYPE,
  175. (void*)&DataType );
  176. pl_get_param( handle, pvcam_cmd, ATTR_COUNT,
  177. (void*)&count);
  178. pl_get_param( handle, pvcam_cmd, ATTR_ACCESS,
  179. (void*)&access );
  180. /* Make sure this is a valid parameter to set. */
  181. if ((access == ACC_READ_WRITE) || (access == ACC_READ_ONLY))
  182. {
  183. status = true;
  184. switch (DataType)
  185. {
  186. case TYPE_INT8 : /* signed char */
  187. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  188. (void*)&temp.bytetmp);
  189. *value = (long) temp.bytetmp;
  190. break;
  191. case TYPE_UNS8 : /* unsigned char */
  192. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  193. (void*)&temp.ubytetmp);
  194. *value = (long) temp.ubytetmp;
  195. break;
  196. case TYPE_INT16 : /* short */
  197. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  198. (void*)&temp.stmp);
  199. *value = (long) temp.stmp;
  200. break;
  201. case TYPE_UNS16 : /* unsigned short */
  202. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  203. (void*)&temp.ustmp);
  204. *value = (long) temp.ustmp;
  205. break;
  206. case TYPE_INT32 : /* long */
  207. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  208. (void*)&temp.ltmp);
  209. *value = (long) temp.ltmp;
  210. break;
  211. case TYPE_UNS32 : /* unsigned long */
  212. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  213. (void*)&temp.ultmp);
  214. *value = (long) temp.ultmp;
  215. break;
  216. case TYPE_FLT64 : /* double */
  217. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  218. (void*)&temp.dtmp);
  219. *value = (long) temp.dtmp;
  220. break;
  221. case TYPE_BOOLEAN : /* Boolean value */
  222. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  223. (void*)&temp.btmp);
  224. *value = (long) temp.btmp;
  225. break;
  226. case TYPE_ENUM : /* Can be treat as unsigned long */
  227. pl_get_param( handle, pvcam_cmd, ATTR_CURRENT,
  228. (void*)&temp.ultmp);
  229. *value = (long) temp.ultmp;
  230. break;
  231. default:
  232. /* ptrs not supported yet. */
  233. case TYPE_VOID_PTR : /* ptr to void */
  234. case TYPE_VOID_PTR_PTR :/* void ptr to a ptr. */
  235. case TYPE_CHAR_PTR : /* char */
  236. status = false;
  237. break;
  238. }
  239. }
  240. }
  241. return(status);
  242. } /* end GetLongParam_PvCam */