Debian Codegraph @

CNI/RXTXCommDriver.java

raw symbols SCIP
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-2007 by 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.util.*;
67 import java.io.*;
68 import java.util.StringTokenizer;
69
70 /**
71 This is the JavaComm for Linux driver.
72 */
73 public class RXTXCommDriver implements CommDriver
74 {
75
76 private final static boolean debug = false;
77 private final static boolean devel = true;
78
79 static
80 {
81
82 if(debug ) System.out.println("RXTXCommDriver {}");
83 /*
84 System.loadLibrary( "rxtxSerial" );
85 */
86
87 /*
88 Perform a crude check to make sure people don't mix
89 versions of the Jar and native lib
90
91 Mixing the libs can create a nightmare.
92
93 It could be possible to move this over to RXTXVersion
94 but All we want to do is warn people when first loading
95 the Library.
96 */
97 String JarVersion = RXTXVersion.getVersion();
98 String LibVersion = nativeGetVersion();
99
100 if ( devel )
101 {
102 System.out.println("Devel Library");
103 System.out.println("=========================================");
104 System.out.println("Native lib Version = " + JarVersion );
105 System.out.println("Java lib Version = " + LibVersion );
106 }
107
108 /* FIXME static not working
109 if ( ! JarVersion.equals( LibVersion ) )
110 {
111 System.out.println( "WARNING: RXTX Version mismatch\n\tJar version = " + JarVersion + "\n\tnative lib Version = " + LibVersion );
112 }
113 else if ( debug )
114 {
115 System.out.println( "RXTXCommDriver:\n\tJar version = " + JarVersion + "\n\tnative lib Version = " + LibVersion );
116 }
117 */
118 }
119
120 /** Get the Serial port prefixes for the running OS */
121 private String deviceDirectory;
122 private String osName;
123 private static native String nativeGetVersion();
124 private native boolean registerKnownPorts(int PortType);
125 private native boolean isPortPrefixValid(String dev);
126 private native boolean testRead(String dev, int type);
127 private native String getDeviceDirectory();
128
129 private final String[] getValidPortPrefixes(String CandidatePortPrefixes[])
130 {
131 /*
132 256 is the number of prefixes ( COM, cua, ttyS, ...) not
133 the number of devices (ttyS0, ttyS1, ttyS2, ...)
134
135 On a Linux system there are about 400 prefixes in
136 deviceDirectory.
137 registerScannedPorts() assigns CandidatePortPrefixes to
138 something less than 50 prefixes.
139
140 Trent
141 */
142
143 String ValidPortPrefixes[]=new String [256];
144 if (debug)
145 System.out.println("\nRXTXCommDriver:getValidPortPrefixes()");
146 if(CandidatePortPrefixes==null)
147 {
148 if (debug)
149 System.out.println("\nRXTXCommDriver:getValidPortPrefixes() No ports prefixes known for this System.\nPlease check the port prefixes listed for " + osName + " in RXTXCommDriver:registerScannedPorts()\n");
150 }
151 int i=0;
152 for(int j=0;j<CandidatePortPrefixes.length;j++){
153 if(isPortPrefixValid(CandidatePortPrefixes[j])) {
154 ValidPortPrefixes[i++]=
155 new String(CandidatePortPrefixes[j]);
156 }
157 }
158 String[] returnArray=new String[i];
159 System.arraycopy(ValidPortPrefixes, 0, returnArray, 0, i);
160 if(ValidPortPrefixes[0]==null)
161 {
162 if (debug)
163 {
164 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:");
165 for(int j=0;j<CandidatePortPrefixes.length;j++){
166 System.out.println("\t" +
167 CandidatePortPrefixes[i]);
168 }
169 }
170 }
171 else
172 {
173 if (debug)
174 System.out.println("\nRXTXCommDriver:getValidPortPrefixes()\nThe following port prefixes have been identified as valid on " + osName + ":\n");
175 /*
176 for(int j=0;j<returnArray.length;j++)
177 {
178 if (debug)
179 System.out.println("\t" + j + " " +
180 returnArray[j]);
181 }
182 */
183 }
184 return returnArray;
185 }
186
187 /** handle solaris/sunos /dev/cua/a convention */
188 private void checkSolaris(String PortName, int PortType)
189 {
190 char p[] = { 91 };
191 for( p[0] =97 ;p[0] < 123; p[0]++ )
192 {
193 if (testRead(PortName.concat(new String(p)),PortType))
194 {
195 CommPortIdentifier.addPortName(
196 PortName.concat(new String(p)),
197 PortType,
198 this
199 );
200 }
201 }
202 }
203 private void registerValidPorts(
204 String CandidateDeviceNames[],
205 String ValidPortPrefixes[],
206 int PortType
207 ) {
208 int i =0;
209 int p =0 ;
210 /* FIXME quick fix to get COM1-8 on windows working. The
211 Read test is not working properly and its crunch time...
212 if(osName.toLowerCase().indexOf("windows") != -1 )
213 {
214 for( i=0;i < CandidateDeviceNames.length;i++ )
215 {
216 CommPortIdentifier.addPortName( CandidateDeviceNames[i],
217 PortType, this );
218 }
219 return;
220
221 }
222 */
223 if (debug)
224 {
225 System.out.println("Entering registerValidPorts()");
226 /* */
227 System.out.println(" Candidate devices:");
228 for (int dn=0;dn<CandidateDeviceNames.length;dn++)
229 System.out.println(" " +
230 CandidateDeviceNames[dn]);
231 System.out.println(" valid port prefixes:");
232 for (int pp=0;pp<ValidPortPrefixes.length;pp++)
233 System.out.println(" "+ValidPortPrefixes[pp]);
234 /* */
235 }
236 if ( CandidateDeviceNames!=null && ValidPortPrefixes!=null)
237 {
238 for( i = 0;i<CandidateDeviceNames.length; i++ ) {
239 for( p = 0;p<ValidPortPrefixes.length; p++ ) {
240 /* this determines:
241 * device file Valid ports
242 * /dev/ttyR[0-9]* != /dev/ttyS[0-9]*
243 * /dev/ttySI[0-9]* != /dev/ttyS[0-9]*
244 * /dev/ttyS[0-9]* == /dev/ttyS[0-9]*
245
246 * Otherwise we check some ports
247 * multiple times. Perl would rock
248 * here.
249 *
250 * If the above passes, we try to read
251 * from the port. If there is no err
252 * the port is added.
253 * Trent
254 */
255 String V = ValidPortPrefixes[ p ];
256 int VL = V.length();
257 String C = CandidateDeviceNames[ i ];
258 if( C.length() < VL ) continue;
259 String CU =
260 C.substring(VL).toUpperCase();
261 String Cl =
262 C.substring(VL).toLowerCase();
263 if( !( C.regionMatches(0, V, 0, VL ) &&
264 CU.equals( Cl ) ) )
265 {
266 continue;
267 }
268 String PortName;
269 if(osName.toLowerCase().indexOf("windows") == -1 )
270 {
271 PortName =
272 new String(deviceDirectory +
273 C );
274 }
275 else
276 {
277 PortName =
278 new String( C );
279 }
280 if (debug)
281 {
282 System.out.println( C +
283 " " + V );
284 System.out.println( CU +
285 " " + Cl );
286 }
287 if( osName.equals("Solaris") ||
288 osName.equals("SunOS"))
289 checkSolaris(PortName,PortType);
290 else if (testRead(PortName, PortType))
291 {
292 CommPortIdentifier.addPortName(
293 PortName,
294 PortType,
295 this
296 );
297 }
298 }
299 }
300 }
301 if (debug)
302 System.out.println("Leaving registerValidPorts()");
303 }
304
305
306 /*
307 * initialize() will be called by the CommPortIdentifier's static
308 * initializer. The responsibility of this method is:
309 * 1) Ensure that that the hardware is present.
310 * 2) Load any required native libraries.
311 * 3) Register the port names with the CommPortIdentifier.
312 *
313 * <p>From the NullDriver.java CommAPI sample.
314 *
315 * added printerport stuff
316 * Holger Lehmann
317 * July 12, 1999
318 * IBM
319
320 * Added ttyM for Moxa boards
321 * Removed obsolete device cuaa
322 * Peter Bennett
323 * January 02, 2000
324 * Bencom
325
326 */
327
328 /**
329 * Determine the OS and where the OS has the devices located
330 */
331 public void initialize()
332 {
333
334 if (debug) System.out.println("RXTXCommDriver:initialize()");
335
336 osName=System.getProperty("os.name");
337 deviceDirectory=getDeviceDirectory();
338
339 /*
340 First try to register ports specified in the properties
341 file. If that doesn't exist, then scan for ports.
342 */
343 for (int PortType=CommPortIdentifier.PORT_SERIAL;PortType<=CommPortIdentifier.PORT_PARALLEL;PortType++) {
344 if (!registerSpecifiedPorts(PortType)) {
345 if (!registerKnownPorts(PortType)) {
346 registerScannedPorts(PortType);
347 }
348 }
349 }
350 }
351
352 private void addSpecifiedPorts(String names, int PortType)
353 {
354 final String pathSep = System.getProperty("path.separator", ":");
355 final StringTokenizer tok = new StringTokenizer(names, pathSep);
356
357 if (debug)
358 System.out.println("\nRXTXCommDriver:addSpecifiedPorts()");
359 while (tok.hasMoreElements())
360 {
361 String PortName = tok.nextToken();
362
363 if (testRead(PortName, PortType))
364 CommPortIdentifier.addPortName(PortName,
365 PortType, this);
366 }
367 }
368
369 /*
370 * Register ports specified in the file "gnu.io.rxtx.properties"
371 * Key system properties:
372 * gnu.io.rxtx.SerialPorts
373 * gnu.io.rxtx.ParallelPorts
374 *
375 * Tested only with sun jdk1.3
376 * The file gnu.io.rxtx.properties must reside in the java extension dir
377 *
378 * Example: /usr/local/java/jre/lib/ext/gnu.io.rxtx.properties
379 *
380 * The file contains the following key properties:
381 *
382 * gnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyS1:
383 * gnu.io.rxtx.ParallelPorts=/dev/lp0:
384 *
385 */
386 private boolean registerSpecifiedPorts(int PortType)
387 {
388 String val = null;
389
390 try
391 {
392
393 String ext_dir=System.getProperty("java.ext.dirs")+System.getProperty("file.separator");
394 FileInputStream rxtx_prop=new FileInputStream(ext_dir+"gnu.io.rxtx.properties");
395 Properties p=new Properties(System.getProperties());
396 p.load(rxtx_prop);
397 System.setProperties(p);
398 }catch(Exception e){
399 if (debug){
400 System.out.println("The file: gnu.io.rxtx.properties doesn't exists.");
401 System.out.println(e.toString());
402 }//end if
403 }//end catch
404
405 if (debug)
406 System.out.println("checking for system-known ports of type "+PortType);
407 if (debug)
408 System.out.println("checking registry for ports of type "+PortType);
409
410 switch (PortType) {
411 case CommPortIdentifier.PORT_SERIAL:
412 if ((val = System.getProperty("gnu.io.rxtx.SerialPorts")) == null)
413 val = System.getProperty("gnu.io.SerialPorts");
414 break;
415
416 case CommPortIdentifier.PORT_PARALLEL:
417 if ((val = System.getProperty("gnu.io.rxtx.ParallelPorts")) == null)
418 val = System.getProperty("gnu.io.ParallelPorts");
419 break;
420 default:
421 if (debug)
422 System.out.println("unknown port type "+PortType+" passed to RXTXCommDriver.registerSpecifiedPorts()");
423 }
424
425 if (val != null) {
426 addSpecifiedPorts(val, PortType);
427 return true;
428 } else return false;
429 }
430
431 /*
432 * Look for all entries in deviceDirectory, and if they look like they should
433 * be serial ports on this OS and they can be opened then register
434 * them.
435 *
436 */
437 private void registerScannedPorts(int PortType)
438 {
439 String[] CandidateDeviceNames;
440 if (debug)
441 System.out.println("scanning device directory "+deviceDirectory+" for ports of type "+PortType);
442 if(osName.equals("Windows CE"))
443 {
444 String[] temp =
445 { "COM1:", "COM2:","COM3:","COM4:",
446 "COM5:", "COM6:", "COM7:", "COM8:" };
447 CandidateDeviceNames=temp;
448 }
449 else if(osName.toLowerCase().indexOf("windows") != -1 )
450 {
451 /*
452 { "COM1:", "COM2:","COM3:","COM4:",
453 "COM5:", "COM6:", "COM7:", "COM8:" };
454 */
455 /* //./name is supposed to work for port numbers > 8 */
456 /*
457 { "//./COM1", "//./COM2", "//./COM3",
458 "//./COM4", "//./COM5", "//./COM6",
459 "//./COM7", "//./COM8" };
460 */
461 String[] temp =
462 {
463 "COM1", "COM2", "COM3",
464 "COM4", "COM5", "COM6",
465 "COM7", "COM8",
466 /*
467 OK, you asked for it The thread gods will
468 not like this.
469 */
470 "COM9", "COM10", "COM11",
471 "COM12", "COM13", "COM14",
472 "COM15", "COM16",
473 /*
474 Lets toss in LPT too!
475 */
476 "LPT1", "LPT2", "LPT3"
477 };
478 /*
479 { "COM1", "COM2","COM3","COM4",
480 "COM5", "COM6", "COM7", "COM8" };
481 */
482 CandidateDeviceNames=temp;
483 }
484 else if ( osName.equals("Solaris") || osName.equals("SunOS"))
485 {
486 /* Solaris uses a few different ways to identify ports.
487 They could be /dev/term/a /dev/term0 /dev/cua/a /dev/cuaa
488 the /dev/???/a appears to be on more systems.
489
490 The uucp lock files should not cause problems.
491 */
492 /*
493 File dev = new File( "/dev/term" );
494 String deva[] = dev.list();
495 dev = new File( "/dev/cua" );
496 String devb[] = dev.list();
497 String[] temp = new String[ deva.length + devb.length ];
498 for(int j =0;j<deva.length;j++)
499 deva[j] = "term/" + deva[j];
500 for(int j =0;j<devb.length;j++)
501 devb[j] = "cua/" + devb[j];
502 System.arraycopy( deva, 0, temp, 0, deva.length );
503 System.arraycopy( devb, 0, temp,
504 deva.length, devb.length );
505 if( debug ) {
506 for( int j = 0; j< temp.length;j++)
507 System.out.println( temp[j] );
508 }
509 CandidateDeviceNames=temp;
510 */
511
512 /*
513
514 ok.. Look the the dirctories representing the port
515 kernel driver interface.
516
517 If there are entries there are possibly ports we can
518 use and need to enumerate.
519 */
520
521 String term[] = new String[2];
522 int l = 0;
523 File dev = null;
524
525 dev = new File( "/dev/term" );
526 if( dev.list().length > 0 );
527 term[l++] = new String( "term/" );
528 /*
529 dev = new File( "/dev/cua0" );
530 if( dev.list().length > 0 );
531 term[l++] = new String( "cua/" );
532 */
533 String[] temp = new String[l];
534 for(l--;l >= 0;l--)
535 temp[l] = term[l];
536 CandidateDeviceNames=temp;
537 }
538 else
539 {
540 File dev = new File( deviceDirectory );
541 String[] temp = dev.list();
542 CandidateDeviceNames=temp;
543 }
544 if (CandidateDeviceNames==null)
545 {
546 if (debug)
547 System.out.println("RXTXCommDriver:registerScannedPorts() no Device files to check ");
548 return;
549 }
550
551 String CandidatePortPrefixes[] = {};
552 switch (PortType) {
553 case CommPortIdentifier.PORT_SERIAL:
554 if (debug)
555 System.out.println("scanning for serial ports for os "+osName);
556 if(osName.equals("Linux"))
557 {
558 String[] Temp = {
559 "ttyS", // linux Serial Ports
560 "ttySA" // for the IPAQs
561 };
562 CandidatePortPrefixes=Temp;
563 }
564 else if(osName.equals("Linux-all-ports"))
565 {
566 /* if you want to enumerate all ports ~5000
567 possible, then replace the above with this
568 */
569 String[] Temp = {
570 "comx", // linux COMMX synchronous serial card
571 "holter", // custom card for heart monitoring
572 "modem", // linux symbolic link to modem.
573 "ttyircomm", // linux IrCommdevices (IrDA serial emu)
574 "ttycosa0c", // linux COSA/SRP synchronous serial card
575 "ttycosa1c", // linux COSA/SRP synchronous serial card
576 "ttyC", // linux cyclades cards
577 "ttyCH",// linux Chase Research AT/PCI-Fast serial card
578 "ttyD", // linux Digiboard serial card
579 "ttyE", // linux Stallion serial card
580 "ttyF", // linux Computone IntelliPort serial card
581 "ttyH", // linux Chase serial card
582 "ttyI", // linux virtual modems
583 "ttyL", // linux SDL RISCom serial card
584 "ttyM", // linux PAM Software's multimodem boards
585 // linux ISI serial card
586 "ttyMX",// linux Moxa Smart IO cards
587 "ttyP", // linux Hayes ESP serial card
588 "ttyR", // linux comtrol cards
589 // linux Specialix RIO serial card
590 "ttyS", // linux Serial Ports
591 "ttySI",// linux SmartIO serial card
592 "ttySR",// linux Specialix RIO serial card 257+
593 "ttyT", // linux Technology Concepts serial card
594 "ttyUSB",//linux USB serial converters
595 "ttyV", // linux Comtrol VS-1000 serial controller
596 "ttyW", // linux specialix cards
597 "ttyX" // linux SpecialX serial card
598 };
599 CandidatePortPrefixes=Temp;
600 }
601 else if(osName.toLowerCase().indexOf("qnx") != -1 )
602 {
603 String[] Temp = {
604 "ser"
605 };
606 CandidatePortPrefixes=Temp;
607 }
608 else if(osName.equals("Irix"))
609 {
610 String[] Temp = {
611 "ttyc", // irix raw character devices
612 "ttyd", // irix basic serial ports
613 "ttyf", // irix serial ports with hardware flow
614 "ttym", // irix modems
615 "ttyq", // irix pseudo ttys
616 "tty4d",// irix RS422
617 "tty4f",// irix RS422 with HSKo/HSki
618 "midi", // irix serial midi
619 "us" // irix mapped interface
620 };
621 CandidatePortPrefixes=Temp;
622 }
623 else if(osName.equals("FreeBSD")) //FIXME this is probably wrong
624 {
625 String[] Temp = {
626 "ttyd", //general purpose serial ports
627 "cuaa", //dialout serial ports
628 "ttyA", //Specialix SI/XIO dialin ports
629 "cuaA", //Specialix SI/XIO dialout ports
630 "ttyD", //Digiboard - 16 dialin ports
631 "cuaD", //Digiboard - 16 dialout ports
632 "ttyE", //Stallion EasyIO (stl) dialin ports
633 "cuaE", //Stallion EasyIO (stl) dialout ports
634 "ttyF", //Stallion Brumby (stli) dialin ports
635 "cuaF", //Stallion Brumby (stli) dialout ports
636 "ttyR", //Rocketport dialin ports
637 "cuaR", //Rocketport dialout ports
638 "stl" //Stallion EasyIO board or Brumby N
639 };
640 CandidatePortPrefixes=Temp;
641 }
642 else if(osName.equals("NetBSD")) // FIXME this is probably wrong
643 {
644 String[] Temp = {
645 "tty0" // netbsd serial ports
646 };
647 CandidatePortPrefixes=Temp;
648 }
649 else if ( osName.equals("Solaris")
650 || osName.equals("SunOS"))
651 {
652 String[] Temp = {
653 "term/",
654 "cua/"
655 };
656 CandidatePortPrefixes=Temp;
657 }
658 else if(osName.equals("HP-UX"))
659 {
660 String[] Temp = {
661 "tty0p",// HP-UX serial ports
662 "tty1p" // HP-UX serial ports
663 };
664 CandidatePortPrefixes=Temp;
665 }
666
667 else if(osName.equals("UnixWare") ||
668 osName.equals("OpenUNIX"))
669 {
670 String[] Temp = {
671 "tty00s", // UW7/OU8 serial ports
672 "tty01s",
673 "tty02s",
674 "tty03s"
675 };
676 CandidatePortPrefixes=Temp;
677 }
678
679 else if (osName.equals("OpenServer"))
680 {
681 String[] Temp = {
682 "tty1A", // OSR5 serial ports
683 "tty2A",
684 "tty3A",
685 "tty4A",
686 "tty5A",
687 "tty6A",
688 "tty7A",
689 "tty8A",
690 "tty9A",
691 "tty10A",
692 "tty11A",
693 "tty12A",
694 "tty13A",
695 "tty14A",
696 "tty15A",
697 "tty16A",
698 "ttyu1A", // OSR5 USB-serial ports
699 "ttyu2A",
700 "ttyu3A",
701 "ttyu4A",
702 "ttyu5A",
703 "ttyu6A",
704 "ttyu7A",
705 "ttyu8A",
706 "ttyu9A",
707 "ttyu10A",
708 "ttyu11A",
709 "ttyu12A",
710 "ttyu13A",
711 "ttyu14A",
712 "ttyu15A",
713 "ttyu16A"
714 };
715 CandidatePortPrefixes=Temp;
716 }
717 else if (osName.equals("Compaq's Digital UNIX") || osName.equals("OSF1"))
718 {
719 String[] Temp = {
720 "tty0" // Digital Unix serial ports
721 };
722 CandidatePortPrefixes=Temp;
723 }
724
725 else if(osName.equals("BeOS"))
726 {
727 String[] Temp = {
728 "serial" // BeOS serial ports
729 };
730 CandidatePortPrefixes=Temp;
731 }
732 else if(osName.equals("Mac OS X"))
733 {
734 String[] Temp = {
735 // Keyspan USA-28X adapter, USB port 1
736 "cu.KeyUSA28X191.",
737 // Keyspan USA-28X adapter, USB port 1
738 "tty.KeyUSA28X191.",
739 // Keyspan USA-28X adapter, USB port 2
740 "cu.KeyUSA28X181.",
741 // Keyspan USA-28X adapter, USB port 2
742 "tty.KeyUSA28X181.",
743 // Keyspan USA-19 adapter
744 "cu.KeyUSA19181.",
745 // Keyspan USA-19 adapter
746 "tty.KeyUSA19181."
747 };
748 CandidatePortPrefixes=Temp;
749 }
750 else if(osName.toLowerCase().indexOf("windows") != -1 )
751 {
752 String[] Temp = {
753 "COM" // win32 serial ports
754 //"//./COM" // win32 serial ports
755 };
756 CandidatePortPrefixes=Temp;
757 }
758 else
759 {
760 if (debug)
761 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().");
762 }
763 break;
764
765 case CommPortIdentifier.PORT_PARALLEL:
766 if (debug)
767 System.out.println("scanning for parallel ports for os "+osName);
768 /** Get the Parallel port prefixes for the running os
769 * Holger Lehmann
770 * July 12, 1999
771 * IBM
772 */
773 if(osName.equals("Linux")
774 /*
775 || osName.equals("NetBSD") FIXME
776 || osName.equals("HP-UX") FIXME
777 || osName.equals("Irix") FIXME
778 || osName.equals("BeOS") FIXME
779 || osName.equals("Compaq's Digital UNIX") FIXME
780 */
781 )
782 {
783 String[] temp={
784 "lp" // linux printer port
785 };
786 CandidatePortPrefixes=temp;
787 }
788 else if(osName.equals("FreeBSD"))
789 {
790 String[] temp={
791 "lpt"
792 };
793 CandidatePortPrefixes=temp;
794 }
795 else if(osName.toLowerCase().indexOf("windows") != -1 )
796 {
797 String[] temp={
798 "LPT"
799 };
800 CandidatePortPrefixes=temp;
801 }
802 else /* printer support is green */
803 {
804 String [] temp={};
805 CandidatePortPrefixes=temp;
806 }
807 break;
808 default:
809 if (debug)
810 System.out.println("Unknown PortType "+PortType+" passed to RXTXCommDriver.registerScannedPorts()");
811 }
812 registerValidPorts(CandidateDeviceNames, CandidatePortPrefixes, PortType);
813 }
814
815
816 /*
817 * <p>From the NullDriver.java CommAPI sample.
818 */
819 /**
820 * @param PortName The name of the port the OS recognizes
821 * @param PortType CommPortIdentifier.PORT_SERIAL or PORT_PARALLEL
822 * @returns CommPort
823 * getCommPort() will be called by CommPortIdentifier from its
824 * openPort() method. PortName is a string that was registered earlier
825 * using the CommPortIdentifier.addPortName() method. getCommPort()
826 * returns an object that extends either SerialPort or ParallelPort.
827 */
828 public CommPort getCommPort( String PortName, int PortType )
829 {
830 if (debug) System.out.println("RXTXCommDriver:getCommPort("
831 +PortName+","+PortType+")");
832 try {
833 switch (PortType) {
834 case CommPortIdentifier.PORT_SERIAL:
835 if(osName.toLowerCase().indexOf("windows") == -1 )
836 {
837
838 return new RXTXPort( PortName );
839 }
840 else
841 {
842 return new RXTXPort( deviceDirectory + PortName );
843 }
844 case CommPortIdentifier.PORT_PARALLEL:
845 //return new LPRPort( PortName );
846 default:
847 if (debug)
848 System.out.println("unknown PortType "+PortType+" passed to RXTXCommDriver.getCommPort()");
849 }
850 } catch( PortInUseException e ) {
851 if (debug)
852 System.out.println(
853 "Port "+PortName+" in use by another application");
854 }
855 return null;
856 }
857
858 /* Yikes. Trying to call println from C for odd reasons */
859 public void Report( String arg )
860 {
861 System.out.println(arg);
862 }
863 }