2

I want to connect sharp network scanner using morena api and twain. Everything is ok if scanner is reachable but when scanner is not reachable, jni library opens a select scanner window. I think it is twain ds screen, I want to disable this screen. If scanner is not reachable, I want to throw error instead of open select device window. When I stop application, this screen also close so I think it depends on java thread. Question is, how can I stop this window's thread without stop whole program. I can run main method in another thread, and I can find this thread id, but when I stop this thread it is not close select device window.

import SK.gnome.morena.Morena;
import SK.gnome.morena.MorenaException;
import SK.gnome.morena.MorenaImage;
import SK.gnome.morena.MorenaSource;
import SK.gnome.twain.TwainManager;
import SK.gnome.twain.TwainSource;

import javax.swing.*;

public class HelloWorld
{ public static void main(String[] args) throws MorenaException
  {

    TwainSource[] list = null;

    try {
      list = TwainManager.listSources();
    } catch (Exception var4) {
      list = null;
    }



    MorenaSource source= list[1];
    System.err.println("Selected source is "+source);
    if (source!=null)
    { source.maskUnsupportedCapabilityException(false); // Lesson 3
      source.maskBadValueException(false);              // Lesson 3
      source.setVisible(false);                         // Lesson 2
      source.setColorMode();                            // Lesson 2
      source.setResolution(300);                        // Lesson 2
      ((TwainSource)source).setUnits(TwainSource.TWUN_CENTIMETERS);
      source.setFrame(0, 0, 7.8, 10.5);
      System.err.println("Image resolution is "+source.getResolution());
      MorenaImage image=new MorenaImage(source);
      System.err.println("Size of acquired image is "
           +image.getWidth()+" x "
           +image.getHeight()+" x "
           +image.getPixelSize());
    }
    Morena.close();
  }
}

enter image description here

maskapsiz
  • 244
  • 5
  • 23

1 Answers1

1

Do you ever want the window itself to pop up? If not you can try TwainManager.getDefaultSource() instead of hardcoding list[1], or TwainManager.listSources() to either build your own selection or evaluate for 0 results and throw your own error.

To use TwainManager.getDefaultSource():

MorenaSource source = TwainManager.listSources();

See Morena's TWAIN JTP Support for more info.

MaKR
  • 1,882
  • 2
  • 17
  • 29