~ubuntu-branches/ubuntu/edgy/rxtx/edgy-201105201527

« back to all changes in this revision

Viewing changes to CNI/RXTXCommDriver.java

  • Committer: Bazaar Package Importer
  • Author(s): Mario Joussen
  • Date: 2006-03-01 18:56:52 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060301185652-ri9941gi01goklvz
Tags: 2.1.7-2
Fixed stupid bug in clean target.
(closes: Bug#354859)

Show diffs side-by-side

added added

removed removed

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