Testing out the PPD42 Air Quality Sensor, with an MSP430 Launchpad and graphing the data with GNUplot.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

825 lines
24 KiB

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