Debian Codegraph @

src/gnu/io/RXTXCommDriver.java

raw symbols ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
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
379 if (testRead(PortName, PortType))
380 CommPortIdentifier.addPortName(PortName,
381 PortType, this);
382 }
383 }
384
385 /*
386 * Register ports specified in the file "gnu.io.rxtx.properties"
387 * Key system properties:
388 * gnu.io.rxtx.SerialPorts
389 * gnu.io.rxtx.ParallelPorts
390 *
391 * Tested only with sun jdk1.3
392 * The file gnu.io.rxtx.properties must reside in the java extension dir
393 *
394 * Example: /usr/local/java/jre/lib/ext/gnu.io.rxtx.properties
395 *
396 * The file contains the following key properties:
397 *
398 * gnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyS1:
399 * gnu.io.rxtx.ParallelPorts=/dev/lp0:
400 *
401 */
402 private boolean registerSpecifiedPorts(int PortType)
403 {
404 String val = null;
405 Properties origp = System.getProperties();//save system properties
406
407 try
408 {
409
410 String ext_dir=System.getProperty("java.ext.dirs")+System.getProperty("file.separator");
411 FileInputStream rxtx_prop=new FileInputStream(ext_dir+"gnu.io.rxtx.properties");
412 Properties p=new Properties();
413 p.load(rxtx_prop);
414 System.setProperties(p);
415 for (Iterator it = p.keySet().iterator(); it.hasNext();) {
416 String key = (String) it.next();
417 System.setProperty(key, p.getProperty(key));
418 }
419 }catch(Exception e){
420 if (debug){
421 System.out.println("The file: gnu.io.rxtx.properties doesn't exists.");
422 System.out.println(e.toString());
423 }//end if
424 }//end catch
425
426 if (debug)
427 System.out.println("checking for system-known ports of type "+PortType);
428 if (debug)
429 System.out.println("checking registry for ports of type "+PortType);
430
431 switch (PortType) {
432 case CommPortIdentifier.PORT_SERIAL:
433 if ((val = System.getProperty("gnu.io.rxtx.SerialPorts")) == null)
434 val = System.getProperty("gnu.io.SerialPorts");
435 break;
436
437 case CommPortIdentifier.PORT_PARALLEL:
438 if ((val = System.getProperty("gnu.io.rxtx.ParallelPorts")) == null)
439 val = System.getProperty("gnu.io.ParallelPorts");
440 break;
441 default:
442 if (debug)
443 System.out.println("unknown port type "+PortType+" passed to RXTXCommDriver.registerSpecifiedPorts()");
444 }
445
446 System.setProperties(origp); //recall saved properties
447 if (val != null) {
448 addSpecifiedPorts(val, PortType);
449 return true;
450 } else {
451 return false;
452 }
453 }
454
455 /*
456 * Look for all entries in deviceDirectory, and if they look like they should
457 * be serial ports on this OS and they can be opened then register
458 * them.
459 *
460 */
461 private void registerScannedPorts(int PortType)
462 {
463 String[] CandidateDeviceNames;
464 if (debug)
465 System.out.println("scanning device directory "+deviceDirectory+" for ports of type "+PortType);
466 if(osName.equals("Windows CE"))
467 {
468 String[] temp =
469 { "COM1:", "COM2:","COM3:","COM4:",
470 "COM5:", "COM6:", "COM7:", "COM8:" };
471 CandidateDeviceNames=temp;
472 }
473 else if(osName.toLowerCase().indexOf("windows") != -1 )
474 {
475 String[] temp = new String[259];
476 for( int i = 1; i <= 256; i++ )
477 {
478 temp[i - 1] = "COM" + i;
479 }
480 for( int i = 1; i <= 3; i++ )
481 {
482 temp[i + 255] = "LPT" + i;
483 }
484 CandidateDeviceNames=temp;
485 }
486 else if ( osName.equals("Solaris") || osName.equals("SunOS"))
487 {
488 /* Solaris uses a few different ways to identify ports.
489 They could be /dev/term/a /dev/term0 /dev/cua/a /dev/cuaa
490 the /dev/???/a appears to be on more systems.
491
492 The uucp lock files should not cause problems.
493 */
494 /*
495 File dev = new File( "/dev/term" );
496 String deva[] = dev.list();
497 dev = new File( "/dev/cua" );
498 String devb[] = dev.list();
499 String[] temp = new String[ deva.length + devb.length ];
500 for(int j =0;j<deva.length;j++)
501 deva[j] = "term/" + deva[j];
502 for(int j =0;j<devb.length;j++)
503 devb[j] = "cua/" + devb[j];
504 System.arraycopy( deva, 0, temp, 0, deva.length );
505 System.arraycopy( devb, 0, temp,
506 deva.length, devb.length );
507 if( debug ) {
508 for( int j = 0; j< temp.length;j++)
509 System.out.println( temp[j] );
510 }
511 CandidateDeviceNames=temp;
512 */
513
514 /*
515
516 ok.. Look the the dirctories representing the port
517 kernel driver interface.
518
519 If there are entries there are possibly ports we can
520 use and need to enumerate.
521 */
522
523 String term[] = new String[2];
524 int l = 0;
525 File dev = null;
526
527 dev = new File( "/dev/term" );
528 if( dev.list().length > 0 )
529 term[l++] ="term/";
530 /*
531 dev = new File( "/dev/cua0" );
532 if( dev.list().length > 0 )
533 term[l++] = "cua/";
534 */
535 String[] temp = new String[l];
536 for(l--;l >= 0;l--)
537 temp[l] = term[l];
538 CandidateDeviceNames=temp;
539 }
540 else
541 {
542 File dev = new File( deviceDirectory );
543 String[] temp = dev.list();
544 CandidateDeviceNames=temp;
545 }
546 if (CandidateDeviceNames==null)
547 {
548 if (debug)
549 System.out.println("RXTXCommDriver:registerScannedPorts() no Device files to check ");
550 return;
551 }
552
553 String CandidatePortPrefixes[] = {};
554 switch (PortType) {
555 case CommPortIdentifier.PORT_SERIAL:
556 if (debug)
557 System.out.println("scanning for serial ports for os "+osName);
558
559
560 /* There are _many_ possible ports that can be used
561 on Linux. See below in the fake Linux-all-ports
562 case for a list. You may add additional ports
563 here but be warned that too many will significantly
564 slow down port enumeration. Linux 2.6 has udev
565 support which should be faster as only ports the
566 kernel finds should be exposed in /dev
567
568 See also how to override port enumeration and
569 specifying port in INSTALL.
570
571 taj
572 */
573
574 if(osName.equals("Linux"))
575 {
576 String[] Temp = {
577 "ttySA", // for the IPAQs
578 "comx", // linux COMMX synchronous serial card
579 "holter", // custom card for heart monitoring
580 "modem", // linux symbolic link to modem.
581 "rfcomm", // bluetooth serial device
582 "ttyircomm", // linux IrCommdevices (IrDA serial emu)
583 "ttycosa0c", // linux COSA/SRP synchronous serial card
584 "ttycosa1c", // linux COSA/SRP synchronous serial card
585 "ttyACM",// linux CDC ACM devices
586 "ttyC", // linux cyclades cards
587 "ttyCH",// linux Chase Research AT/PCI-Fast serial card
588 "ttyD", // linux Digiboard serial card
589 "ttyE", // linux Stallion serial card
590 "ttyF", // linux Computone IntelliPort serial card
591 "ttyH", // linux Chase serial card
592 "ttyI", // linux virtual modems
593 "ttyL", // linux SDL RISCom serial card
594 "ttyM", // linux PAM Software's multimodem boards
595 // linux ISI serial card
596 "ttyMX",// linux Moxa Smart IO cards
597 "ttyP", // linux Hayes ESP serial card
598 "ttyR", // linux comtrol cards
599 // linux Specialix RIO serial card
600 "ttyS", // linux Serial Ports
601 "ttySI",// linux SmartIO serial card
602 "ttySR",// linux Specialix RIO serial card 257+
603 "ttyT", // linux Technology Concepts serial card
604 "ttyUSB",//linux USB serial converters
605 "ttyV", // linux Comtrol VS-1000 serial controller
606 "ttyW", // linux specialix cards
607 "ttyX" // linux SpecialX serial card
608 };
609 CandidatePortPrefixes=Temp;
610 }
611 else if(osName.toLowerCase().indexOf("qnx") != -1 )
612 {
613 String[] Temp = {
614 "ser"
615 };
616 CandidatePortPrefixes=Temp;
617 }
618 else if(osName.equals("Irix"))
619 {
620 String[] Temp = {
621 "ttyc", // irix raw character devices
622 "ttyd", // irix basic serial ports
623 "ttyf", // irix serial ports with hardware flow
624 "ttym", // irix modems
625 "ttyq", // irix pseudo ttys
626 "tty4d",// irix RS422
627 "tty4f",// irix RS422 with HSKo/HSki
628 "midi", // irix serial midi
629 "us" // irix mapped interface
630 };
631 CandidatePortPrefixes=Temp;
632 }
633 else if(osName.equals("FreeBSD")) //FIXME this is probably wrong
634 {
635 String[] Temp = {
636 "ttyd", //general purpose serial ports
637 "cuaa", //dialout serial ports
638 "ttyA", //Specialix SI/XIO dialin ports
639 "cuaA", //Specialix SI/XIO dialout ports
640 "ttyD", //Digiboard - 16 dialin ports
641 "cuaD", //Digiboard - 16 dialout ports
642 "ttyE", //Stallion EasyIO (stl) dialin ports
643 "cuaE", //Stallion EasyIO (stl) dialout ports
644 "ttyF", //Stallion Brumby (stli) dialin ports
645 "cuaF", //Stallion Brumby (stli) dialout ports
646 "ttyR", //Rocketport dialin ports
647 "cuaR", //Rocketport dialout ports
648 "stl" //Stallion EasyIO board or Brumby N
649 };
650 CandidatePortPrefixes=Temp;
651 }
652 else if(osName.equals("NetBSD")) // FIXME this is probably wrong
653 {
654 String[] Temp = {
655 "tty0" // netbsd serial ports
656 };
657 CandidatePortPrefixes=Temp;
658 }
659 else if ( osName.equals("Solaris")
660 || osName.equals("SunOS"))
661 {
662 String[] Temp = {
663 "term/",
664 "cua/"
665 };
666 CandidatePortPrefixes=Temp;
667 }
668 else if(osName.equals("HP-UX"))
669 {
670 String[] Temp = {
671 "tty0p",// HP-UX serial ports
672 "tty1p" // HP-UX serial ports
673 };
674 CandidatePortPrefixes=Temp;
675 }
676
677 else if(osName.equals("UnixWare") ||
678 osName.equals("OpenUNIX"))
679 {
680 String[] Temp = {
681 "tty00s", // UW7/OU8 serial ports
682 "tty01s",
683 "tty02s",
684 "tty03s"
685 };
686 CandidatePortPrefixes=Temp;
687 }
688
689 else if (osName.equals("OpenServer"))
690 {
691 String[] Temp = {
692 "tty1A", // OSR5 serial ports
693 "tty2A",
694 "tty3A",
695 "tty4A",
696 "tty5A",
697 "tty6A",
698 "tty7A",
699 "tty8A",
700 "tty9A",
701 "tty10A",
702 "tty11A",
703 "tty12A",
704 "tty13A",
705 "tty14A",
706 "tty15A",
707 "tty16A",
708 "ttyu1A", // OSR5 USB-serial ports
709 "ttyu2A",
710 "ttyu3A",
711 "ttyu4A",
712 "ttyu5A",
713 "ttyu6A",
714 "ttyu7A",
715 "ttyu8A",
716 "ttyu9A",
717 "ttyu10A",
718 "ttyu11A",
719 "ttyu12A",
720 "ttyu13A",
721 "ttyu14A",
722 "ttyu15A",
723 "ttyu16A"
724 };
725 CandidatePortPrefixes=Temp;
726 }
727 else if (osName.equals("Compaq's Digital UNIX") || osName.equals("OSF1"))
728 {
729 String[] Temp = {
730 "tty0" // Digital Unix serial ports
731 };
732 CandidatePortPrefixes=Temp;
733 }
734
735 else if(osName.equals("BeOS"))
736 {
737 String[] Temp = {
738 "serial" // BeOS serial ports
739 };
740 CandidatePortPrefixes=Temp;
741 }
742 else if(osName.equals("Mac OS X"))
743 {
744 String[] Temp = {
745 // Keyspan USA-28X adapter, USB port 1
746 "cu.KeyUSA28X191.",
747 // Keyspan USA-28X adapter, USB port 1
748 "tty.KeyUSA28X191.",
749 // Keyspan USA-28X adapter, USB port 2
750 "cu.KeyUSA28X181.",
751 // Keyspan USA-28X adapter, USB port 2
752 "tty.KeyUSA28X181.",
753 // Keyspan USA-19 adapter
754 "cu.KeyUSA19181.",
755 // Keyspan USA-19 adapter
756 "tty.KeyUSA19181."
757 };
758 CandidatePortPrefixes=Temp;
759 }
760 else if(osName.toLowerCase().indexOf("windows") != -1 )
761 {
762 String[] Temp = {
763 "COM" // win32 serial ports
764 //"//./COM" // win32 serial ports
765 };
766 CandidatePortPrefixes=Temp;
767 }
768 else
769 {
770 if (debug)
771 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().");
772 }
773 break;
774
775 case CommPortIdentifier.PORT_PARALLEL:
776 if (debug)
777 System.out.println("scanning for parallel ports for os "+osName);
778 /** Get the Parallel port prefixes for the running os
779 * Holger Lehmann
780 * July 12, 1999
781 * IBM
782 */
783 if(osName.equals("Linux")
784 /*
785 || osName.equals("NetBSD") FIXME
786 || osName.equals("HP-UX") FIXME
787 || osName.equals("Irix") FIXME
788 || osName.equals("BeOS") FIXME
789 || osName.equals("Compaq's Digital UNIX") FIXME
790 */
791 )
792 {
793 String[] temp={
794 "lp" // linux printer port
795 };
796 CandidatePortPrefixes=temp;
797 }
798 else if(osName.equals("FreeBSD"))
799 {
800 String[] temp={
801 "lpt"
802 };
803 CandidatePortPrefixes=temp;
804 }
805 else if(osName.toLowerCase().indexOf("windows") != -1 )
806 {
807 String[] temp={
808 "LPT"
809 };
810 CandidatePortPrefixes=temp;
811 }
812 else /* printer support is green */
813 {
814 String [] temp={};
815 CandidatePortPrefixes=temp;
816 }
817 break;
818 default:
819 if (debug)
820 System.out.println("Unknown PortType "+PortType+" passed to RXTXCommDriver.registerScannedPorts()");
821 }
822 registerValidPorts(CandidateDeviceNames, CandidatePortPrefixes, PortType);
823 }
824
825
826 /*
827 * <p>From the NullDriver.java CommAPI sample.
828 */
829 /**
830 * @param PortName The name of the port the OS recognizes
831 * @param PortType CommPortIdentifier.PORT_SERIAL or PORT_PARALLEL
832 * @return CommPort
833 * getCommPort() will be called by CommPortIdentifier from its
834 * openPort() method. PortName is a string that was registered earlier
835 * using the CommPortIdentifier.addPortName() method. getCommPort()
836 * returns an object that extends either SerialPort or ParallelPort.
837 */
838 public CommPort getCommPort( String PortName, int PortType )
839 {
840 if (debug) System.out.println("RXTXCommDriver:getCommPort("
841 +PortName+","+PortType+")");
842 try {
843 switch (PortType) {
844 case CommPortIdentifier.PORT_SERIAL:
845 if(osName.toLowerCase().indexOf("windows") == -1 )
846 {
847
848 return new RXTXPort( PortName );
849 }
850 else
851 {
852 return new RXTXPort( deviceDirectory + PortName );
853 }
854 case CommPortIdentifier.PORT_PARALLEL:
855 return new LPRPort( PortName );
856 default:
857 if (debug)
858 System.out.println("unknown PortType "+PortType+" passed to RXTXCommDriver.getCommPort()");
859 }
860 } catch( PortInUseException e ) {
861 if (debug)
862 System.out.println(
863 "Port "+PortName+" in use by another application");
864 }
865 return null;
866 }
867
868 /* Yikes. Trying to call println from C for odd reasons */
869 public void Report( String arg )
870 {
871 System.out.println(arg);
872 }
873 }