Debian Codegraph @

src/gnu/io/RXTXCommDriver.java

raw symbols ◀ ▶
Source reconstructed at patch state 0 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 "ttyS", // linux Serial Ports
578 "ttySA", // for the IPAQs
579 "ttyUSB", // for USB frobs
580 "rfcomm", // bluetooth serial device
581 "ttyircomm", // linux IrCommdevices (IrDA serial emu)
582 };
583 CandidatePortPrefixes=Temp;
584 }
585 else if(osName.equals("Linux-all-ports"))
586 {
587 /* if you want to enumerate all ports ~5000
588 possible, then replace the above with this
589 */
590 String[] Temp = {
591 "comx", // linux COMMX synchronous serial card
592 "holter", // custom card for heart monitoring
593 "modem", // linux symbolic link to modem.
594 "rfcomm", // bluetooth serial device
595 "ttyircomm", // linux IrCommdevices (IrDA serial emu)
596 "ttycosa0c", // linux COSA/SRP synchronous serial card
597 "ttycosa1c", // linux COSA/SRP synchronous serial card
598 "ttyACM",// linux CDC ACM devices
599 "ttyC", // linux cyclades cards
600 "ttyCH",// linux Chase Research AT/PCI-Fast serial card
601 "ttyD", // linux Digiboard serial card
602 "ttyE", // linux Stallion serial card
603 "ttyF", // linux Computone IntelliPort serial card
604 "ttyH", // linux Chase serial card
605 "ttyI", // linux virtual modems
606 "ttyL", // linux SDL RISCom serial card
607 "ttyM", // linux PAM Software's multimodem boards
608 // linux ISI serial card
609 "ttyMX",// linux Moxa Smart IO cards
610 "ttyP", // linux Hayes ESP serial card
611 "ttyR", // linux comtrol cards
612 // linux Specialix RIO serial card
613 "ttyS", // linux Serial Ports
614 "ttySI",// linux SmartIO serial card
615 "ttySR",// linux Specialix RIO serial card 257+
616 "ttyT", // linux Technology Concepts serial card
617 "ttyUSB",//linux USB serial converters
618 "ttyV", // linux Comtrol VS-1000 serial controller
619 "ttyW", // linux specialix cards
620 "ttyX" // linux SpecialX serial card
621 };
622 CandidatePortPrefixes=Temp;
623 }
624 else if(osName.toLowerCase().indexOf("qnx") != -1 )
625 {
626 String[] Temp = {
627 "ser"
628 };
629 CandidatePortPrefixes=Temp;
630 }
631 else if(osName.equals("Irix"))
632 {
633 String[] Temp = {
634 "ttyc", // irix raw character devices
635 "ttyd", // irix basic serial ports
636 "ttyf", // irix serial ports with hardware flow
637 "ttym", // irix modems
638 "ttyq", // irix pseudo ttys
639 "tty4d",// irix RS422
640 "tty4f",// irix RS422 with HSKo/HSki
641 "midi", // irix serial midi
642 "us" // irix mapped interface
643 };
644 CandidatePortPrefixes=Temp;
645 }
646 else if(osName.equals("FreeBSD")) //FIXME this is probably wrong
647 {
648 String[] Temp = {
649 "ttyd", //general purpose serial ports
650 "cuaa", //dialout serial ports
651 "ttyA", //Specialix SI/XIO dialin ports
652 "cuaA", //Specialix SI/XIO dialout ports
653 "ttyD", //Digiboard - 16 dialin ports
654 "cuaD", //Digiboard - 16 dialout ports
655 "ttyE", //Stallion EasyIO (stl) dialin ports
656 "cuaE", //Stallion EasyIO (stl) dialout ports
657 "ttyF", //Stallion Brumby (stli) dialin ports
658 "cuaF", //Stallion Brumby (stli) dialout ports
659 "ttyR", //Rocketport dialin ports
660 "cuaR", //Rocketport dialout ports
661 "stl" //Stallion EasyIO board or Brumby N
662 };
663 CandidatePortPrefixes=Temp;
664 }
665 else if(osName.equals("NetBSD")) // FIXME this is probably wrong
666 {
667 String[] Temp = {
668 "tty0" // netbsd serial ports
669 };
670 CandidatePortPrefixes=Temp;
671 }
672 else if ( osName.equals("Solaris")
673 || osName.equals("SunOS"))
674 {
675 String[] Temp = {
676 "term/",
677 "cua/"
678 };
679 CandidatePortPrefixes=Temp;
680 }
681 else if(osName.equals("HP-UX"))
682 {
683 String[] Temp = {
684 "tty0p",// HP-UX serial ports
685 "tty1p" // HP-UX serial ports
686 };
687 CandidatePortPrefixes=Temp;
688 }
689
690 else if(osName.equals("UnixWare") ||
691 osName.equals("OpenUNIX"))
692 {
693 String[] Temp = {
694 "tty00s", // UW7/OU8 serial ports
695 "tty01s",
696 "tty02s",
697 "tty03s"
698 };
699 CandidatePortPrefixes=Temp;
700 }
701
702 else if (osName.equals("OpenServer"))
703 {
704 String[] Temp = {
705 "tty1A", // OSR5 serial ports
706 "tty2A",
707 "tty3A",
708 "tty4A",
709 "tty5A",
710 "tty6A",
711 "tty7A",
712 "tty8A",
713 "tty9A",
714 "tty10A",
715 "tty11A",
716 "tty12A",
717 "tty13A",
718 "tty14A",
719 "tty15A",
720 "tty16A",
721 "ttyu1A", // OSR5 USB-serial ports
722 "ttyu2A",
723 "ttyu3A",
724 "ttyu4A",
725 "ttyu5A",
726 "ttyu6A",
727 "ttyu7A",
728 "ttyu8A",
729 "ttyu9A",
730 "ttyu10A",
731 "ttyu11A",
732 "ttyu12A",
733 "ttyu13A",
734 "ttyu14A",
735 "ttyu15A",
736 "ttyu16A"
737 };
738 CandidatePortPrefixes=Temp;
739 }
740 else if (osName.equals("Compaq's Digital UNIX") || osName.equals("OSF1"))
741 {
742 String[] Temp = {
743 "tty0" // Digital Unix serial ports
744 };
745 CandidatePortPrefixes=Temp;
746 }
747
748 else if(osName.equals("BeOS"))
749 {
750 String[] Temp = {
751 "serial" // BeOS serial ports
752 };
753 CandidatePortPrefixes=Temp;
754 }
755 else if(osName.equals("Mac OS X"))
756 {
757 String[] Temp = {
758 // Keyspan USA-28X adapter, USB port 1
759 "cu.KeyUSA28X191.",
760 // Keyspan USA-28X adapter, USB port 1
761 "tty.KeyUSA28X191.",
762 // Keyspan USA-28X adapter, USB port 2
763 "cu.KeyUSA28X181.",
764 // Keyspan USA-28X adapter, USB port 2
765 "tty.KeyUSA28X181.",
766 // Keyspan USA-19 adapter
767 "cu.KeyUSA19181.",
768 // Keyspan USA-19 adapter
769 "tty.KeyUSA19181."
770 };
771 CandidatePortPrefixes=Temp;
772 }
773 else if(osName.toLowerCase().indexOf("windows") != -1 )
774 {
775 String[] Temp = {
776 "COM" // win32 serial ports
777 //"//./COM" // win32 serial ports
778 };
779 CandidatePortPrefixes=Temp;
780 }
781 else
782 {
783 if (debug)
784 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().");
785 }
786 break;
787
788 case CommPortIdentifier.PORT_PARALLEL:
789 if (debug)
790 System.out.println("scanning for parallel ports for os "+osName);
791 /** Get the Parallel port prefixes for the running os
792 * Holger Lehmann
793 * July 12, 1999
794 * IBM
795 */
796 if(osName.equals("Linux")
797 /*
798 || osName.equals("NetBSD") FIXME
799 || osName.equals("HP-UX") FIXME
800 || osName.equals("Irix") FIXME
801 || osName.equals("BeOS") FIXME
802 || osName.equals("Compaq's Digital UNIX") FIXME
803 */
804 )
805 {
806 String[] temp={
807 "lp" // linux printer port
808 };
809 CandidatePortPrefixes=temp;
810 }
811 else if(osName.equals("FreeBSD"))
812 {
813 String[] temp={
814 "lpt"
815 };
816 CandidatePortPrefixes=temp;
817 }
818 else if(osName.toLowerCase().indexOf("windows") != -1 )
819 {
820 String[] temp={
821 "LPT"
822 };
823 CandidatePortPrefixes=temp;
824 }
825 else /* printer support is green */
826 {
827 String [] temp={};
828 CandidatePortPrefixes=temp;
829 }
830 break;
831 default:
832 if (debug)
833 System.out.println("Unknown PortType "+PortType+" passed to RXTXCommDriver.registerScannedPorts()");
834 }
835 registerValidPorts(CandidateDeviceNames, CandidatePortPrefixes, PortType);
836 }
837
838
839 /*
840 * <p>From the NullDriver.java CommAPI sample.
841 */
842 /**
843 * @param PortName The name of the port the OS recognizes
844 * @param PortType CommPortIdentifier.PORT_SERIAL or PORT_PARALLEL
845 * @return CommPort
846 * getCommPort() will be called by CommPortIdentifier from its
847 * openPort() method. PortName is a string that was registered earlier
848 * using the CommPortIdentifier.addPortName() method. getCommPort()
849 * returns an object that extends either SerialPort or ParallelPort.
850 */
851 public CommPort getCommPort( String PortName, int PortType )
852 {
853 if (debug) System.out.println("RXTXCommDriver:getCommPort("
854 +PortName+","+PortType+")");
855 try {
856 switch (PortType) {
857 case CommPortIdentifier.PORT_SERIAL:
858 if(osName.toLowerCase().indexOf("windows") == -1 )
859 {
860
861 return new RXTXPort( PortName );
862 }
863 else
864 {
865 return new RXTXPort( deviceDirectory + PortName );
866 }
867 case CommPortIdentifier.PORT_PARALLEL:
868 return new LPRPort( PortName );
869 default:
870 if (debug)
871 System.out.println("unknown PortType "+PortType+" passed to RXTXCommDriver.getCommPort()");
872 }
873 } catch( PortInUseException e ) {
874 if (debug)
875 System.out.println(
876 "Port "+PortName+" in use by another application");
877 }
878 return null;
879 }
880
881 /* Yikes. Trying to call println from C for odd reasons */
882 public void Report( String arg )
883 {
884 System.out.println(arg);
885 }
886 }