uk.co.mmscomputing twain scanner works with cannon scanner only

1k views Asked by At

I have a uk.co.mmscomputing applet for scanning through web application. It works fine with Cannon DR-9080C scanner. Recently I purchased Kodak i2600 scanner and it is not working with my applet. The scanner scans all pages in the tray when i click Acquire for the first time but when I load more pages and click Acquire again, I get "Java Stopped Working" error.

I tried setting up uk.co.mmscomputing again but it was not helpful.

package uk.co.mmscomputing.application.imageviewer;

import java.io.*;
import java.awt.image.*;
import javax.swing.*;
import uk.co.mmscomputing.device.scanner.*;

import uk.co.mmscomputing.device.twain.*;


public class ScannerTab extends ImageTab implements ScannerListener{

  static private int no=1;

  public ScannerTab(java.util.Properties properties){

      super(properties);
  }

  @Override
protected void setButtonPanel(JPanel gui){
    super.setButtonPanel(gui);

    try{


      Scanner scanner=Scanner.getDevice();            // get a device and set GUI panel up
      if(scanner!=null){
        gui.add(scanner.getScanGUI());
        scanner.addListener(this);

        if(scanner instanceof TwainScanner){
          TwainIdentity[] list=((TwainScanner)scanner).getIdentities();
          for(int i=0;i<list.length;i++){
            System.out.println(list[i].toString());
          }
        }
      }
    }catch(Exception e){
      System.out.println("9\b"+getClass().getName()+".setButtonPanel:\n\t"+e);
    }
  }

  public void update(ScannerIOMetadata.Type type, final ScannerIOMetadata metadata){
    if(type.equals(ScannerIOMetadata.ACQUIRED)){    // acquired BufferedImage
      final BufferedImage image=metadata.getImage();// make reference copy here to avoid race condition
      new Thread(){
        @Override
        public void run(){
          try{
            addImage("scan_"+(no++),image);
          }catch(Exception e){
            System.out.println("9\b"+getClass().getName()+".update:\n\t"+e);
            System.err.println(getClass().getName()+".update:\n\t"+e);
            e.printStackTrace();
          }
        }
      }.start();
    }else if(type.equals(ScannerIOMetadata.FILE)){  // acquired image as file (twain only for the time being)
      final File file=metadata.getFile();           // make reference copy here to avoid race condition
      new Thread(){
        @Override
        public void run(){
          try{
            open(file.getPath());
          }catch(Exception e){
            System.out.println("9\b"+getClass().getName()+".update:\n\t"+e);
            System.err.println(getClass().getName()+".update:\n\t"+e);
            e.printStackTrace();
          }finally{
            if(!file.delete()){
              System.out.println("9\b"+getClass().getName()+".update:\n\tCould not delete: "+file.getPath());
              System.err.println(getClass().getName()+".update:\n\tCould not delete: "+file.getPath());
            }
          }
        }
      }.start();
    }else if(type.equals(ScannerIOMetadata.NEGOTIATE)){
      negotiate(metadata);    
    }else if(type.equals(ScannerIOMetadata.STATECHANGE)){
      System.out.println("Scanner State "+metadata.getStateStr());

      if(metadata instanceof TwainIOMetadata){                                // TWAIN only ! 
        if(metadata.isState(TwainConstants.STATE_TRANSFERREADY)){             // state = 6
          TwainSource source = ((TwainIOMetadata)metadata).getSource();
          try{
            TwainImageInfo imageInfo=new TwainImageInfo(source);            
            imageInfo.get();
            System.out.println(imageInfo.toString());
          }catch(Exception e){
            System.out.println("3\b"+getClass().getName()+".update:\n\tCannot retrieve image information.\n\t"+e);
          }
          try{
            TwainImageLayout imageLayout=new TwainImageLayout(source);      
            imageLayout.get();
            System.out.println(imageLayout.toString());
          }catch(Exception e){
            System.out.println("3\b"+getClass().getName()+".update:\n\tCannot retrieve image layout.\n\t"+e);
          }
        }else if(metadata.isState(TwainConstants.STATE_TRANSFERRING)){       // state = 7

          TwainSource source = ((TwainIOMetadata)metadata).getSource();
          try{            
            int[] tweis=new int[0x1240-0x1200];
            for(int i=0;i<tweis.length;i++){tweis[i]=0x1200+i;}

            TwainExtImageInfo imageInfo=new TwainExtImageInfo(source,tweis);
            imageInfo.get();
            System.out.println(imageInfo.toString());
          }catch(Exception e){
            System.out.println("3\b"+getClass().getName()+".update:\n\tCannot retrieve extra image information.\n\t"+e);
          }
        }
      }

    }else if(type.equals(ScannerIOMetadata.INFO)){
      System.out.println(metadata.getInfo());
    }else if(type.equals(ScannerIOMetadata.EXCEPTION)){
      System.out.println("9\b"+metadata.getException().getMessage());
      metadata.getException().printStackTrace();
    }
  }

  private void negotiate(ScannerIOMetadata metadata){


    ScannerDevice sd=metadata.getDevice();                   // SANE & TWAIN
    try{
      sd.setShowUserInterface(false); 
      System.out.println("9\b"+e.getMessage());
    }


    if(metadata instanceof TwainIOMetadata){                 // TWAIN only!
      TwainSource source=((TwainIOMetadata)metadata).getSource();

      try{      
        TwainCapability[] caps=source.getCapabilities();     // print out all the capabilities
        for(int i=0;i<caps.length;i++){
          System.out.println(caps[i].toString());
        }
      }catch(Exception e){
        System.out.println("9\b"+e.getMessage());
      }

    }
  }
}
0

There are 0 answers