Subversion Repositories f9daq

Rev

Rev 195 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <windows.h>
  2. #include <drsread.h>
  3.  
  4. /* The two macros below are used as error return codes */
  5. /* in case the DLL does not load, or is missing one or */
  6. /* more functions, respectively.  You must define them */
  7. /* to whatever values are meaningful for your DLL.     */
  8. #define kFailedToLoadDLLError     ???
  9. #define kCouldNotFindFunction     ???
  10.  
  11. static HINSTANCE DLLHandle;
  12.  
  13. /* Declare the variables that hold the addresses of the function   */
  14. /* pointers.                                                       */
  15. static void (__cdecl *DRSSetMask_Ptr)(int mask);
  16. static void (__cdecl *DRSSetTriggerType_Ptr)(int type);
  17. static void (__cdecl *DRSSetFrequency_Ptr)(int freq);
  18. static void (__cdecl *DRSSetRange_Ptr)(double range);
  19. static void (__cdecl *DRSSetTriggerChannel_Ptr)(int channel);
  20. static void (__cdecl *DRSSetTriggerDelay_Ptr)(double delay);
  21. static void (__cdecl *DRSSetTriggerLevel_Ptr)(double level);
  22. static void (__cdecl *DRSSetTriggerPolarity_Ptr)(int polarity);
  23. static float *(__cdecl *DRSGetTime_Ptr)(int ch);
  24. static float *(__cdecl *DRSGetWave_Ptr)(int ch);
  25. static int (__cdecl *DRSInit_Ptr)();
  26. static int (__cdecl *DRSRead_Ptr)(int drstimer);
  27. static int (__cdecl *DRSEnd_Ptr)();
  28. static int (__cdecl *DRSToBuffer_Ptr)(unsigned char *p, int m_evSerial);
  29. static int (__cdecl *DRSIsTimeout_Ptr)();
  30. static void (__cdecl *DRSSetTimeout_Ptr)();
  31. static void (__cdecl *DRSSigInt_Ptr)(int k);
  32.  
  33.  
  34. /* Load the DLL and get the addresses of the functions */
  35. static int LoadDLLIfNeeded(void)
  36. {
  37.     if (DLLHandle)
  38.         return 0;
  39.  
  40.     DLLHandle = LoadLibrary("drsread.dll");
  41.     if (DLLHandle == NULL) {
  42.         return kFailedToLoadDLLError;
  43.         }
  44.  
  45.     if (!(DRSSetMask_Ptr = (void*) GetProcAddress(DLLHandle, "DRSSetMask")))
  46.         goto FunctionNotFoundError;
  47.  
  48.     if (!(DRSSetTriggerType_Ptr = (void*) GetProcAddress(DLLHandle,
  49.          "DRSSetTriggerType")))
  50.         goto FunctionNotFoundError;
  51.  
  52.     if (!(DRSSetFrequency_Ptr = (void*) GetProcAddress(DLLHandle,
  53.          "DRSSetFrequency")))
  54.         goto FunctionNotFoundError;
  55.  
  56.     if (!(DRSSetRange_Ptr = (void*) GetProcAddress(DLLHandle, "DRSSetRange")))
  57.         goto FunctionNotFoundError;
  58.  
  59.     if (!(DRSSetTriggerChannel_Ptr = (void*) GetProcAddress(DLLHandle,
  60.          "DRSSetTriggerChannel")))
  61.         goto FunctionNotFoundError;
  62.  
  63.     if (!(DRSSetTriggerDelay_Ptr = (void*) GetProcAddress(DLLHandle,
  64.          "DRSSetTriggerDelay")))
  65.         goto FunctionNotFoundError;
  66.  
  67.     if (!(DRSSetTriggerLevel_Ptr = (void*) GetProcAddress(DLLHandle,
  68.          "DRSSetTriggerLevel")))
  69.         goto FunctionNotFoundError;
  70.  
  71.     if (!(DRSSetTriggerPolarity_Ptr = (void*) GetProcAddress(DLLHandle,
  72.          "DRSSetTriggerPolarity")))
  73.         goto FunctionNotFoundError;
  74.  
  75.     if (!(DRSGetTime_Ptr = (void*) GetProcAddress(DLLHandle, "DRSGetTime")))
  76.         goto FunctionNotFoundError;
  77.  
  78.     if (!(DRSGetWave_Ptr = (void*) GetProcAddress(DLLHandle, "DRSGetWave")))
  79.         goto FunctionNotFoundError;
  80.  
  81.     if (!(DRSInit_Ptr = (void*) GetProcAddress(DLLHandle, "DRSInit")))
  82.         goto FunctionNotFoundError;
  83.  
  84.     if (!(DRSRead_Ptr = (void*) GetProcAddress(DLLHandle, "DRSRead")))
  85.         goto FunctionNotFoundError;
  86.  
  87.     if (!(DRSEnd_Ptr = (void*) GetProcAddress(DLLHandle, "DRSEnd")))
  88.         goto FunctionNotFoundError;
  89.  
  90.     if (!(DRSToBuffer_Ptr = (void*) GetProcAddress(DLLHandle, "DRSToBuffer")))
  91.         goto FunctionNotFoundError;
  92.  
  93.     if (!(DRSIsTimeout_Ptr = (void*) GetProcAddress(DLLHandle, "DRSIsTimeout")))
  94.         goto FunctionNotFoundError;
  95.  
  96.     if (!(DRSSetTimeout_Ptr = (void*) GetProcAddress(DLLHandle, "DRSSetTimeout")))
  97.         goto FunctionNotFoundError;
  98.  
  99.     if (!(DRSSigInt_Ptr = (void*) GetProcAddress(DLLHandle, "DRSSigInt")))
  100.         goto FunctionNotFoundError;
  101.  
  102.     return 0;
  103.  
  104. FunctionNotFoundError:
  105.     FreeLibrary(DLLHandle);
  106.     DLLHandle = 0;
  107.     return kCouldNotFindFunction;
  108. }
  109.  
  110.  
  111. /* Glue Code for each of the DLL functions */
  112.  
  113.  
  114.  
  115. void DRSSetMask(int mask)
  116. {
  117.     int dllLoadError;
  118.  
  119.     if (dllLoadError = LoadDLLIfNeeded())
  120.         return;
  121.     (*DRSSetMask_Ptr)(mask);
  122. }
  123.  
  124.  
  125. void DRSSetTriggerType(int type)
  126. {
  127.     int dllLoadError;
  128.  
  129.     if (dllLoadError = LoadDLLIfNeeded())
  130.         return;
  131.     (*DRSSetTriggerType_Ptr)(type);
  132. }
  133.  
  134.  
  135. void DRSSetFrequency(int freq)
  136. {
  137.     int dllLoadError;
  138.  
  139.     if (dllLoadError = LoadDLLIfNeeded())
  140.         return;
  141.     (*DRSSetFrequency_Ptr)(freq);
  142. }
  143.  
  144.  
  145. void DRSSetRange(double range)
  146. {
  147.     int dllLoadError;
  148.  
  149.     if (dllLoadError = LoadDLLIfNeeded())
  150.         return;
  151.     (*DRSSetRange_Ptr)(range);
  152. }
  153.  
  154.  
  155. void DRSSetTriggerChannel(int channel)
  156. {
  157.     int dllLoadError;
  158.  
  159.     if (dllLoadError = LoadDLLIfNeeded())
  160.         return;
  161.     (*DRSSetTriggerChannel_Ptr)(channel);
  162. }
  163.  
  164.  
  165. void DRSSetTriggerDelay(double delay)
  166. {
  167.     int dllLoadError;
  168.  
  169.     if (dllLoadError = LoadDLLIfNeeded())
  170.         return;
  171.     (*DRSSetTriggerDelay_Ptr)(delay);
  172. }
  173.  
  174.  
  175. void DRSSetTriggerLevel(double level)
  176. {
  177.     int dllLoadError;
  178.  
  179.     if (dllLoadError = LoadDLLIfNeeded())
  180.         return;
  181.     (*DRSSetTriggerLevel_Ptr)(level);
  182. }
  183.  
  184.  
  185. void DRSSetTriggerPolarity(int polarity)
  186. {
  187.     int dllLoadError;
  188.  
  189.     if (dllLoadError = LoadDLLIfNeeded())
  190.         return;
  191.     (*DRSSetTriggerPolarity_Ptr)(polarity);
  192. }
  193.  
  194.  
  195. float *DRSGetTime(int ch)
  196. {
  197.     int dllLoadError;
  198.  
  199.     if (dllLoadError = LoadDLLIfNeeded())
  200.         return ???;
  201.     return (*DRSGetTime_Ptr)(ch);
  202. }
  203.  
  204.  
  205. float *DRSGetWave(int ch)
  206. {
  207.     int dllLoadError;
  208.  
  209.     if (dllLoadError = LoadDLLIfNeeded())
  210.         return ???;
  211.     return (*DRSGetWave_Ptr)(ch);
  212. }
  213.  
  214.  
  215. int DRSInit()
  216. {
  217.     int dllLoadError;
  218.  
  219.     if (dllLoadError = LoadDLLIfNeeded())
  220.         return dllLoadError;
  221.     return (*DRSInit_Ptr)();
  222. }
  223.  
  224.  
  225. int DRSRead(int drstimer)
  226. {
  227.     int dllLoadError;
  228.  
  229.     if (dllLoadError = LoadDLLIfNeeded())
  230.         return dllLoadError;
  231.     return (*DRSRead_Ptr)(drstimer);
  232. }
  233.  
  234.  
  235. int DRSEnd()
  236. {
  237.     int dllLoadError;
  238.  
  239.     if (dllLoadError = LoadDLLIfNeeded())
  240.         return dllLoadError;
  241.     return (*DRSEnd_Ptr)();
  242. }
  243.  
  244.  
  245. int DRSToBuffer(unsigned char *p, int m_evSerial)
  246. {
  247.     int dllLoadError;
  248.  
  249.     if (dllLoadError = LoadDLLIfNeeded())
  250.         return dllLoadError;
  251.     return (*DRSToBuffer_Ptr)(p, m_evSerial);
  252. }
  253.  
  254.  
  255. int DRSIsTimeout()
  256. {
  257.     int dllLoadError;
  258.  
  259.     if (dllLoadError = LoadDLLIfNeeded())
  260.         return dllLoadError;
  261.     return (*DRSIsTimeout_Ptr)();
  262. }
  263.  
  264.  
  265. void DRSSetTimeout()
  266. {
  267.     int dllLoadError;
  268.  
  269.     if (dllLoadError = LoadDLLIfNeeded())
  270.         return;
  271.     (*DRSSetTimeout_Ptr)();
  272. }
  273.  
  274.  
  275. void DRSSigInt(int k)
  276. {
  277.     int dllLoadError;
  278.  
  279.     if (dllLoadError = LoadDLLIfNeeded())
  280.         return;
  281.     (*DRSSigInt_Ptr)(k);
  282. }
  283.  
  284.