1/* sane - Scanner Access Now Easy. 2 Copyright (C) 1997 Jeffrey S. Freedman 3 This file is part of the SANE package. 4 5 This program is free software; you can redistribute it and/or 6 modify it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 2 of the 8 License, or (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <https://www.gnu.org/licenses/>. 17 18 As a special exception, the authors of SANE give permission for 19 additional uses of the libraries contained in this release of SANE. 20 21 The exception is that, if you link a SANE library with other files 22 to produce an executable, this does not by itself cause the 23 resulting executable to be covered by the GNU General Public 24 License. Your use of that executable is in no way restricted on 25 account of linking the SANE library code into it. 26 27 This exception does not, however, invalidate any other reasons why 28 the executable file might be covered by the GNU General Public 29 License. 30 31 If you submit changes to SANE to the maintainers to be included in 32 a subsequent release, you agree by submitting the changes that 33 those changes may be distributed with this exception intact. 34 35 If you write modifications of your own for SANE, it is your choice 36 whether to permit this exception to apply to your modifications. 37 If you do not wish that, delete this exception notice. */ 38 39class Test 40{ 41public static void main(String[] args) 42 { 43 Sane sane = new Sane(); 44 int version[] = new int[1]; // Array to get version #. 45 int status = sane.init(version); 46 if (status != Sane.STATUS_GOOD) 47 { 48 System.out.println("getDevices() failed. Status= " + status); 49 return; 50 } 51 System.out.println("VersionMajor =" + sane.versionMajor(version[0])); 52 System.out.println("VersionMinor =" + sane.versionMinor(version[0])); 53 System.out.println("VersionBuild =" + sane.versionBuild(version[0])); 54 // Get list of devices. 55 // Allocate room for 50. 56 SaneDevice devList[] = new SaneDevice[50]; 57 status = sane.getDevices(devList, false); 58 if (status != Sane.STATUS_GOOD) 59 { 60 System.out.println("getDevices() failed. Status= " + status); 61 return; 62 } 63 for (int i = 0; i < 50 && devList[i] != null; i++) 64 { 65 System.out.println("Device '" + devList[i].name + "' is a " + 66 devList[i].vendor + " " + devList[i].model + " " + 67 devList[i].type); 68 } 69 int handle[] = new int[1]; 70 status = sane.open(devList[0].name, handle); 71 if (status != Sane.STATUS_GOOD) 72 { 73 System.out.println("open() failed. Status= " + status); 74 return; 75 } 76 System.out.println("Open handle=" + handle[0]); 77 // Get # of device options. 78 int numDevOptions[] = new int[1]; 79 status = sane.getControlOption(handle[0], 0, numDevOptions, null); 80 if (status != Sane.STATUS_GOOD) 81 { 82 System.out.println("controlOption() failed. Status= " 83 + status); 84 return; 85 } 86 System.out.println("Number of device options=" + numDevOptions[0]); 87 for (int i = 0; i < numDevOptions[0]; i++) 88 { 89 SaneOption opt = sane.getOptionDescriptor(handle[0], i); 90 if (opt == null) 91 { 92 System.out.println("getOptionDescriptor() failed for " 93 + i); 94 continue; 95 } 96 System.out.println("Option name: " + opt.name); 97 System.out.println("Option title: " + opt.title); 98 System.out.println("Option desc: " + opt.desc); 99 switch (opt.constraintType) 100 { 101 case SaneOption.CONSTRAINT_RANGE: 102 System.out.println("Range: " + 103 opt.rangeConstraint.min + ", " + 104 opt.rangeConstraint.max + ", " + 105 opt.rangeConstraint.quant); 106 break; 107 case SaneOption.CONSTRAINT_WORD_LIST: 108 System.out.print("Word list: "); 109 for (int j = 0; j < opt.wordListConstraint[0]; j++) 110 System.out.print(opt.wordListConstraint[j]); 111 System.out.println(); 112 break; 113 case SaneOption.CONSTRAINT_STRING_LIST: 114 for (int j = 0; opt.stringListConstraint[j] != null; 115 j++) 116 System.out.print("String constraint: " + 117 opt.stringListConstraint[j]); 118 break; 119 default: 120 System.out.println("No constraint."); 121 break; 122 } 123 } 124 status = sane.setControlOption(handle[0], 2, 125 SaneOption.ACTION_SET_VALUE, "../test1.pnm", null); 126 if (status != Sane.STATUS_GOOD) 127 { 128 System.out.println("setControlOption() failed. Status= " 129 + status); 130 } 131 // 132 // Main scanning loop. 133 // 134 SaneParameters parm = new SaneParameters(); 135 int dataLen = 32*1024; 136 byte [] data = new byte[dataLen]; 137 int [] readLen = new int[1]; 138 int frameCnt = 0; 139 do 140 { 141 frameCnt++; 142 System.out.println("Reading frame #" + frameCnt); 143 status = sane.start(handle[0]); 144 if (status != Sane.STATUS_GOOD) 145 { 146 System.out.println("start() failed. Status= " 147 + status); 148 return; 149 } 150 status = sane.getParameters(handle[0], parm); 151 if (status != Sane.STATUS_GOOD) 152 { 153 System.out.println("getParameters() failed. Status= " 154 + status); 155 return; //++++cleanup. 156 } 157 while ((status = sane.read(handle[0], data, dataLen, readLen)) 158 == Sane.STATUS_GOOD) 159 { 160 System.out.println("Read " + readLen[0] + " bytes."); 161 // ++++++++Process data. 162 } 163 if (status != Sane.STATUS_EOF) 164 { 165 System.out.println("read() failed. Status= " 166 + status); 167 } 168 } 169 while (!parm.lastFrame); 170 171 sane.close(handle[0]); 172 } 173} 174