Ver Mensaje Individual
  #8 (permalink)  
Antiguo 06/06/2010, 16:17
fj87
 
Fecha de Ingreso: junio-2010
Mensajes: 17
Antigüedad: 14 años, 5 meses
Puntos: 0
Respuesta: Tarjeta de adquisicion

Es cierto, ha sido un error mio.

Supongamos que tengo un programa de este estilo (es el programa de ejemplo de la SDK de la tarjeta de adquisicion). Para hacer algo similar en python, de que manera deberia de actuar?

Que solución considerais más adecuada? uso de ctypes o por el contrario elaborar un wrapper? Podrías darme alguna noción de como actuar con ello?

Muchas gracias!
y nuevamente, perdón por saltarme las normas del foro.

un saludo

Código C:
Ver original
  1. /*
  2. FUNCTIONS:
  3.  
  4.     WinMain()        gets handle to ADC subsystem, configures ADC for
  5.                      continuous operation, opens a dialog box to receive
  6.                      window messages, and performs continuous operation
  7.                      on the ADC.
  8.     GetDriver()      callback to get board name and open board, opens
  9.                      the first available Open Layers board.
  10.     OutputBox()      dialog box to handle information and error window
  11.                      messages from the ADC subsystem.
  12.  
  13. */
  14. #include <windows.h>    
  15. #include <stdlib.h>    
  16. #include <stdio.h>    
  17. #include <olmem.h>        
  18. #include <olerrors.h>        
  19. #include <oldaapi.h>
  20. #include "contadc.h"
  21.  
  22. #define NUM_BUFFERS 4
  23. #define STRLEN 80        /* string size for general text manipulation   */
  24. char str[STRLEN];        /* global string for general text manipulation */
  25.  
  26. /* Error handling macros */
  27. #define SHOW_ERROR(ecode) MessageBox(HWND_DESKTOP,olDaGetErrorString(ecode,\
  28.                   str,STRLEN),"Error", MB_ICONEXCLAMATION | MB_OK);
  29.  
  30. #define CHECKERROR(ecode) if ((board.status = (ecode)) != OLNOERROR)\
  31.                   {\
  32.                   SHOW_ERROR(board.status);\
  33.                   olDaReleaseDASS(board.hdass);\
  34.                   olDaTerminate(board.hdrvr);\
  35.                   return ((UINT)NULL);}
  36.  
  37. #define CLOSEONERROR(ecode) if ((board.status = (ecode)) != OLNOERROR)\
  38.                   {\
  39.                   SHOW_ERROR(board.status);\
  40.                   olDaReleaseDASS(board.hdass);\
  41.                   olDaTerminate(board.hdrvr);\
  42.                   EndDialog(hDlg, TRUE);\
  43.                   return (TRUE);}
  44.  
  45. /* simple structure used with board */
  46. typedef struct tag_board {
  47.    HDEV  hdrvr;        /* device handle            */
  48.    HDASS hdass;        /* sub system handle        */
  49.    ECODE status;       /* board error status       */
  50.    char name[MAX_BOARD_NAME_LENGTH];  /* string for board name    */
  51.    char entry[MAX_BOARD_NAME_LENGTH]; /* string for board name    */
  52. } BOARD;
  53.  
  54. typedef BOARD* LPBOARD;
  55. static BOARD board;
  56. static ULNG count = 0;
  57.  
  58. BOOL CALLBACK
  59. GetDriver( LPSTR lpszName, LPSTR lpszEntry, LPARAM lParam )  
  60. /*
  61. this is a callback function of olDaEnumBoards, it gets the
  62. strings of the Open Layers board and attempts to initialize
  63. the board.  If successful, enumeration is halted.
  64. */
  65. {
  66.    LPBOARD lpboard = (LPBOARD)(LPVOID)lParam;
  67.    
  68.    /* fill in board strings */
  69.  
  70.    lstrcpyn(lpboard->name,lpszName,MAX_BOARD_NAME_LENGTH-1);
  71.    lstrcpyn(lpboard->entry,lpszEntry,MAX_BOARD_NAME_LENGTH-1);
  72.  
  73.    /* try to open board */
  74.  
  75.    lpboard->status = olDaInitialize(lpszName,&lpboard->hdrvr);
  76.    if   (lpboard->hdrvr != NULL)
  77.       return FALSE;          /* false to stop enumerating */
  78.    else                      
  79.       return TRUE;           /* true to continue          */
  80. }
  81. BOOL CALLBACK
  82. InputBox( HWND hDlg,
  83.           UINT message,
  84.           WPARAM wParam,
  85.           LPARAM lParam )
  86. /*
  87. This function processes messages for "Input" dialog box
  88. */
  89. {
  90.    DBL min=0,max=0;
  91.    DBL volts;
  92.    ULNG value;
  93.    ULNG samples;
  94.    UINT encoding=0,resolution=0;
  95.    HBUF  hBuffer = NULL;
  96.    PDWORD  pBuffer32 = NULL;
  97.    PWORD  pBuffer = NULL;
  98.    char WindowTitle[128];
  99.    char temp[128];    
  100.    DASSINFO ssinfo;
  101.  
  102.  
  103.    switch (message) {
  104.       case WM_INITDIALOG:   /* message: initialize dialog box  */
  105.          
  106.          /* set the title to the board name */
  107.          
  108.          olDaGetDASSInfo(board.hdass,&ssinfo);
  109.          itoa(ssinfo.uiElement,temp,10);
  110.          strncpy(WindowTitle,board.name,128);
  111.          strncat(WindowTitle," Element # ",128);
  112.          strncat(WindowTitle,temp,128);
  113.  
  114.          SetWindowText(hDlg,WindowTitle);
  115.            
  116.  
  117.          /* set window handle and configure sub system */
  118.          
  119.          CLOSEONERROR (olDaSetWndHandle(board.hdass, hDlg,(UINT)NULL));
  120.          CLOSEONERROR (olDaConfig(board.hdass));
  121.  
  122.          /* start sub system */
  123.  
  124.          CLOSEONERROR (olDaStart(board.hdass));
  125.          return (TRUE);   /* Did process a message */
  126.  
  127.       case OLDA_WM_BUFFER_REUSED:   /* message: buffer reused  */
  128.          break;
  129.  
  130.       case OLDA_WM_BUFFER_DONE:     /* message: buffer done  */
  131.  
  132.          /* get buffer off done list */
  133.  
  134.          CHECKERROR (olDaGetBuffer(board.hdass, &hBuffer));
  135.  
  136.          /* if there is a buffer */
  137.  
  138.          if( hBuffer )
  139.          {
  140.  
  141.              /* get sub system information for code/volts conversion */
  142.  
  143.              CLOSEONERROR (olDaGetRange(board.hdass,&max,&min));
  144.              CLOSEONERROR (olDaGetEncoding(board.hdass,&encoding));
  145.              CLOSEONERROR (olDaGetResolution(board.hdass,&resolution));
  146.  
  147.             /* get max samples in input buffer */
  148.  
  149.             CLOSEONERROR (olDmGetValidSamples( hBuffer, &samples ) );
  150.  
  151.             /* get pointer to the buffer */
  152.             if (resolution > 16)
  153.             {
  154.             CLOSEONERROR (olDmGetBufferPtr( hBuffer,(LPVOID*)&pBuffer32));
  155.             /* get last sample in buffer */
  156.             value = pBuffer32[samples-1];
  157.             }
  158.             else
  159.             {
  160.             CLOSEONERROR (olDmGetBufferPtr( hBuffer,(LPVOID*)&pBuffer));
  161.             /* get last sample in buffer */
  162.             value = pBuffer[samples-1];
  163.             }
  164.             /* put buffer back to ready list */
  165.  
  166.             CHECKERROR (olDaPutBuffer(board.hdass, hBuffer));
  167.          
  168.             /*  convert value to volts */
  169.  
  170.             if (encoding != OL_ENC_BINARY)
  171.             {
  172.                /* convert to offset binary by inverting the sign bit */
  173.      
  174.                value ^= 1L << (resolution-1);
  175.                value &= (1L << resolution) - 1;     /* zero upper bits */
  176.             }
  177.    
  178.             volts = ((float)max-(float)min)/(1L<<resolution)*value + (float)min;
  179.  
  180.             /* display value */
  181.    
  182.             sprintf(str,"%.3f Volts",volts);
  183.             SetDlgItemText (hDlg, IDD_VALUE, str);
  184.          }
  185.          return (TRUE);   /* Did process a message */
  186.          
  187.       case OLDA_WM_QUEUE_DONE:
  188.       case OLDA_WM_QUEUE_STOPPED:
  189.          /* using wrap multiple - if these message are received */
  190.          /* acquisition has stopped.                            */
  191.    
  192.          EndDialog(hDlg, TRUE);
  193.          return (TRUE);   /* Did process a message */
  194.    
  195.       case OLDA_WM_TRIGGER_ERROR:
  196.          /* Process trigger error message */
  197.  
  198.          MessageBox(hDlg,"Trigger error: acquisition stopped",
  199.                   "Error", MB_ICONEXCLAMATION | MB_OK);
  200.          EndDialog(hDlg, TRUE);
  201.          return (TRUE);   /* Did process a message */
  202.        
  203.       case OLDA_WM_OVERRUN_ERROR:
  204.          /* Process underrun error message */
  205.        
  206.          MessageBox(hDlg,"Input overrun error: acquisition stopped",
  207.                   "Error", MB_ICONEXCLAMATION | MB_OK);
  208.          EndDialog(hDlg, TRUE);   /* Did process a message */
  209.          return (TRUE);   /* Did process a message */
  210.  
  211.       case WM_COMMAND:      /* message: received a command */
  212.  
  213.          switch ( LOWORD(wParam) )  {
  214.             case IDOK:
  215.             case IDCANCEL:
  216.                CLOSEONERROR (olDaAbort(board.hdass));
  217.                EndDialog(hDlg, TRUE);
  218.                return (TRUE);   /* Did process a message */
  219.          }
  220.          break;  
  221.     }                              
  222.     return (FALSE);               /* Didn't process a message */
  223. }