Exemplo n.º 1
0
  /** Wraps access to the specified camera. */
  public Kodak(Device dev) throws IOException {
    try {
      // can we use usbdevfs?
      socket = new USBSocket(dev);
      in = socket.getInputStream();
      out = socket.getOutputStream();

    } catch (IOException e) {

      if ("Linux".equals(System.getProperty("os.name"))) {
        // assume this is the LOCAL implementation
        // semantics are like a half duplex packet stream socket

        // assume just one camera (kernel handles up to 16)
        // single open, per the driver's exclusion policy
        random = new RandomAccessFile("/dev/usb/dc2xx0", "rw");
        in = new InputHack(random);
        out = new OutputHack(random);
      } else {
        throw e;
      }

      // NOTE:  GCJ 2.96 bug on this path ... putting this
      // call here evidently prevented the constructor from
      // returning a null object.  Strange.
      System.err.print("");
    }
    getCameraStatus();
    getCameraType(); // ensures it's a supported camera type
  }
Exemplo n.º 2
0
  /**
   * Updates the local copy of the camera status table, and returns a copy of it. The format of this
   * data is in section 3.1 of the DC-280 specification; that is a superset of previous models
   * including the dc240. Note that this table snapshots the camera's notion of the current time.
   */
  public byte[] getCameraStatus() throws IOException {
    // this is how NOT to do it!
    // no error handling, no framework for other calls.

    byte temp[] = new byte[8];
    byte response[] = new byte[258];
    int len;

    temp[0] = 0x7F; // send camera status table
    temp[7] = 0x1A;

    // write command, receive ack
    out.write(temp, 0, temp.length);
    len = in.read(temp, 0, 1);
    if (len != 1 || temp[0] != KODAK_ACK) throw new IOException("needed ACK");

    // get, check, and ack response (ignoring packet checksum!)
    len = in.read(response);
    if (len != 258 || temp[0] != KODAK_ACK) throw new IOException("needed status packet");
    response[0] = KODAK_CORRECT;
    out.write(response, 0, 1);

    // copy and save the table
    temp = new byte[256];
    System.arraycopy(response, 1, temp, 0, 256);
    statusTable = temp;

    // also copy a return value
    temp = new byte[256];
    System.arraycopy(response, 1, temp, 0, 256);

    // get and check ACK
    len = in.read(temp, 0, 1);
    if (len != 1 || temp[0] != KODAK_COMPLETED) throw new IOException("needed ACK2");

    return temp;
  }
Exemplo n.º 3
0
  public static void main(String argv[]) {
    Bus busses[] = null;
    Host host;

    try {

      // FIXME:  option flag for rmi (iiop?) host:port spec.

      host = HostFactory.getHost();
      if (host == null) {
        System.err.println("USB is unavailable, can't run.");
        return;
      }

      System.out.println("<!-- " + host + " -->");

      busses = host.getBusses();
      indentLine(0, "<host busses='" + busses.length + "'>");
      for (int busno = 0; busno < busses.length; busno++) {
        indentLine(2, "<!-- Bus #" + (busno + 1) + " -->");
        // show tree from root hub
        if (busses[busno] != null) {
          try {
            printDevice(2, busses[busno].getRootHub());
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
      indentLine(0, "</host>");

    } catch (SecurityException e) {
      System.err.println("USB permissions problem:");
      System.err.println(e.getMessage());
      System.exit(1);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }