Debian Codegraph @

src/gnu/io/RXTXCommDriver.java

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 /*-------------------------------------------------------------------------
2 | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface.
3 | RXTX is a native interface to serial ports in java.
4 | Copyright 1998 Kevin Hester, [email protected]
5 | Copyright 2000-2008 Trent Jarvi [email protected] and others who
6 | actually wrote it. See individual source files for more information.
7 |
8 | A copy of the LGPL v 2.1 may be found at
9 | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is
10 | here for your convenience.
11 |
12 | This library is free software; you can redistribute it and/or
13 | modify it under the terms of the GNU Lesser General Public
14 | License as published by the Free Software Foundation; either
15 | version 2.1 of the License, or (at your option) any later version.
16 |
17 | This library is distributed in the hope that it will be useful,
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 | Lesser General Public License for more details.
21 |
22 | An executable that contains no derivative of any portion of RXTX, but
23 | is designed to work with RXTX by being dynamically linked with it,
24 | is considered a "work that uses the Library" subject to the terms and
25 | conditions of the GNU Lesser General Public License.
26 |
27 | The following has been added to the RXTX License to remove
28 | any confusion about linking to RXTX. We want to allow in part what
29 | section 5, paragraph 2 of the LGPL does not permit in the special
30 | case of linking over a controlled interface. The intent is to add a
31 | Java Specification Request or standards body defined interface in the
32 | future as another exception but one is not currently available.
33 |
34 | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface
35 |
36 | As a special exception, the copyright holders of RXTX give you
37 | permission to link RXTX with independent modules that communicate with
38 | RXTX solely through the Sun Microsytems CommAPI interface version 2,
39 | regardless of the license terms of these independent modules, and to copy
40 | and distribute the resulting combined work under terms of your choice,
41 | provided that every copy of the combined work is accompanied by a complete
42 | copy of the source code of RXTX (the version of RXTX used to produce the
43 | combined work), being distributed under the terms of the GNU Lesser General
44 | Public License plus this exception. An independent module is a
45 | module which is not derived from or based on RXTX.
46 |
47 | Note that people who make modified versions of RXTX are not obligated
48 | to grant this special exception for their modified versions; it is
49 | their choice whether to do so. The GNU Lesser General Public License
50 | gives permission to release a modified version without this exception; this
51 | exception also makes it possible to release a modified version which
52 | carries forward this exception.
53 |
54 | You should have received a copy of the GNU Lesser General Public
55 | License along with this library; if not, write to the Free
56 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
57 | All trademarks belong to their respective owners.
58 --------------------------------------------------------------------------*/
59 /* Martin Pool <[email protected]> added support for explicitly-specified
60 * lists of ports, October 2000. */
61 /* Joseph Goldstone <[email protected]> reorganized to support registered ports,
62 * known ports, and scanned ports, July 2001 */
63
64 package gnu.io;
65
66 import java.lang.*;
67 import java.util.*;
68 import java.io.*;
69 import java.util.StringTokenizer;
70
71 /**
72 This is the JavaComm for Linux driver.
73 */
74 public class RXTXCommDriver implements CommDriver
75 {
76
77 private final static boolean debug = false;
78 private final static boolean devel = false;
79 private final static boolean noVersionOutput = "true".equals( System.getProperty( "gnu.io.rxtx.NoVersionOutput" ) );
80
81 static
82 {
83 if(debug ) System.out.println("RXTXCommDriver {}");
84 System.loadLibrary( "rxtxSerial" );
85
86 /*
87 Perform a crude check to make sure people don't mix
88 versions of the Jar and native lib
89
90 Mixing the libs can create a nightmare.
91
92 It could be possible to move this over to RXTXVersion
93 but All we want to do is warn people when first loading
94 the Library.
95 */
96 String JarVersion = RXTXVersion.getVersion();
97 String LibVersion;
98 try {
99 LibVersion = RXTXVersion.nativeGetVersion();
100 } catch ( Error UnsatisfiedLinkError )
101 {
102 // for rxtx prior to 2.1.7
103 LibVersion = nativeGetVersion();
104 }
105 if ( devel )
106 {
107 if ( ! noVersionOutput )
108 {
109 System.out.println("Stable Library");
110 System.out.println("=========================================");
111 System.out.println("Native lib Version = " + LibVersion );
112 System.out.println("Java lib Version = " + JarVersion );
113 }
114 }
115
116 if ( ! JarVersion.equals( LibVersion ) )
117 {
118 System.out.println( "WARNING: RXTX Version mismatch\n\tJar version = " + JarVersion + "\n\tnative lib Version = " + LibVersion );
119 }
120 else if ( debug )
121 {
122 System.out.println( "RXTXCommDriver:\n\tJar version = " + JarVersion + "\n\tnative lib Version = " + LibVersion );
123 }
124 }
125
126 /** Get the Serial port prefixes for the running OS */
127 private String deviceDirectory;
128 private String osName;
129 private native boolean registerKnownPorts(int PortType);
130 private native boolean isPortPrefixValid(String dev);
131 private native boolean testRead(String dev, int type);
132 private native String getDeviceDirectory();
133 // for rxtx prior to 2.1.7
134 public static native String nativeGetVersion();
135
136 private final String[] getValidPortPrefixes(String CandidatePortPrefixes[])
137 {
138 /*
139 256 is the number of prefixes ( COM, cua, ttyS, ...) not
140 the number of devices (ttyS0, ttyS1, ttyS2, ...)
141
142 On a Linux system there are about 400 prefixes in
143 deviceDirectory.
144 registerScannedPorts() assigns CandidatePortPrefixes to
145 something less than 50 prefixes.
146
147 Trent
148 */
149
150 String ValidPortPrefixes[]=new String [256];
151 if (debug)
152 System.out.println("\nRXTXCommDriver:getValidPortPrefixes()");
153 if(CandidatePortPrefixes==null)
154 {
155 if (debug)
156 System.out.println("\nRXTXCommDriver:getValidPortPrefixes() No ports prefixes known for this System.\nPlease check the port prefixes listed for " + osName + " in RXTXCommDriver:registerScannedPorts()\n");
157 }
158 int i=0;
159 for(int j=0;j<CandidatePortPrefixes.length;j++){
160 if(isPortPrefixValid(CandidatePortPrefixes[j])) {
161 ValidPortPrefixes[i++]=
162 CandidatePortPrefixes[j];
163 }
164 }
165 String[] returnArray=new String[i];
166 System.arraycopy(ValidPortPrefixes, 0, returnArray, 0, i);
167 if(ValidPortPrefixes[0]==null)
168 {
169 if (debug)
170 {
171 System.out.println("\nRXTXCommDriver:getValidPortPrefixes() No ports matched the list assumed for this\nSystem in the directory " + deviceDirectory + ". Please check the ports listed for \"" + osName + "\" in\nRXTXCommDriver:registerScannedPorts()\nTried:");
172 for(int j=0;j<CandidatePortPrefixes.length;j++){
173 System.out.println("\t" +
174 CandidatePortPrefixes[i]);
175 }
176 }
177 }
178 else
179 {
180 if (debug)
181 System.out.println("\nRXTXCommDriver:getValidPortPrefixes()\nThe following port prefixes have been identified as valid on " + osName + ":\n");
182 /*
183 for(int j=0;j<returnArray.length;j++)
184 {
185 if (debug)
186 System.out.println("\t" + j + " " +
187 returnArray[j]);
188 }
189 */
190 }
191 return returnArray;
192 }
193
194 /** handle solaris/sunos /dev/cua/a convention */
195 private void checkSolaris(String PortName, int PortType)
196 {
197 char p[] = { 91 };
198 for( p[0] =97 ;p[0] < 123; p[0]++ )
199 {
200 if (testRead(PortName.concat(new String(p)),PortType))
201 {
202 CommPortIdentifier.addPortName(
203 PortName.concat(new String(p)),
204 PortType,
205 this
206 );
207 }
208 }
209 /** check for 0-9 in case we have them (Solaris USB) */
210 for( p[0] =48 ;p[0] <= 57; p[0]++ )
211 {
212 if (testRead(PortName.concat(new String(p)),PortType))
213 {
214 CommPortIdentifier.addPortName(
215 PortName.concat(new String(p)),
216 PortType,
217 this
218 );
219 }
220 }
221 }
222 private void registerValidPorts(
223 String CandidateDeviceNames[],
224 String ValidPortPrefixes[],
225 int PortType
226 ) {
227 int i =0;
228 int p =0 ;
229 /* FIXME quick fix to get COM1-8 on windows working. The
230 Read test is not working properly and its crunch time...
231 if(osName.toLowerCase().indexOf("windows") != -1 )
232 {
233 for( i=0;i < CandidateDeviceNames.length;i++ )
234 {
235 CommPortIdentifier.addPortName( CandidateDeviceNames[i],
236 PortType, this );
237 }
238 return;
239
240 }
241 */
242 if (debug)
243 {
244 System.out.println("Entering registerValidPorts()");
245 /* */
246 System.out.println(" Candidate devices:");
247 for (int dn=0;dn<CandidateDeviceNames.length;dn++)
248 System.out.println(" " +
249 CandidateDeviceNames[dn]);
250 System.out.println(" valid port prefixes:");
251 for (int pp=0;pp<ValidPortPrefixes.length;pp++)
252 System.out.println(" "+ValidPortPrefixes[pp]);
253 /* */
254 }
255 if ( CandidateDeviceNames!=null && ValidPortPrefixes!=null)
256 {
257 for( i = 0;i<CandidateDeviceNames.length; i++ ) {
258 for( p = 0;p<ValidPortPrefixes.length; p++ ) {
259 /* this determines:
260 * device file Valid ports
261 * /dev/ttyR[0-9]* != /dev/ttyS[0-9]*
262 * /dev/ttySI[0-9]* != /dev/ttyS[0-9]*
263 * /dev/ttyS[0-9]* == /dev/ttyS[0-9]*
264
265 * Otherwise we check some ports
266 * multiple times. Perl would rock
267 * here.
268 *
269 * If the above passes, we try to read
270 * from the port. If there is no err
271 * the port is added.
272 * Trent
273 */
274 String V = ValidPortPrefixes[ p ];
275 int VL = V.length();
276 String C = CandidateDeviceNames[ i ];
277 if( C.length() < VL ) continue;
278 String CU =
279 C.substring(VL).toUpperCase();
280 String Cl =
281 C.substring(VL).toLowerCase();
282 if( !( C.regionMatches(0, V, 0, VL ) &&
283 CU.equals( Cl ) ) )
284 {
285 continue;
286 }
287 String PortName;
288 if(osName.toLowerCase().indexOf("windows") == -1 )
289 {
290 PortName = deviceDirectory + C;
291 }
292 else
293 {
294 PortName = C;
295 }
296 if (debug)
297 {
298 System.out.println( C +
299 " " + V );
300 System.out.println( CU +
301 " " + Cl );
302 }
303 if( osName.equals("Solaris") ||
304 osName.equals("SunOS"))
305 checkSolaris(PortName,PortType);
306 else if (testRead(PortName, PortType))
307 {
308 CommPortIdentifier.addPortName(
309 PortName,
310 PortType,
311 this
312 );
313 }
314 }
315 }
316 }
317 if (debug)
318 System.out.println("Leaving registerValidPorts()");
319 }
320
321
322 /*
323 * initialize() will be called by the CommPortIdentifier's static
324 * initializer. The responsibility of this method is:
325 * 1) Ensure that that the hardware is present.
326 * 2) Load any required native libraries.
327 * 3) Register the port names with the CommPortIdentifier.
328 *
329 * <p>From the NullDriver.java CommAPI sample.
330 *
331 * added printerport stuff
332 * Holger Lehmann
333 * July 12, 1999
334 * IBM
335
336 * Added ttyM for Moxa boards
337 * Removed obsolete device cuaa
338 * Peter Bennett
339 * January 02, 2000
340 * Bencom
341
342 */
343
344 /**
345 * Determine the OS and where the OS has the devices located
346 */
347 public void initialize()
348 {
349
350 if (debug) System.out.println("RXTXCommDriver:initialize()");
351
352 osName=System.getProperty("os.name");
353 deviceDirectory=getDeviceDirectory();
354
355 /*
356 First try to register ports specified in the properties
357 file. If that doesn't exist, then scan for ports.
358 */
•359 for (int PortType=CommPortIdentifier.PORT_SERIAL; PortType<=CommPortIdentifier.PORT_PARALLEL; PortType++) {
360 if (!registerSpecifiedPorts(PortType)) {
361 if (!registerKnownPorts(PortType)) {
362 registerScannedPorts(PortType);
363 }
364 }
365 }
366 }
367
368 private void addSpecifiedPorts(String names, int PortType)
369 {
370 final String pathSep = System.getProperty("path.separator", ":");
371 final StringTokenizer tok = new StringTokenizer(names, pathSep);
372
373 if (debug)
374 System.out.println("\nRXTXCommDriver:addSpecifiedPorts()");
375 while (tok.hasMoreElements())
376 {
377 String PortName = tok.nextToken();
•378 if(debug)
379 System.out.println("Trying " + PortName + ".");
380 if (testRead(PortName, PortType)) {
381 CommPortIdentifier.addPortName(PortName,
382 PortType, this);
•383 if(debug)
384 System.out.println("Success: Read from " + PortName + ".");
385 }else{
386 if(debug)
387 System.out.println("Fail: Cannot read from " + PortName
388 + ".");
389 }
390 }
391 }
392
393 /*
394 * Register ports specified in the file "gnu.io.rxtx.properties"
395 * Key system properties:
396 * gnu.io.rxtx.SerialPorts
397 * gnu.io.rxtx.ParallelPorts
398 *
399 * Tested only with sun jdk1.3
400 * The file gnu.io.rxtx.properties must reside in the java extension dir
401 *
402 * Example: /usr/local/java/jre/lib/ext/gnu.io.rxtx.properties
403 *
404 * The file contains the following key properties:
405 *
406 * gnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyS1:
407 * gnu.io.rxtx.ParallelPorts=/dev/lp0:
408 *
409 */
410 private boolean registerSpecifiedPorts(int PortType)
411 {
412 String val = null;
•413 Properties origp = System.getProperties(); // save system properties
414
•415 String [] ext_dirs = System.getProperty("java.ext.dirs") != null ? System.getProperty("java.ext.dirs").split(":") : new String[0];
416 String fs = System.getProperty("file.separator");
417 for (int n = 0; n < ext_dirs.length; ++n) {
418 String ext_file = "?";
419 try{
420 ext_file = ext_dirs[n] + fs + "gnu.io.rxtx.properties";
421 FileInputStream rxtx_prop = new FileInputStream(ext_file);
422 Properties p=new Properties();
423 p.load(rxtx_prop);
424 System.setProperties(p);
425 for (Iterator it = p.keySet().iterator(); it.hasNext();) {
426 String key = (String) it.next();
427 String value = p.getProperty(key);
428 if(debug) {
429 System.out.println(key + " -> " + value);
430 }
431 System.setProperty(key, value);
432 }
433 }catch(Exception e){
434 if (debug){
435 System.out.println("The file \"" + ext_file
436 + "\" doesn't exist.");
437 System.out.println(e.toString());
438 }//end if
439 continue;
440 }//end catch
•441 if (debug){
442 System.out.println("Read properties from \"" + ext_file
443 + "\".");
444 }//end if
445 }//end for
446
447 if (debug)
448 System.out.println("checking for system-known ports of type "+PortType);
449 if (debug)
450 System.out.println("checking registry for ports of type "+PortType);
451
452 switch (PortType) {
453 case CommPortIdentifier.PORT_SERIAL:
454 if ((val = System.getProperty("gnu.io.rxtx.SerialPorts")) == null)
455 val = System.getProperty("gnu.io.SerialPorts");
456 break;
457
458 case CommPortIdentifier.PORT_PARALLEL:
459 if ((val = System.getProperty("gnu.io.rxtx.ParallelPorts")) == null)
460 val = System.getProperty("gnu.io.ParallelPorts");
461 break;
462 default:
463 if (debug)
464 System.out.println("unknown port type "+PortType+" passed to RXTXCommDriver.registerSpecifiedPorts()");
465 }
466
467 System.setProperties(origp); //recall saved properties
468 if (val != null) {
469 addSpecifiedPorts(val, PortType);
470 return true;
471 } else {
472 return false;
473 }
474 }
475
476 /*
477 * Look for all entries in deviceDirectory, and if they look like they should
478 * be serial ports on this OS and they can be opened then register
479 * them.
480 *
481 */
482 private void registerScannedPorts(int PortType)
483 {
484 String[] CandidateDeviceNames;
485 if (debug)
486 System.out.println("scanning device directory "+deviceDirectory+" for ports of type "+PortType);
487 if(osName.equals("Windows CE"))
488 {
489 String[] temp =
490 { "COM1:", "COM2:","COM3:","COM4:",
491 "COM5:", "COM6:", "COM7:", "COM8:" };
492 CandidateDeviceNames=temp;
493 }
494 else if(osName.toLowerCase().indexOf("windows") != -1 )
495 {
496 String[] temp = new String[259];
497 for( int i = 1; i <= 256; i++ )
498 {
499 temp[i - 1] = "COM" + i;
500 }
501 for( int i = 1; i <= 3; i++ )
502 {
503 temp[i + 255] = "LPT" + i;
504 }
505 CandidateDeviceNames=temp;
506 }
507 else if ( osName.equals("Solaris") || osName.equals("SunOS"))
508 {
509 /* Solaris uses a few different ways to identify ports.
510 They could be /dev/term/a /dev/term0 /dev/cua/a /dev/cuaa
511 the /dev/???/a appears to be on more systems.
512
513 The uucp lock files should not cause problems.
514 */
515 /*
516 File dev = new File( "/dev/term" );
517 String deva[] = dev.list();
518 dev = new File( "/dev/cua" );
519 String devb[] = dev.list();
520 String[] temp = new String[ deva.length + devb.length ];
521 for(int j =0;j<deva.length;j++)
522 deva[j] = "term/" + deva[j];
523 for(int j =0;j<devb.length;j++)
524 devb[j] = "cua/" + devb[j];
525 System.arraycopy( deva, 0, temp, 0, deva.length );
526 System.arraycopy( devb, 0, temp,
527 deva.length, devb.length );
528 if( debug ) {
529 for( int j = 0; j< temp.length;j++)
530 System.out.println( temp[j] );
531 }
532 CandidateDeviceNames=temp;
533 */
534
535 /*
536
537 ok.. Look the the dirctories representing the port
538 kernel driver interface.
539
540 If there are entries there are possibly ports we can
541 use and need to enumerate.
542 */
543
544 String term[] = new String[2];
545 int l = 0;
546 File dev = null;
547
548 dev = new File( "/dev/term" );
549 if( dev.list().length > 0 )
550 term[l++] ="term/";
551 /*
552 dev = new File( "/dev/cua0" );
553 if( dev.list().length > 0 )
554 term[l++] = "cua/";
555 */
556 String[] temp = new String[l];
557 for(l--;l >= 0;l--)
558 temp[l] = term[l];
559 CandidateDeviceNames=temp;
560 }
561 else
562 {
563 File dev = new File( deviceDirectory );
564 String[] temp = dev.list();
565 CandidateDeviceNames=temp;
566 }
567 if (CandidateDeviceNames==null)
568 {
569 if (debug)
570 System.out.println("RXTXCommDriver:registerScannedPorts() no Device files to check ");
571 return;
572 }
573
574 String CandidatePortPrefixes[] = {};
575 switch (PortType) {
576 case CommPortIdentifier.PORT_SERIAL:
577 if (debug)
578 System.out.println("scanning for serial ports for os "+osName);
579
580
581 /* There are _many_ possible ports that can be used
582 on Linux. See below in the fake Linux-all-ports
583 case for a list. You may add additional ports
584 here but be warned that too many will significantly
585 slow down port enumeration. Linux 2.6 has udev
586 support which should be faster as only ports the
587 kernel finds should be exposed in /dev
588
589 See also how to override port enumeration and
590 specifying port in INSTALL.
591
592 taj
593 */
594
595 if(osName.equals("Linux"))
596 {
597 String[] Temp = {
598 "ttySA", // for the IPAQs
599 "comx", // linux COMMX synchronous serial card
600 "holter", // custom card for heart monitoring
601 "modem", // linux symbolic link to modem.
602 "rfcomm", // bluetooth serial device
603 "ttyircomm", // linux IrCommdevices (IrDA serial emu)
604 "ttycosa0c", // linux COSA/SRP synchronous serial card
605 "ttycosa1c", // linux COSA/SRP synchronous serial card
606 "ttyACM",// linux CDC ACM devices
607 "ttyC", // linux cyclades cards
608 "ttyCH",// linux Chase Research AT/PCI-Fast serial card
609 "ttyD", // linux Digiboard serial card
610 "ttyE", // linux Stallion serial card
611 "ttyF", // linux Computone IntelliPort serial card
612 "ttyH", // linux Chase serial card
613 "ttyI", // linux virtual modems
614 "ttyL", // linux SDL RISCom serial card
615 "ttyM", // linux PAM Software's multimodem boards
616 // linux ISI serial card
617 "ttyMX",// linux Moxa Smart IO cards
618 "ttyP", // linux Hayes ESP serial card
619 "ttyR", // linux comtrol cards
620 // linux Specialix RIO serial card
621 "ttyS", // linux Serial Ports
622 "ttySI",// linux SmartIO serial card
623 "ttySR",// linux Specialix RIO serial card 257+
624 "ttyT", // linux Technology Concepts serial card
625 "ttyUSB",//linux USB serial converters
626 "ttyV", // linux Comtrol VS-1000 serial controller
627 "ttyW", // linux specialix cards
628 "ttyX" // linux SpecialX serial card
629 };
630 CandidatePortPrefixes=Temp;
631 }
632 else if(osName.toLowerCase().indexOf("qnx") != -1 )
633 {
634 String[] Temp = {
635 "ser"
636 };
637 CandidatePortPrefixes=Temp;
638 }
639 else if(osName.equals("Irix"))
640 {
641 String[] Temp = {
642 "ttyc", // irix raw character devices
643 "ttyd", // irix basic serial ports
644 "ttyf", // irix serial ports with hardware flow
645 "ttym", // irix modems
646 "ttyq", // irix pseudo ttys
647 "tty4d",// irix RS422
648 "tty4f",// irix RS422 with HSKo/HSki
649 "midi", // irix serial midi
650 "us" // irix mapped interface
651 };
652 CandidatePortPrefixes=Temp;
653 }
654 else if(osName.equals("FreeBSD")) //FIXME this is probably wrong
655 {
656 String[] Temp = {
657 "ttyd", //general purpose serial ports
658 "cuaa", //dialout serial ports
659 "ttyA", //Specialix SI/XIO dialin ports
660 "cuaA", //Specialix SI/XIO dialout ports
661 "ttyD", //Digiboard - 16 dialin ports
662 "cuaD", //Digiboard - 16 dialout ports
663 "ttyE", //Stallion EasyIO (stl) dialin ports
664 "cuaE", //Stallion EasyIO (stl) dialout ports
665 "ttyF", //Stallion Brumby (stli) dialin ports
666 "cuaF", //Stallion Brumby (stli) dialout ports
667 "ttyR", //Rocketport dialin ports
668 "cuaR", //Rocketport dialout ports
669 "stl" //Stallion EasyIO board or Brumby N
670 };
671 CandidatePortPrefixes=Temp;
672 }
673 else if(osName.equals("NetBSD")) // FIXME this is probably wrong
674 {
675 String[] Temp = {
676 "tty0" // netbsd serial ports
677 };
678 CandidatePortPrefixes=Temp;
679 }
680 else if ( osName.equals("Solaris")
681 || osName.equals("SunOS"))
682 {
683 String[] Temp = {
684 "term/",
685 "cua/"
686 };
687 CandidatePortPrefixes=Temp;
688 }
689 else if(osName.equals("HP-UX"))
690 {
691 String[] Temp = {
692 "tty0p",// HP-UX serial ports
693 "tty1p" // HP-UX serial ports
694 };
695 CandidatePortPrefixes=Temp;
696 }
697
698 else if(osName.equals("UnixWare") ||
699 osName.equals("OpenUNIX"))
700 {
701 String[] Temp = {
702 "tty00s", // UW7/OU8 serial ports
703 "tty01s",
704 "tty02s",
705 "tty03s"
706 };
707 CandidatePortPrefixes=Temp;
708 }
709
710 else if (osName.equals("OpenServer"))
711 {
712 String[] Temp = {
713 "tty1A", // OSR5 serial ports
714 "tty2A",
715 "tty3A",
716 "tty4A",
717 "tty5A",
718 "tty6A",
719 "tty7A",
720 "tty8A",
721 "tty9A",
722 "tty10A",
723 "tty11A",
724 "tty12A",
725 "tty13A",
726 "tty14A",
727 "tty15A",
728 "tty16A",
729 "ttyu1A", // OSR5 USB-serial ports
730 "ttyu2A",
731 "ttyu3A",
732 "ttyu4A",
733 "ttyu5A",
734 "ttyu6A",
735 "ttyu7A",
736 "ttyu8A",
737 "ttyu9A",
738 "ttyu10A",
739 "ttyu11A",
740 "ttyu12A",
741 "ttyu13A",
742 "ttyu14A",
743 "ttyu15A",
744 "ttyu16A"
745 };
746 CandidatePortPrefixes=Temp;
747 }
748 else if (osName.equals("Compaq's Digital UNIX") || osName.equals("OSF1"))
749 {
750 String[] Temp = {
751 "tty0" // Digital Unix serial ports
752 };
753 CandidatePortPrefixes=Temp;
754 }
755
756 else if(osName.equals("BeOS"))
757 {
758 String[] Temp = {
759 "serial" // BeOS serial ports
760 };
761 CandidatePortPrefixes=Temp;
762 }
763 else if(osName.equals("Mac OS X"))
764 {
765 String[] Temp = {
766 // Keyspan USA-28X adapter, USB port 1
767 "cu.KeyUSA28X191.",
768 // Keyspan USA-28X adapter, USB port 1
769 "tty.KeyUSA28X191.",
770 // Keyspan USA-28X adapter, USB port 2
771 "cu.KeyUSA28X181.",
772 // Keyspan USA-28X adapter, USB port 2
773 "tty.KeyUSA28X181.",
774 // Keyspan USA-19 adapter
775 "cu.KeyUSA19181.",
776 // Keyspan USA-19 adapter
777 "tty.KeyUSA19181."
778 };
779 CandidatePortPrefixes=Temp;
780 }
781 else if(osName.toLowerCase().indexOf("windows") != -1 )
782 {
783 String[] Temp = {
784 "COM" // win32 serial ports
785 //"//./COM" // win32 serial ports
786 };
787 CandidatePortPrefixes=Temp;
788 }
789 else
790 {
791 if (debug)
792 System.out.println("No valid prefixes for serial ports have been entered for "+osName + " in RXTXCommDriver.java. This may just be a typo in the method registerScanPorts().");
793 }
794 break;
795
796 case CommPortIdentifier.PORT_PARALLEL:
797 if (debug)
798 System.out.println("scanning for parallel ports for os "+osName);
799 /** Get the Parallel port prefixes for the running os
800 * Holger Lehmann
801 * July 12, 1999
802 * IBM
803 */
804 if(osName.equals("Linux")
805 /*
806 || osName.equals("NetBSD") FIXME
807 || osName.equals("HP-UX") FIXME
808 || osName.equals("Irix") FIXME
809 || osName.equals("BeOS") FIXME
810 || osName.equals("Compaq's Digital UNIX") FIXME
811 */
812 )
813 {
814 String[] temp={
815 "lp" // linux printer port
816 };
817 CandidatePortPrefixes=temp;
818 }
819 else if(osName.equals("FreeBSD"))
820 {
821 String[] temp={
822 "lpt"
823 };
824 CandidatePortPrefixes=temp;
825 }
826 else if(osName.toLowerCase().indexOf("windows") != -1 )
827 {
828 String[] temp={
829 "LPT"
830 };
831 CandidatePortPrefixes=temp;
832 }
833 else /* printer support is green */
834 {
835 String [] temp={};
836 CandidatePortPrefixes=temp;
837 }
838 break;
839 default:
840 if (debug)
841 System.out.println("Unknown PortType "+PortType+" passed to RXTXCommDriver.registerScannedPorts()");
842 }
843 registerValidPorts(CandidateDeviceNames, CandidatePortPrefixes, PortType);
844 }
845
846
847 /*
848 * <p>From the NullDriver.java CommAPI sample.
849 */
850 /**
851 * @param PortName The name of the port the OS recognizes
852 * @param PortType CommPortIdentifier.PORT_SERIAL or PORT_PARALLEL
853 * @return CommPort
854 * getCommPort() will be called by CommPortIdentifier from its
855 * openPort() method. PortName is a string that was registered earlier
856 * using the CommPortIdentifier.addPortName() method. getCommPort()
857 * returns an object that extends either SerialPort or ParallelPort.
858 */
859 public CommPort getCommPort( String PortName, int PortType )
860 {
861 if (debug) System.out.println("RXTXCommDriver:getCommPort("
862 +PortName+","+PortType+")");
863 try {
864 switch (PortType) {
865 case CommPortIdentifier.PORT_SERIAL:
866 if(osName.toLowerCase().indexOf("windows") == -1 )
867 {
868
869 return new RXTXPort( PortName );
870 }
871 else
872 {
873 return new RXTXPort( deviceDirectory + PortName );
874 }
875 case CommPortIdentifier.PORT_PARALLEL:
876 return new LPRPort( PortName );
877 default:
878 if (debug)
879 System.out.println("unknown PortType "+PortType+" passed to RXTXCommDriver.getCommPort()");
880 }
881 } catch( PortInUseException e ) {
882 if (debug)
883 System.out.println(
884 "Port "+PortName+" in use by another application");
885 }
886 return null;
887 }
888
889 /* Yikes. Trying to call println from C for odd reasons */
890 public void Report( String arg )
891 {
892 System.out.println(arg);
893 }
894 }