Example #1
0
/* Implementation of pyk8055lib */

static int __pyx_f_10pyk8055lib_13K8055LibClass___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_10pyk8055lib_13K8055LibClass___cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_devname = 0;
  PyObject *__pyx_v_iRet;
  int __pyx_r;
  char *__pyx_1;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"devname",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_devname)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_devname);
  __pyx_v_iRet = Py_None; Py_INCREF(Py_None);

  /* "G:/Projekte/svn_mynew/svnroot/os2/usb/k8055/pyk8055/pyk8055lib.pyx":29 */
  if (__Pyx_PrintItem(__pyx_n_cinit) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;}
  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;}

  /* "G:/Projekte/svn_mynew/svnroot/os2/usb/k8055/pyk8055/pyk8055lib.pyx":30 */
  __pyx_1 = PyString_AsString(__pyx_v_devname); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;}
  ((struct __pyx_obj_10pyk8055lib_K8055LibClass *)__pyx_v_self)->pcDevName = __pyx_1;

  /* "G:/Projekte/svn_mynew/svnroot/os2/usb/k8055/pyk8055/pyk8055lib.pyx":31 */
  __pyx_2 = PyLong_FromUnsignedLong(K8055_Open(((struct __pyx_obj_10pyk8055lib_K8055LibClass *)__pyx_v_self)->pcDevName,(&((struct __pyx_obj_10pyk8055lib_K8055LibClass *)__pyx_v_self)->ulDevHandle))); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; goto __pyx_L1;}
  Py_DECREF(__pyx_v_iRet);
  __pyx_v_iRet = __pyx_2;
  __pyx_2 = 0;

  /* "G:/Projekte/svn_mynew/svnroot/os2/usb/k8055/pyk8055/pyk8055lib.pyx":32 */
  K8055_Init((&((struct __pyx_obj_10pyk8055lib_K8055LibClass *)__pyx_v_self)->ulDevHandle));

  /* "G:/Projekte/svn_mynew/svnroot/os2/usb/k8055/pyk8055/pyk8055lib.pyx":33 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("pyk8055lib.K8055LibClass.__cinit__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_iRet);
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_devname);
  return __pyx_r;
}
Example #2
0
void main( INT argc, CHAR* *argv )
{

  // -- Option derived variables ----

  INT    iOptChar;   // ASCII value of a
                     // Command Line Option Character

  BOOL   blTestsExplained;
  BOOL   blTestScreens;
  BOOL   blDisclaimerLock;

  // -- Variables concerning the USB Device Driver ----

  ULONG  hDevice;
  ULONG  *phDevice;
  CHAR   pszName[9] = "$"; // Refers to USBECD.SYS /N:$

  // -- K8055 input variables ----

  ULONG  ulInpIxValue;
  ULONG  ulInpA1value, ulInpA2value;
  ULONG  ulDecodedInpIxValue;
  ULONG  ulCounterValue;
  ULONG  ulCounterIndex;

  // -- K8055 output variables ----

  ULONG  ulDigitalOutValue;
  ULONG  ulDAC1value;
  ULONG  ulDAC2value;
  ULONG  ulDACidx;

  // -- Variables for user interaction ----

  BOOL   blDoTheMainMenuAgain;
  CHAR   szCmdKeys[33];
  ULONG  ulKeyCode;
  ULONG  ulKeyIdx;

  // -- Variables used in the Read-Test ----

  INT    iTableIdx;
  INT    iBlckCycl;
  ULONG  ulDisplayedValuesCount;

  // -- Variables used in the Read-Test ----

  INT    iByteCycl;

  // -- Variables for specific purposes ----
  //
  ULONG ulrc;       // Return Code for functions



  // -- Initialising Variables ---------- BEGIN ====

  blTestsExplained = FALSE;
  blTestScreens = TRUE;
  blDisclaimerLock = FALSE;

  blDoTheMainMenuAgain = TRUE;

  // -- Initialising Variables ------------ END ====


  // -- Processing Command Line Options ------------- BEGIN --/
  //
  while( ( iOptChar = getopt( argc, argv, "dihn:p?" ) ) != -1 )
  {
    switch( iOptChar )
    {
      case 'd':
        blDisclaimerLock = TRUE;
        break;

      case 'i':
        // -- Basic information on 'K8055DD.dll'.
        //
        blTestScreens = FALSE;
        printf("\n");
        ulrc = PrintingInfo();
        printf("\n");
        break;

      case 'h':
        // -- Printing list of options.
        //
        blTestScreens = FALSE;
        ulrc = PrintingCommandLineOptions();
        break;

      case 'n':
        // -- Passing the Device Name to the application.
        //
        strcpy( pszName, optarg );
        // -- Testaid -----
        // printf( "Device Name Option: '%s' ", pszName );
        blTestScreens = TRUE;
        break;

      case 'p':
        // -- Explaining every test in form of an intro.
        //
        blTestsExplained = TRUE;
        break;

      case '?':
        blTestScreens = FALSE;
        ulrc = PrintingCommandLineOptions();
        break;
    }
  }

  // -- Resolving Option Inconsistancy ------------

  // -- Testaid -----
  printf( "\n  Number of Cmd Line Options: '%#02d' ", argc );

  if ( argc == 1 )
  {
    blTestScreens = FALSE;
    ulrc = PrintingCommandLineOptions();
  }

  // -- 'exit(0)' Testaid for argument scanning ---
  //exit(0);


  // -- Processing Command Line Options --------------- END --/



  // -- Main Menu Key Section ----------------------- BEGIN --|

  if ( blTestScreens == TRUE )
  {

    // -- Main Menu Key Loop --------------------------- BL -))
    do
    {

      ulrc = PrintingHeadLine();

      if ( blDisclaimerLock == FALSE )
      {
        ulrc = PrintingDisclaimer();
        ulrc = PrintingDisclaimerHint();

        ulrc = PrintingGoodByePhrase();

        exit(0);

      }

      // -- The Main Menu -----------------------------------
      //
      printf("   Main menu \n\n");

      printf("\n     Reading from K8055.....................");
      printf("............. r ");
      printf("\n     Writing to K8055.......................");
      printf("............. w ");
      printf("\n ");
      printf("\n     Info on the Device Specific Library ");
      printf("K8055DD.dll .... i ");
      printf("\n     Disclaimer.............................");
      printf("............. d ");
      printf("\n     Quit...................................");
      printf("............. q ");
      printf("\n\n");
      printf("\n      Press one of the listed keys !");
      printf("\n");

      strcpy( szCmdKeys, "iIdDqQrRwW" );
      ulKeyCode = 0;
      ulKeyIdx = 0;
      ulrc = PollingForMenuKeyByCharArray( &szCmdKeys,
                                           &ulKeyCode,
                                           &ulKeyIdx   );

      // -- Testaid ---
      //    to check all return conditions of
      //    'PollingForMenuKeyByCharArray()'
      //
      //printf( "%hu , ", ulrc );
      //printf( "%hu , ", ulKeyCode );
      //printf( "%hu", ulKeyIdx );
      //exit(0);

      // -- Main Menu Function Selector --------- BEGIN ------&
      //
      switch( ulKeyCode )
      {
        //-- Showing Disclaimer -----------------------------
        //
        case 'd':
        case 'D':

          ulrc = PrintingHeadLine();
          ulrc = PrintingDisclaimer();

          printf("\n\n  Press  m  ");
          printf("to return to the Main Menu \n");
          strcpy( szCmdKeys, "mM" );
          ulKeyCode = 0;
          ulKeyIdx = 0;
          ulrc = PollingForMenuKeyByCharArray( &szCmdKeys,
                                               &ulKeyCode,
                                               &ulKeyIdx   );

          blDoTheMainMenuAgain = TRUE;

          break; //-- Showing Disclaimer, ready -------------

        //-- Showing info on 'K8055DD.dll' ------------------
        //
        case 'i':
        case 'I':

          if ( blTestsExplained == TRUE )
          {

            ulrc = PrintingHeadLine();
            ulrc = PrintingInfoPref();

            printf( "\n\n  Press  i  to start test \n" );
            strcpy( szCmdKeys, "iI" );
            ulKeyCode = 0;
            ulKeyIdx = 0;
            ulrc = PollingForMenuKeyByCharArray( &szCmdKeys,
                                                 &ulKeyCode,
                                                 &ulKeyIdx   );
          }

          ulrc = PrintingHeadLine();
          ulrc = PrintingInfoHeadLine( &pszName );

          // This function will call 'K8055_GetInfoStr()'
          ulrc = PrintingInfo();

          printf( "\n\n  Press  m  " );
          printf( "to return to the Main Menu \n" );
          strcpy( szCmdKeys, "mM" );
          ulKeyCode = 0;
          ulKeyIdx = 0;
          ulrc = PollingForMenuKeyByCharArray( &szCmdKeys,
                                               &ulKeyCode,
                                               &ulKeyIdx   );

          blDoTheMainMenuAgain = TRUE;

          break; //-- Showing info on 'K8055DD.dll', ready --

        //-- Test: Reading from K8055 -----------------------
        //
        case 'r':
        case 'R':

          if ( blTestsExplained == TRUE )
          {

            ulrc = PrintingHeadLine();
            ulrc = PrintingReadPref();

            printf( "\n\n  Press  r   to start the test \n" );

            strcpy( szCmdKeys, "rR" );
            ulKeyCode = 0;
            ulKeyIdx = 0;
            ulrc = PollingForMenuKeyByCharArray( &szCmdKeys,
                                                 &ulKeyCode,
                                                 &ulKeyIdx   );

          }

          phDevice = &hDevice;

          ulrc = K8055_Open( &pszName[0], phDevice );
          if (ulrc != 0)
          {
            printf( "\n\n Cannot open device " );
            printf( " '%s' ! ", pszName );

            ulrc = PrintingGoodByePhrase();
            exit(0);
          }
          else
          {

            // ----------------------------------------------
            // 'K8055_Init' reads descriptors and sets
            // the configuration as a K8055 needs it.
            //
            ulrc = K8055_Init( phDevice );
            if ( ulrc == 0 )
            {


              // -- Displays 5 tables of 5 value lines ---LB-
              //
              for( iTableIdx = 1;
                   iTableIdx <= 5;
                   iTableIdx++     )
              {

                // -- Extra time between two value tables.
                //
                sleep(1);

                ulrc = PrintingHeadLine();
                ulrc = PrintingHeadLineRead( iTableIdx,
                                             &pszName   );

                // -- Displays 5 value lines -------------LB-
                //
                for( iBlckCycl = 0;
                     iBlckCycl <= 5;
                     iBlckCycl++     )
                {

                  ulInpIxValue = 1;
                  ulInpA1value = 0;  ulInpA2value = 0;
                  ulrc = K8055_ReadAllInputs( phDevice,
                                              &ulInpIxValue,
                                              &ulInpA1value,
                                              &ulInpA2value  );

                  printf( "\n      " );
                  printf( "%#04x,   ", ulInpIxValue );

                  ulrc = K8055_DecodeDigitalInputs
                                      ( &ulInpIxValue,
                                        &ulDecodedInpIxValue );

                  printf( "%#04x  ",   ulDecodedInpIxValue );
                  printf( "  ( %#06b )", ulDecodedInpIxValue );
                  printf( " ³     " );
                  printf( "%#03d", ulInpA1value );

                  printf( "    " );
                  printf( "%#03d", ulInpA2value );

                  // -- Time between two value lines is app.
                  //    the same time as between two reading
                  //    operations.
                  //
                  sleep(1);

                }
                // -- Displays 5 value lines -------------LE-

              }
              // -- Displays 5 tables of 5 value lines ---LE-

              ulCounterValue = 0;
              // -- Obtaining impulses counted on I1 --
              ulCounterIndex = 1;
              ulrc = K8055_CheckIxCounter( &ulCounterValue,
                                           &ulCounterIndex );

              printf( "\n  Impulses counted on I1 =  " );
              printf( "%#06d ", ulCounterValue);

              // -- Obtaining impulses counted on I2 --
              ulCounterIndex = 2;
              ulrc = K8055_CheckIxCounter( &ulCounterValue,
                                           &ulCounterIndex );

              printf( "\n  Impulses counted on I2 =  " );
              printf( "%#06d ", ulCounterValue);

              ulrc = K8055_Close( phDevice );
              printf( " \n");
              printf( " Device '%s' closed.", pszName );

            }
            printf( "\n" );
            printf( " Test -Read- completed !" );

          }

          printf( "\n\n  Press  m  " );
          printf( "to return to the Main Menu \n" );
          strcpy( szCmdKeys, "mM" );
          ulKeyCode = 0;
          ulKeyIdx = 0;
          ulrc = PollingForMenuKeyByCharArray( &szCmdKeys,
                                               &ulKeyCode,
                                               &ulKeyIdx   );

          blDoTheMainMenuAgain = TRUE;

          break; //-- Test: Reading from K8055, ready -------

        //-- Test: Writing to K8055 -------------------------
        //
        case 'w':
        case 'W':

          if ( blTestsExplained == TRUE )
          {

            ulrc = PrintingHeadLine();
            ulrc = PrintingWritePref();

            printf( "\n\n  Press  w  to start the test \n" );

            strcpy( szCmdKeys, "wW" );
            ulKeyCode = 0;
            ulKeyIdx = 0;
            ulrc = PollingForMenuKeyByCharArray( &szCmdKeys,
                                                 &ulKeyCode,
                                                 &ulKeyIdx   );

          }

          ulrc = PrintingHeadLine();
          ulrc = PrintingHeadLineWrite( &pszName );

          phDevice = &hDevice;

          ulrc = K8055_Open( &pszName[0], phDevice );
          if ( ulrc != 0 )
          {
            printf( "\n\n Cannot open device " );
            printf( " '%s' ! ", pszName );

            ulrc = PrintingGoodByePhrase();
            exit(0);
          }
          else
          {

            // ----------------------------------------------
            // 'K8055_Init' reads descriptors and sets the
            // configuration as a K8055 needs it.
            //
            ulrc = K8055_Init( phDevice );
            if ( ulrc == 0 )
            {

              ulDisplayedValuesCount = 0;
              for( iByteCycl = 0;
                   iByteCycl <= 255;
                   iByteCycl++ )
              {

                delay(5);

                ulDigitalOutValue = iByteCycl;
                ulrc = K8055_PrepairDigitalOut
                                        ( &ulDigitalOutValue );

                // -- Selecting DAC1, going upwards -----
                ulDACidx = 1;
                ulDAC1value = iByteCycl;
                ulrc = K8055_PrepairDACxOut( &ulDAC1value,
                                             &ulDACidx     );

                // -- Selecting DAC2, going downwards ---
                ulDACidx = 2;
                ulDAC2value = 255 - iByteCycl;
                ulrc = K8055_PrepairDACxOut( &ulDAC2value,
                                             &ulDACidx     );

                ulrc = K8055_SetAllOutputs( phDevice );

                if ( ulDisplayedValuesCount == 24 )
                {
                  ulDisplayedValuesCount = 0;
                  printf( "\n" );
                }
                ++ulDisplayedValuesCount;
                printf( " %02X", iByteCycl );

                delay(5);

              }

              ulrc = K8055_Close( phDevice );
              printf( " \n");
              printf( " Device '%s' closed.", pszName );

            }
            printf( "\n" );
            printf( " Test -Write- completed !" );
          }

          printf("\n\n  Press  m  ");
          printf("to return to the Main Menu \n");
          strcpy( szCmdKeys, "mM" );
          ulKeyCode = 0;
          ulKeyIdx = 0;
          ulrc = PollingForMenuKeyByCharArray( &szCmdKeys,
                                               &ulKeyCode,
                                               &ulKeyIdx   );

          blDoTheMainMenuAgain = TRUE;

          break; //-- Test: Writing to K8055, ready ---------

        //-- Qitting Main Menu ------------------------------
        //
        case 'q':
        case 'Q':

          printf( " \n");
          printf( " -Quit- selected !" );

          blDoTheMainMenuAgain = FALSE;

          break; //-- Quitting Main Menu, ready -------------


      }
      //
      // -- Main Menu Function Selector ----------- END ------&


    } while ( blDoTheMainMenuAgain == TRUE );
    //
    // -- Main Menu Key Loop --------------------------- EL -))

  }
  else
  {
    //empty
  }
  // -- Main Menu Key Section ------------------------- END --|

  ulrc = PrintingGoodByePhrase();

  exit(0);

}