Menu

getDevice(0) returns null

Help
mauro
2009-03-13
2013-04-15
  • mauro

    mauro - 2009-03-13

    Hi

    i downloaded the source code and compiled Tester.java under ubuntu linux.
    When i run the Tester class
    connection.getNumberDevices() returns 1, but
    connection.getDevice(0) returns null

    What should I check?

    Thanks,
    Mauro

     
    • Andi McLean

      Andi McLean - 2009-03-13

      This is a rather interesting problem.

      Have you tried
      connection.getDevices();

      which returns a vector of devices?

      and check the size of that and if it contains the device?

      Andi

       
    • mauro

      mauro - 2009-03-16

      I have modified the tester class to include a call to connection.getDevices().

          public Tester()
          {
              try
              {
                  JSane_Net_Connection connection = new JSane_Net_Connection("127.0.0.1", 6566);

                  System.out.println("> calling connection.getDevices()");

                  Vector v = connection.getDevices();

                  System.out.println("> end of connection.getDevices()");

                  int size = v.size();

                  System.out.println("size of connection.getDevices() => " + size);

                  for (int deviceNum = 0;
                      deviceNum < connection.getNumberDevices();
                      ++deviceNum)
                  {

                  ....
                  ....

      connection.getDevices() returns an empty vector, while getNumberDevices() still returns 1.

      In fact getDevices calls getNumberDevices which tests if _devices == null and since this happens it calls
      _devices = net_get_devices();

      The net_get_devices() method issues

      reply.devices = _wire.getPtrArray( dev );

      The getPtrArray method calls

      int size = getWord();

      This call returns 1, so getWord is called a second time

      isNull = getWord();

      and it returns 1 this time too, so

      vec.add(null)

      is executed.

      As a result the _devices.devices Vector has one element and this element is null. This explains why
      getNumberDevices returns 1 and getDevices() returns an empty vector.

      But i cannot explain why my device is not correctly detected.

      I enclose a log i have made (here also getWord is logged).

      > calling connection.getDevices()
      > start of getNumberDevices
      _devices == null
      > start of net_get_devices
      1st getbyte returns => 0
      value is => 0
      2nd getbyte returns => 0
      value is => 0
      3rd getbyte returns => 0
      value is => 0
      4th getbyte returns => 0
      value is => 0
      > start of getPtrArray
      1st getbyte returns => 0
      value is => 0
      2nd getbyte returns => 0
      value is => 0
      3rd getbyte returns => 0
      value is => 0
      4th getbyte returns => 1
      value is => 1
      > 1st getWord returns => 1
      1st getbyte returns => 0
      value is => 0
      2nd getbyte returns => 0
      value is => 0
      3rd getbyte returns => 0
      value is => 0
      4th getbyte returns => 1
      value is => 1
      > 2nd getWord returns => 1
      > getPtrArray returns a vector with size => 1
      first element of returned Vector is null
      > end of getPtrArray
      > end of net_get_devices
      getNumberDevices: _devices.devices has size => 1
      first element of _devices.devices is null
      > start of getNumberDevices
      > end of connection.getDevices()
      size of connection.getDevices() => 0

      I hope you can give some help.

      Thanks, Mauro

       
    • mauro

      mauro - 2009-03-16

      i believe the scanner is correctly installed because we can scan with scanimage

       
    • mauro

      mauro - 2009-03-16

      also, in net_get_devices i get reply.status = 0 (= SANE_STATUS_GOOD)

       
      • Andi McLean

        Andi McLean - 2009-03-16

        Thanks for the debugging.

        I'll add a check to make sure that null is not entered in to the vector.

        Have you tried performing scanimage -L on the same box as you are trying to run JSane and checking that the device is listed with a net: interface.

        Andi

         
    • mauro

      mauro - 2009-03-17

      it was a kind of problem with permissions, we have solved by starting saned with user = root and group = root.

      Mauro

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.