Ejemplo n.º 1
0
  public int getButtons() throws Exception {
    int[] intIOType = {0};
    int[] intChannel = {0};
    double[] dblValue = {0};
    // Variables to satisfy certain method signatures
    int[] dummyInt = {0};
    double[] dummyDouble = {0};
    long lngIteration;
    int intErrorcode;
    int ValueDIPort = 0;

    intErrorcode = LJUD.GoOne(intHandle[0]);
    ErrorHandler(intErrorcode, 0, new Exception());

    intErrorcode =
        LJUD.GetFirstResult(intHandle[0], intIOType, intChannel, dblValue, dummyInt, dummyDouble);
    ErrorHandler(intErrorcode, 0, new Exception());
    lngIteration = 0; // Used by the error handling function.
    while (intErrorcode < LJUD.LJE_MIN_GROUP_ERROR) {
      if (intIOType[0] == LJUDJavaConstants.LJ_ioGET_DIGITAL_PORT) {
        ValueDIPort = (int) dblValue[0];
      }

      intErrorcode =
          LJUD.GetNextResult(intHandle[0], intIOType, intChannel, dblValue, dummyInt, dummyDouble);

      if (intErrorcode != LJUD.LJE_NO_MORE_DATA_AVAILABLE) {
        ErrorHandler(intErrorcode, lngIteration, new Exception());
      }
      lngIteration++;
    }
    return ValueDIPort;
  }
Ejemplo n.º 2
0
  public static void ErrorHandler(int Errorcode, long Iteration, Exception excep) {
    byte[] err = new byte[255];

    if (Errorcode != LJUD.LJE_NOERROR) {
      LJUD.ErrorToString(Errorcode, err);
      System.out.println("Error number = " + Errorcode);
      System.out.println("Error string = " + new String(err));
      System.out.println("Iteration = " + Iteration);
      System.out.println("Stack Trace : ");
      excep.printStackTrace();
      if (Errorcode > LJUD.LJE_MIN_GROUP_ERROR) {
        // Quit if this is a group error.
        System.exit(1);
      }
    }
  }
Ejemplo n.º 3
0
  public MLSButtons() {
    // System.out.println("Button Constructor");
    try {
      System.loadLibrary("LJUDJava");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Library load failed. Where is LJUDJava.dll?\n" + e);
      System.exit(1);
    }

    // Open the first found LabJack.
    try {
      intErrorcode = LJUD.OpenLabJack(LJUD.LJ_dtU3, LJUD.LJ_ctUSB, "1", 1, intHandle);
      if (intErrorcode == LJUD.LJE_NOERROR) {
        labjackOpen = true;
      } else {
        labjackOpen = false;
        return;
      }
      ErrorHandler(intErrorcode, 0, new Exception());
    } catch (Exception elj) {
      labjackOpen = false;
      return;
    }
    // factory default condition.
    intErrorcode = LJUD.ePut(intHandle[0], LJUD.LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
    ErrorHandler(intErrorcode, 0, new Exception());

    // Configure quickSample.
    intErrorcode =
        LJUD.ePut(intHandle[0], LJUD.LJ_ioPUT_CONFIG, LJUD.LJ_chAIN_RESOLUTION, quickSample, 0);
    ErrorHandler(intErrorcode, 0, new Exception());

    // Configure longSettling.
    intErrorcode =
        LJUD.ePut(intHandle[0], LJUD.LJ_ioPUT_CONFIG, LJUD.LJ_chAIN_SETTLING_TIME, longSettling, 0);
    ErrorHandler(intErrorcode, 0, new Exception());

    // Configure the necessary lines as analog.
    intErrorcode = LJUD.ePut(intHandle[0], LJUD.LJ_ioPUT_ANALOG_ENABLE_PORT, 0, 0, 16);
    ErrorHandler(intErrorcode, 0, new Exception());
    // Now add requests that will be processed every iteration of the loop.
    // Read CIO digital lines.
    intErrorcode = LJUD.AddRequest(intHandle[0], LJUD.LJ_ioGET_DIGITAL_PORT, 0, 0, 9, 0);
    ErrorHandler(intErrorcode, 0, new Exception());
    System.err.println("End of LabJack initialization");
  }