├── .gitattributes ├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── src └── main │ ├── c │ ├── .gitignore │ ├── JAVA_HOME.mk │ ├── Makefile │ ├── cross-compile-libs │ │ ├── ARM_32 │ │ │ ├── liblockdev.so │ │ │ └── liblockdev.so.1 │ │ ├── ARM_64 │ │ │ ├── liblockdev.so │ │ │ └── liblockdev.so.1 │ │ ├── README.TXT │ │ └── x86_32 │ │ │ ├── liblockdev.so │ │ │ └── liblockdev.so.1 │ ├── include │ │ ├── SerialImp.h │ │ ├── config.h │ │ ├── target │ │ │ ├── gnu_io_CommPortIdentifier.h │ │ │ ├── gnu_io_RXTXCommDriver.h │ │ │ ├── gnu_io_RXTXPort.h │ │ │ ├── gnu_io_RXTXPort_MonitorThread.h │ │ │ ├── gnu_io_RXTXPort_SerialInputStream.h │ │ │ ├── gnu_io_RXTXPort_SerialOutputStream.h │ │ │ ├── gnu_io_RXTXVersion.h │ │ │ └── gnu_io_Zystem.h │ │ └── windows │ │ │ ├── win32 │ │ │ └── jni_md.h │ │ │ └── win32termios.h │ ├── natives.mk │ ├── platform.mk │ ├── resources │ │ └── native │ │ │ ├── freebsd │ │ │ ├── ARM_64 │ │ │ │ └── libNRJavaSerialv8.so │ │ │ ├── x86_32 │ │ │ │ └── libNRJavaSerial.so │ │ │ └── x86_64 │ │ │ │ └── libNRJavaSerial.so │ │ │ ├── linux │ │ │ ├── ARM_32 │ │ │ │ ├── libNRJavaSerialv5.so │ │ │ │ ├── libNRJavaSerialv6.so │ │ │ │ ├── libNRJavaSerialv6_HF.so │ │ │ │ ├── libNRJavaSerialv7.so │ │ │ │ ├── libNRJavaSerialv7_HF.so │ │ │ │ ├── libNRJavaSerialv8.so │ │ │ │ └── libNRJavaSerialv8_HF.so │ │ │ ├── ARM_64 │ │ │ │ └── libNRJavaSerialv8.so │ │ │ ├── PPC │ │ │ │ └── libNRJavaSerial.so │ │ │ ├── x86_32 │ │ │ │ └── libNRJavaSerial.so │ │ │ └── x86_64 │ │ │ │ └── libNRJavaSerial.so │ │ │ ├── osx │ │ │ └── libNRJavaSerial.jnilib │ │ │ └── windows │ │ │ ├── x86_32 │ │ │ └── libNRJavaSerial.dll │ │ │ └── x86_64 │ │ │ └── libNRJavaSerial.dll │ └── src │ │ ├── SerialImp.c │ │ ├── fixup.c │ │ ├── fuserImp.c │ │ └── windows │ │ ├── init.c │ │ └── termios.c │ ├── java │ └── gnu │ │ └── io │ │ ├── CommDriver.java │ │ ├── CommPort.java │ │ ├── CommPortEnumerator.java │ │ ├── CommPortIdentifier.java │ │ ├── CommPortOwnershipListener.java │ │ ├── NRSerialPort.java │ │ ├── NativeResource.java │ │ ├── NativeResourceException.java │ │ ├── NoSuchPortException.java │ │ ├── PortInUseException.java │ │ ├── RXTXCommDriver.java │ │ ├── RXTXPort.java │ │ ├── RXTXVersion.java │ │ ├── SerialManager.java │ │ ├── SerialPort.java │ │ ├── SerialPortEvent.java │ │ ├── SerialPortEventListener.java │ │ ├── UnSupportedLoggerException.java │ │ ├── UnsupportedCommOperationException.java │ │ ├── Zystem.java │ │ ├── factory │ │ ├── DefaultSerialPortFactory.java │ │ ├── RFC2217PortCreator.java │ │ ├── RxTxPortCreator.java │ │ ├── SerialPortCreator.java │ │ ├── SerialPortFactory.java │ │ └── SerialPortRegistry.java │ │ └── rfc2217 │ │ ├── AbstractComPortCommandSwitch.java │ │ ├── BaudRateCommand.java │ │ ├── ComPortCommand.java │ │ ├── ComPortCommandSwitch.java │ │ ├── ComPortOptionHandler.java │ │ ├── ControlCommand.java │ │ ├── DataSizeCommand.java │ │ ├── FlowControlResumeCommand.java │ │ ├── FlowControlSuspendCommand.java │ │ ├── LineStateMaskCommand.java │ │ ├── ModemStateMaskCommand.java │ │ ├── NotifyLineStateCommand.java │ │ ├── NotifyModemStateCommand.java │ │ ├── ParityCommand.java │ │ ├── PurgeDataCommand.java │ │ ├── RFC2217.java │ │ ├── SignatureCommand.java │ │ ├── StopSizeCommand.java │ │ ├── TelnetSerialPort.java │ │ ├── TransmitBinaryOptionHandler.java │ │ ├── Util.java │ │ └── Version.java │ └── resources │ ├── com │ └── neuronrobotics │ │ └── nrjavaserial │ │ └── build.properties │ └── jvser.properties └── test └── src └── test ├── NRJavaSerialTest.java ├── ReadTest.java ├── Rfc2217Test.java └── SerialTest.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Our code formatter, Spotless, checks that file line endings match whatever 2 | # Git thinks they should be. Unfortunately, Git's default thinking is that 3 | # lines should follow the platform's native line ending: see 4 | # https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreeol. 5 | # Git has this thought rattling around in the back of its mind even when 6 | # automatic line ending convertion (`core.autocrlf`) is turned off (`false`). 7 | # When Spotless rolls up and asks Git what it thinks on a Windows system, it'll 8 | # say “CRLF” (assuming the user hasn't overridden `core.eol`), even when all of 9 | # the checked-out files are LF-terminated. So Spotless will throw an error for 10 | # every. Single. Line of source. 11 | # 12 | # The solution is to tell Git that we want all files (`*`) to be LF-terminated 13 | # (`eol=lf`), but we don't ever want it to do any conversions automatically 14 | # (`-text`). 15 | # 16 | # Some sources, including Spotless themselves (https://github.com/diffplug/ 17 | # spotless/tree/main/plugin-gradle#line-endings-and-encodings-invisible-stuff), 18 | # suggest using: 19 | # 20 | # * text eol=lf 21 | # 22 | # This forces Git to treat all files (`*`) as text (`text`) with LF-terminated 23 | # lines (`eol=lf`). This configuration will break any binary files checked into 24 | # the repository! Git will perform end-of-line mangling – sorry, 25 | # “normalization” – on checkout of all files it thinks contain text. If it 26 | # thinks your binary files are text and should have LF-terminated lines, then 27 | # it'll happily replace all CRLF byte sequences (0x0D0A) with just LF (0x0A). 28 | # 29 | # So, to recap: keep line ending conversions disabled, but maintain a correct 30 | # opinion about what the line endings should be. 31 | * -text eol=lf 32 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | - push 4 | - pull_request 5 | 6 | jobs: 7 | natives-linux-windows: 8 | name: Linux (x86/ARM/PPC) and Windows native library compilation 9 | runs-on: ubuntu-18.04 10 | 11 | defaults: 12 | run: 13 | working-directory: src/main/c 14 | 15 | steps: 16 | - name: Checkout the target branch 17 | uses: actions/checkout@v2 18 | - name: Setup Java 19 | uses: actions/setup-java@v1 20 | with: 21 | java-version: 8 22 | - name: Install build prerequisites 23 | run: | 24 | sudo apt update 25 | sudo make crosstools 26 | 27 | - name: Build the Linux and Windows native libraries 28 | run: | 29 | make clean-linux clean-windows 30 | make linux windows 31 | 32 | # The names of the artifacts containing native libraries correspond 33 | # exactly to the directories inside `src/main/c/resources/native`. That 34 | # way, the Java build job can pull down all artifacts and unpack them 35 | # into that directory to overwrite the versions in-repo. This is sadly 36 | # necessary because the actions/download-artifact@v2 action flattens 37 | # paths inside artifacts. If it retained full relative paths, we could 38 | # put Linux and Windows natives inside the same artifact, and we could be 39 | # flexible with the artifact names. But it doesn't, so we can't, and we 40 | # can't. 41 | - name: Upload Linux native libraries 42 | uses: actions/upload-artifact@v2 43 | with: 44 | name: linux 45 | path: src/main/c/resources/native/linux 46 | - name: Upload Windows native libraries 47 | uses: actions/upload-artifact@v2 48 | with: 49 | name: windows 50 | path: src/main/c/resources/native/windows 51 | 52 | natives-macos: 53 | name: macOS native library compilation 54 | runs-on: macos-10.15 55 | 56 | defaults: 57 | run: 58 | working-directory: src/main/c 59 | 60 | steps: 61 | - name: Checkout the target branch 62 | uses: actions/checkout@v2 63 | - name: Setup Java 64 | uses: actions/setup-java@v1 65 | with: 66 | java-version: 8 67 | 68 | - name: Build the macOS native libraries 69 | run: | 70 | make clean-osx 71 | make osx 72 | 73 | - name: Upload macOS native libraries 74 | uses: actions/upload-artifact@v2 75 | with: 76 | name: osx 77 | path: src/main/c/resources/native/osx/libNRJavaSerial.jnilib 78 | 79 | natives-freebsd: 80 | name: FreeBSD native library compilation 81 | runs-on: ubuntu-18.04 82 | container: 83 | image: empterdose/freebsd-cross-build:9.3 84 | env: 85 | JAVA_HOME: /usr/lib/jvm/default-jvm 86 | 87 | defaults: 88 | run: 89 | working-directory: src/main/c 90 | 91 | steps: 92 | - name: Checkout the target branch 93 | uses: actions/checkout@v2 94 | - name: Setup Java 95 | # This feels extremely dirty, but the only native header we care about 96 | # is `jni_md.h`, and it is exactly identical between Linux and FreeBSD 97 | # (at least in OpenJDK 8). 98 | run: | 99 | apk add openjdk8 100 | ln -s $JAVA_HOME/include/linux $JAVA_HOME/include/freebsd 101 | 102 | - name: Build the FreeBSD native libraries 103 | run: | 104 | make clean-freebsd 105 | settarget i386-freebsd9 make freebsd32 106 | settarget x86_64-freebsd9 make freebsd64 107 | 108 | - name: Upload FreeBSD native libraries 109 | uses: actions/upload-artifact@v2 110 | with: 111 | name: freebsd 112 | path: src/main/c/resources/native/freebsd 113 | 114 | java: 115 | name: Java compilation 116 | runs-on: ubuntu-18.04 117 | 118 | needs: 119 | - natives-linux-windows 120 | - natives-macos 121 | - natives-freebsd 122 | 123 | steps: 124 | # We use Spotless in “ratchet mode” to incrementally enforce code 125 | # formatting throughout the project. In order to ensure feature branches 126 | # don't regress formatting when compared with the master branch, we need 127 | # to have a local copy of the master branch for comparison. 128 | - name: Checkout the master branch 129 | uses: actions/checkout@v2 130 | with: 131 | ref: master 132 | - name: Checkout the target branch 133 | uses: actions/checkout@v2 134 | - name: Setup Java 135 | uses: actions/setup-java@v1 136 | with: 137 | java-version: 8 138 | 139 | - name: Download native libraries 140 | uses: actions/download-artifact@v2 141 | with: 142 | path: src/main/c/resources/native 143 | 144 | - name: Build the Java library 145 | run: ./gradlew build 146 | 147 | - name: Determine commit hash for artifact filename 148 | id: vars 149 | run: echo "::set-output name=short-rev::$(git rev-parse --short HEAD)" 150 | - name: Upload build artifacts 151 | uses: actions/upload-artifact@v2 152 | with: 153 | name: nrjavaserial-${{steps.vars.outputs.short-rev}} 154 | path: build/libs/*.jar 155 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /bin/ 3 | /gradle.properties 4 | .gradle/* 5 | .classpath 6 | .project 7 | .settings/ 8 | *~* 9 | /.gradle/ 10 | /hs_err_pid26993.log 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 2 | RXTX is a native interface to serial ports in java. 3 | 4 | A copy of the LGPL v 2.1 may be found at 5 | http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt. 6 | A copy is here for your convenience. 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2.1 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | An executable that contains no derivative of any portion of RXTX, but 19 | is designed to work with RXTX by being dynamically linked with it, 20 | is considered a "work that uses the Library" subject to the terms and 21 | conditions of the GNU Lesser General Public License. 22 | 23 | The following has been added to the RXTX License to remove 24 | any confusion about linking to RXTX. We want to allow in part what 25 | section 5, paragraph 2 of the LGPL does not permit in the special 26 | case of linking over a controlled interface. The intent is to add a 27 | Java Specification Request or standards body defined interface in the 28 | future as another exception but one is not currently available. 29 | 30 | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 31 | 32 | As a special exception, the copyright holders of RXTX give you 33 | permission to link RXTX with independent modules that communicate with 34 | RXTX solely through the Sun Microsytems CommAPI interface version 2, 35 | regardless of the license terms of these independent modules, and to copy 36 | and distribute the resulting combined work under terms of your choice, 37 | provided that every copy of the combined work is accompanied by a complete 38 | copy of the source code of RXTX (the version of RXTX used to produce the 39 | combined work), being distributed under the terms of the GNU Lesser General 40 | Public License plus this exception. An independent module is a 41 | module which is not derived from or based on RXTX. 42 | 43 | Note that people who make modified versions of RXTX are not obligated 44 | to grant this special exception for their modified versions; it is 45 | their choice whether to do so. The GNU Lesser General Public License 46 | gives permission to release a modified version without this exception; this 47 | exception also makes it possible to release a modified version which 48 | carries forward this exception. 49 | 50 | You should have received a copy of the GNU Lesser General Public 51 | License along with this library; if not, write to the Free 52 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 53 | All trademarks belong to their respective owners. 54 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include src/main/c/platform.mk 2 | 3 | define ONLY_GRADLE 4 | You haven't specified a platform to build the native library, so I'm only going 5 | to build the Java portion of the project. To build natives, specify a platform: 6 | 7 | make linux|osx|freebsd|windows 8 | 9 | endef 10 | 11 | only-gradle: 12 | $(info $(ONLY_GRADLE)) 13 | $(call gradlew-build) 14 | %: 15 | $(MAKE) -C src/main/c $@ 16 | $(call gradlew-build) 17 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "biz.aQute.bnd.builder" version "5.0.1" 3 | id "com.diffplug.spotless" version "5.9.0" 4 | } 5 | 6 | apply plugin: 'java' 7 | apply plugin: 'eclipse' 8 | apply plugin: 'maven' 9 | apply plugin: 'signing' 10 | 11 | [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' 12 | 13 | File buildDir = file("."); 14 | Properties props = new Properties() 15 | props.load(new FileInputStream(buildDir.getAbsolutePath() + "/src/main/resources/com/neuronrobotics/nrjavaserial/build.properties")) 16 | 17 | group = "com.neuronrobotics" 18 | archivesBaseName = "nrjavaserial" 19 | version = props."app.version" 20 | 21 | sourceSets { 22 | test { 23 | java { 24 | srcDirs = ["test/src"] 25 | } 26 | } 27 | main { 28 | resources { 29 | srcDirs = ["src/main/resources", "src/main/c/resources"] 30 | includes = ["**/*.so","**/*.dll", "**/*.jnilib","**/*.properties"] 31 | } 32 | } 33 | } 34 | 35 | jar.archiveName = "nrjavaserial-${props.'app.version'}.jar" 36 | 37 | repositories { 38 | mavenCentral() 39 | jcenter() 40 | } 41 | 42 | dependencies { 43 | compile fileTree(dir: 'libs', includes: ['*.jar']) 44 | testCompile 'junit:junit:4.12' 45 | compile 'commons-net:commons-net:3.9.0' 46 | compileOnly 'net.java.dev.jna:jna:4.4.0' 47 | compileOnly 'net.java.dev.jna:jna-platform:4.4.0' 48 | } 49 | 50 | jar { 51 | jar.duplicatesStrategy = DuplicatesStrategy.EXCLUDE 52 | 53 | bnd("Created-By": "Commonwealth Robotics Cooperative", 54 | "Specification-Title": props."app.name", 55 | "Specification-Version": props."app.version", 56 | "Specification-Vendor": "Commonwealth Robotics Cooperative", 57 | "Implementation-Title": props."app.name", 58 | "Implementation-Version" : props."app.version", 59 | "Implementation-Vendor": "Commonwealth Robotics Cooperative", 60 | "Import-Package": "com.sun.jna.platform.win32;resolution:=optional,org.apache.commons.net.telnet;resolution:=optional,!gnu.io*,*", 61 | "Export-Package": "gnu.io*" 62 | ) 63 | 64 | } 65 | 66 | task javadocJar(type: Jar) { 67 | classifier = 'javadoc' 68 | from javadoc 69 | } 70 | 71 | task sourcesJar(type: Jar) { 72 | classifier = 'sources' 73 | from (sourceSets.main.allSource) { 74 | exclude 'native/' 75 | } 76 | } 77 | 78 | spotless { 79 | enforceCheck false 80 | ratchetFrom 'origin/master' 81 | 82 | format 'misc', { 83 | target '*.gradle' 84 | 85 | trimTrailingWhitespace() 86 | indentWithTabs() 87 | endWithNewline() 88 | } 89 | 90 | java { 91 | importOrder() 92 | removeUnusedImports() 93 | eclipse() 94 | } 95 | } 96 | /* 97 | signing { 98 | required { 99 | gradle.taskGraph.hasTask("uploadArchives") 100 | } 101 | sign configurations.archives 102 | } 103 | 104 | artifacts { 105 | archives javadocJar 106 | archives sourcesJar 107 | archives jar 108 | } 109 | 110 | //import org.gradle.plugins.signing.Sign 111 | // 112 | //gradle.taskGraph.whenReady { taskGraph -> 113 | // if (taskGraph.allTasks.any { it instanceof Sign }) { 114 | // // Use Java 6's console to read from the console (no good for 115 | // // a CI environment) 116 | // Console console = System.console() 117 | // console.printf "\n\nWe have to sign some things in this build." + 118 | // "\n\nPlease enter your signing details.\n\n" 119 | // 120 | // def id = console.readLine("PGP Key Id: ") 121 | // def file = console.readLine("PGP Secret Key Ring File (absolute path): ") 122 | // def password = console.readPassword("PGP Private Key Password: ") 123 | // 124 | // allprojects { ext."signing.keyId" = id } 125 | // allprojects { ext."signing.secretKeyRingFile" = file } 126 | // allprojects { ext."signing.password" = password } 127 | // 128 | // console.printf "\nThanks.\n\n" 129 | // } 130 | //} 131 | 132 | uploadArchives { 133 | repositories { 134 | mavenDeployer { 135 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 136 | 137 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { 138 | authentication(userName: ossrhUsername, password: ossrhPassword) 139 | } 140 | 141 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { 142 | authentication(userName: ossrhUsername, password: ossrhPassword) 143 | } 144 | 145 | 146 | pom.project { 147 | name 'NRJavaSerial' 148 | packaging 'jar' 149 | description 'A fork of the RXTX library with a focus on ease of use and embeddability in other libraries.' 150 | url 'http://neuronrobotics.com' 151 | 152 | scm { 153 | connection 'scm:git:https://github.com/NeuronRobotics/nrjavaserial.git' 154 | developerConnection 'scm:git:git@github.com:NeuronRobotics/nrjavaserial.git' 155 | url 'https://github.com/NeuronRobotics/nrjavaserial' 156 | } 157 | 158 | licenses { 159 | license { 160 | name 'The Apache License, Version 2.0' 161 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 162 | } 163 | } 164 | 165 | developers { 166 | developer { 167 | id 'madhephaestus' 168 | name 'Kevin Harrington' 169 | email 'kharrington@neuronrobotics.com' 170 | } 171 | } 172 | } 173 | } 174 | } 175 | } 176 | */ 177 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | /home/hephaestus/gradle.properties -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto init 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto init 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :init 68 | @rem Get command-line arguments, handling Windows variants 69 | 70 | if not "%OS%" == "Windows_NT" goto win9xME_args 71 | 72 | :win9xME_args 73 | @rem Slurp the command line arguments. 74 | set CMD_LINE_ARGS= 75 | set _SKIP=2 76 | 77 | :win9xME_args_slurp 78 | if "x%~1" == "x" goto execute 79 | 80 | set CMD_LINE_ARGS=%* 81 | 82 | :execute 83 | @rem Setup the command line 84 | 85 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 86 | 87 | @rem Execute Gradle 88 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 89 | 90 | :end 91 | @rem End local scope for the variables with windows NT shell 92 | if "%ERRORLEVEL%"=="0" goto mainEnd 93 | 94 | :fail 95 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 96 | rem the _cmd.exe /c_ return code! 97 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 98 | exit /b 1 99 | 100 | :mainEnd 101 | if "%OS%"=="Windows_NT" endlocal 102 | 103 | :omega 104 | -------------------------------------------------------------------------------- /src/main/c/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .project 3 | .cproject 4 | -------------------------------------------------------------------------------- /src/main/c/JAVA_HOME.mk: -------------------------------------------------------------------------------- 1 | # “Undefined JAVA_HOME” is a strong contender for the most hated error message 2 | # in all of software development, so we'll take a shot at figuring it out 3 | # before leaving the user to fend for themselves. 4 | # 5 | # The detection here tries to be failure-tollerant, but Make is not a very good 6 | # environment for either resilient string manipulation or reliable 7 | # cross-platform path operations. If you're reading this because you think the 8 | # path detection contained herein is causing trouble, the easiest way to avoid 9 | # this file altogether is to define the JAVA_HOME environment variable. 10 | 11 | ifndef JAVA_HOME 12 | 13 | define MISSING_JAVA 14 | The JAVA_HOME environment variable has not been defined, and you don't have the 15 | `java` binary on your PATH, so I can't determine the location of your Java 16 | installation automatically. Please set the JAVA_HOME environment variable to 17 | the location of your preferred Java installation 18 | endef 19 | 20 | define EXPLICITLY_SET 21 | If that's not correct, or to suppress this message, explicitly set the 22 | JAVA_HOME environment variable to the location of your preferred Java 23 | installation. 24 | endef 25 | 26 | define DARWIN_GUESSED_JAVA_HOME 27 | The JAVA_HOME environment variable has not been defined; 28 | based on the output of `/usr/libexec/java_home`, I'm going to use: 29 | 30 | $(JAVA_HOME) 31 | 32 | $(EXPLICITLY_SET) 33 | endef 34 | 35 | define GUESSED_JAVA_HOME 36 | The JAVA_HOME environment variable has not been defined. 37 | Based on the location of the `java` binary, I've guessed it's: 38 | 39 | $(JAVA_HOME) 40 | 41 | $(EXPLICITLY_SET) 42 | endef 43 | 44 | # Windows will set the “OS” environment variable by default. 45 | ifeq ($(OS),) 46 | OS := $(shell uname) 47 | endif 48 | 49 | # On macOS, we can just ask where Java is. 50 | ifeq ($(OS),Darwin) 51 | JAVA_HOME=$(shell /usr/libexec/java_home) 52 | $(warning $(DARWIN_GUESSED_JAVA_HOME)) 53 | 54 | else 55 | 56 | # First, find java(1). On POSIX systems, we can use which(1); on Windows, we 57 | # need to use WHERE. 58 | WHICH=which 59 | ifeq ($(OS),Windows_NT) 60 | # Just checking whether we're on Windows isn't good enough: if we're running in 61 | # a Cygwin or MinGW environment (e.g., Git Bash) which requires Unix-like 62 | # absolute paths (e.g., “/c/foo/bar”, not “C:\foo\bar”), then we still need to 63 | # use which(1) – WHERE will give us paths we can't use. TERM seems like a 64 | # pretty safe environment variable to check; it's a Unix-ism not embraced by 65 | # cmd.exe or PowerShell, but it should be set by emulation environments. 66 | ifndef TERM 67 | # This needs to explicitly include the “.exe” extension to disambiguate between 68 | # the classic “WHERE” executable and the “Where” PowerShell cmdlet. 69 | WHICH=where.exe 70 | endif 71 | endif 72 | 73 | JAVA_PATH := $(shell $(WHICH) java) 74 | ifeq ($(JAVA_PATH),) 75 | $(error $(MISSING_JAVA)) 76 | endif 77 | 78 | # Make's builtin filename operations, such as $(realpath ...) and $(dir ...), 79 | # operate on space-separated lists of filenames, and Java is often installed to 80 | # a path containing spaces on Windows (e.g., C:\Program Files\AdoptOpenJDK\ 81 | # jdk-8.x.y.z-hotspot), so we need to munge any spaces in the path to something 82 | # which won't appear in legal path names, do our manipulations, then swap the 83 | # spaces back into place. 84 | empty := 85 | space := $(empty) $(empty) 86 | JAVA_PATH := $(subst $(space),?,$(JAVA_PATH)) 87 | 88 | # Resolve any symlinks (e.g., /usr/bin/java → /etc/alternatives/java → 89 | # /usr/lib/jvm/java-11-openjdk-amd64/bin/java. 90 | JAVA_REALPATH := $(realpath $(JAVA_PATH)) 91 | ifneq ($(JAVA_REALPATH),) 92 | # Of course, if there _were_ any spaces in the path (which have now been 93 | # replaced with an invalid character), realpath will fall over. Let's hope we 94 | # never have to deal with a situation where the path contains symlinks _and_ 95 | # spaces. 96 | JAVA_PATH := $(JAVA_REALPATH) 97 | endif 98 | 99 | # JAVA_PATH should be JAVA_HOME/bin/java or maybe JAVA_HOME/jre/bin/java. To 100 | # get JAVA_HOME, we want to traverse two or three levels up from JAVA_PATH. 101 | # However, we can't just call $(dir $(dir $(JAVA_PATH)), because unlike 102 | # dirname(1), $(dir ...) returns the given path untouched if it is already a 103 | # directory, instead of always returning the parent (i.e., “$(dir foo/bar/)” 104 | # returns “foo/bar/”, not “foo/”). And $(abspath ...) breaks the leading “/c/” 105 | # in POSIX emulation shells on Windows. We'll just resort to to string 106 | # manipulation. 107 | JAVA_HOME := $(subst /jre/bin/java,,$(JAVA_PATH)) 108 | JAVA_HOME := $(subst /bin/java,,$(JAVA_HOME)) 109 | JAVA_HOME := $(subst \bin\java.exe,,$(JAVA_HOME)) 110 | # Now fix any spaces in the path. 111 | JAVA_HOME := "$(subst ?,$(space),$(JAVA_HOME))" 112 | $(warning $(GUESSED_JAVA_HOME)) 113 | 114 | endif # ifeq ($(OS),Darwin) 115 | endif # ifndef JAVA_HOME 116 | -------------------------------------------------------------------------------- /src/main/c/cross-compile-libs/ARM_32/liblockdev.so: -------------------------------------------------------------------------------- 1 | liblockdev.so.1 -------------------------------------------------------------------------------- /src/main/c/cross-compile-libs/ARM_32/liblockdev.so.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/cross-compile-libs/ARM_32/liblockdev.so.1 -------------------------------------------------------------------------------- /src/main/c/cross-compile-libs/ARM_64/liblockdev.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/cross-compile-libs/ARM_64/liblockdev.so -------------------------------------------------------------------------------- /src/main/c/cross-compile-libs/ARM_64/liblockdev.so.1: -------------------------------------------------------------------------------- 1 | liblockdev.so -------------------------------------------------------------------------------- /src/main/c/cross-compile-libs/README.TXT: -------------------------------------------------------------------------------- 1 | This directory contains shared objects (used as stubs) 2 | that cannot (easily) be provided by packages on the 3 | system that is used for cross compiling. 4 | 5 | The shared object "stubs" are used when a new shared object 6 | (our serial native library) is created during cross 7 | compilation. They "inform" the linker about the entry 8 | points available on the target system. Therefore they 9 | only have to be updated when the API version changes. -------------------------------------------------------------------------------- /src/main/c/cross-compile-libs/x86_32/liblockdev.so: -------------------------------------------------------------------------------- 1 | liblockdev.so.1 -------------------------------------------------------------------------------- /src/main/c/cross-compile-libs/x86_32/liblockdev.so.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/cross-compile-libs/x86_32/liblockdev.so.1 -------------------------------------------------------------------------------- /src/main/c/include/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.in by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_DLFCN_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_FCNTL_H 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_GRP_H 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_INTTYPES_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_MEMORY_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_PWD_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_SIGNAL_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_STDINT_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_STDLIB_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STRINGS_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STRING_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_SYS_FCNTL_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_FILE_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_SIGNAL_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_SYS_STAT_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_SYS_TIME_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_SYS_TYPES_H 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_TERMIOS_H 1 57 | 58 | /* Define to 1 if you have the header file. */ 59 | #define HAVE_UNISTD_H 1 60 | 61 | /* Name of package */ 62 | #define PACKAGE "Serial" 63 | 64 | /* Define to the address where bug reports for this package should be sent. */ 65 | #define PACKAGE_BUGREPORT "" 66 | 67 | /* Define to the full name of this package. */ 68 | #define PACKAGE_NAME "" 69 | 70 | /* Define to the full name and version of this package. */ 71 | #define PACKAGE_STRING "" 72 | 73 | /* Define to the one symbol short name of this package. */ 74 | #define PACKAGE_TARNAME "" 75 | 76 | /* Define to the version of this package. */ 77 | #define PACKAGE_VERSION "" 78 | 79 | /* Define to 1 if you have the ANSI C header files. */ 80 | #define STDC_HEADERS 1 81 | 82 | /* Version number of package */ 83 | #define VERSION "2.2pre2" 84 | 85 | -------------------------------------------------------------------------------- /src/main/c/include/target/gnu_io_CommPortIdentifier.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class gnu_io_CommPortIdentifier */ 4 | 5 | #ifndef _Included_gnu_io_CommPortIdentifier 6 | #define _Included_gnu_io_CommPortIdentifier 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #undef gnu_io_CommPortIdentifier_PORT_SERIAL 11 | #define gnu_io_CommPortIdentifier_PORT_SERIAL 1L 12 | #undef gnu_io_CommPortIdentifier_PORT_PARALLEL 13 | #define gnu_io_CommPortIdentifier_PORT_PARALLEL 2L 14 | #undef gnu_io_CommPortIdentifier_PORT_I2C 15 | #define gnu_io_CommPortIdentifier_PORT_I2C 3L 16 | #undef gnu_io_CommPortIdentifier_PORT_RS485 17 | #define gnu_io_CommPortIdentifier_PORT_RS485 4L 18 | #undef gnu_io_CommPortIdentifier_PORT_RAW 19 | #define gnu_io_CommPortIdentifier_PORT_RAW 5L 20 | #undef gnu_io_CommPortIdentifier_debug 21 | #define gnu_io_CommPortIdentifier_debug 0L 22 | /* 23 | * Class: gnu_io_CommPortIdentifier 24 | * Method: native_psmisc_report_owner 25 | * Signature: (Ljava/lang/String;)Ljava/lang/String; 26 | */ 27 | JNIEXPORT jstring JNICALL Java_gnu_io_CommPortIdentifier_native_1psmisc_1report_1owner 28 | (JNIEnv *, jobject, jstring); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | #endif 34 | -------------------------------------------------------------------------------- /src/main/c/include/target/gnu_io_RXTXCommDriver.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class gnu_io_RXTXCommDriver */ 4 | 5 | #ifndef _Included_gnu_io_RXTXCommDriver 6 | #define _Included_gnu_io_RXTXCommDriver 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #undef gnu_io_RXTXCommDriver_debug 11 | #define gnu_io_RXTXCommDriver_debug 0L 12 | #undef gnu_io_RXTXCommDriver_devel 13 | #define gnu_io_RXTXCommDriver_devel 0L 14 | /* 15 | * Class: gnu_io_RXTXCommDriver 16 | * Method: registerKnownPorts 17 | * Signature: (I)Z 18 | */ 19 | JNIEXPORT jboolean JNICALL Java_gnu_io_RXTXCommDriver_registerKnownPorts 20 | (JNIEnv *, jobject, jint); 21 | 22 | /* 23 | * Class: gnu_io_RXTXCommDriver 24 | * Method: isPortPrefixValid 25 | * Signature: (Ljava/lang/String;)Z 26 | */ 27 | JNIEXPORT jboolean JNICALL Java_gnu_io_RXTXCommDriver_isPortPrefixValid 28 | (JNIEnv *, jobject, jstring); 29 | 30 | /* 31 | * Class: gnu_io_RXTXCommDriver 32 | * Method: testRead 33 | * Signature: (Ljava/lang/String;I)Z 34 | */ 35 | JNIEXPORT jboolean JNICALL Java_gnu_io_RXTXCommDriver_testRead 36 | (JNIEnv *, jobject, jstring, jint); 37 | 38 | /* 39 | * Class: gnu_io_RXTXCommDriver 40 | * Method: getDeviceDirectory 41 | * Signature: ()Ljava/lang/String; 42 | */ 43 | JNIEXPORT jstring JNICALL Java_gnu_io_RXTXCommDriver_getDeviceDirectory 44 | (JNIEnv *, jobject); 45 | 46 | /* 47 | * Class: gnu_io_RXTXCommDriver 48 | * Method: nativeGetVersion 49 | * Signature: ()Ljava/lang/String; 50 | */ 51 | JNIEXPORT jstring JNICALL Java_gnu_io_RXTXCommDriver_nativeGetVersion 52 | (JNIEnv *, jclass); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | #endif 58 | -------------------------------------------------------------------------------- /src/main/c/include/target/gnu_io_RXTXPort_MonitorThread.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class gnu_io_RXTXPort_MonitorThread */ 4 | 5 | #ifndef _Included_gnu_io_RXTXPort_MonitorThread 6 | #define _Included_gnu_io_RXTXPort_MonitorThread 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #undef gnu_io_RXTXPort_MonitorThread_MIN_PRIORITY 11 | #define gnu_io_RXTXPort_MonitorThread_MIN_PRIORITY 1L 12 | #undef gnu_io_RXTXPort_MonitorThread_NORM_PRIORITY 13 | #define gnu_io_RXTXPort_MonitorThread_NORM_PRIORITY 5L 14 | #undef gnu_io_RXTXPort_MonitorThread_MAX_PRIORITY 15 | #define gnu_io_RXTXPort_MonitorThread_MAX_PRIORITY 10L 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | #endif 20 | -------------------------------------------------------------------------------- /src/main/c/include/target/gnu_io_RXTXPort_SerialInputStream.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class gnu_io_RXTXPort_SerialInputStream */ 4 | 5 | #ifndef _Included_gnu_io_RXTXPort_SerialInputStream 6 | #define _Included_gnu_io_RXTXPort_SerialInputStream 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #undef gnu_io_RXTXPort_SerialInputStream_SKIP_BUFFER_SIZE 11 | #define gnu_io_RXTXPort_SerialInputStream_SKIP_BUFFER_SIZE 2048L 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /src/main/c/include/target/gnu_io_RXTXPort_SerialOutputStream.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class gnu_io_RXTXPort_SerialOutputStream */ 4 | 5 | #ifndef _Included_gnu_io_RXTXPort_SerialOutputStream 6 | #define _Included_gnu_io_RXTXPort_SerialOutputStream 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | #endif 14 | -------------------------------------------------------------------------------- /src/main/c/include/target/gnu_io_RXTXVersion.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class gnu_io_RXTXVersion */ 4 | 5 | #ifndef _Included_gnu_io_RXTXVersion 6 | #define _Included_gnu_io_RXTXVersion 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: gnu_io_RXTXVersion 12 | * Method: nativeGetVersion 13 | * Signature: ()Ljava/lang/String; 14 | */ 15 | JNIEXPORT jstring JNICALL Java_gnu_io_RXTXVersion_nativeGetVersion 16 | (JNIEnv *, jclass); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /src/main/c/include/target/gnu_io_Zystem.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class gnu_io_Zystem */ 4 | 5 | #ifndef _Included_gnu_io_Zystem 6 | #define _Included_gnu_io_Zystem 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #undef gnu_io_Zystem_SILENT_MODE 11 | #define gnu_io_Zystem_SILENT_MODE 0L 12 | #undef gnu_io_Zystem_FILE_MODE 13 | #define gnu_io_Zystem_FILE_MODE 1L 14 | #undef gnu_io_Zystem_NET_MODE 15 | #define gnu_io_Zystem_NET_MODE 2L 16 | #undef gnu_io_Zystem_MEX_MODE 17 | #define gnu_io_Zystem_MEX_MODE 3L 18 | #undef gnu_io_Zystem_PRINT_MODE 19 | #define gnu_io_Zystem_PRINT_MODE 4L 20 | #undef gnu_io_Zystem_J2EE_MSG_MODE 21 | #define gnu_io_Zystem_J2EE_MSG_MODE 5L 22 | #undef gnu_io_Zystem_J2SE_LOG_MODE 23 | #define gnu_io_Zystem_J2SE_LOG_MODE 6L 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | #endif 28 | -------------------------------------------------------------------------------- /src/main/c/include/windows/win32/jni_md.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved. 3 | * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 4 | * 5 | * 6 | * 7 | * 8 | * 9 | * 10 | * 11 | * 12 | * 13 | * 14 | * 15 | * 16 | * 17 | * 18 | * 19 | * 20 | * 21 | * 22 | * 23 | * 24 | */ 25 | 26 | #ifndef _JAVASOFT_JNI_MD_H_ 27 | #define _JAVASOFT_JNI_MD_H_ 28 | 29 | #define JNIEXPORT __declspec(dllexport) 30 | #define JNIIMPORT __declspec(dllimport) 31 | #define JNICALL __stdcall 32 | 33 | typedef long jint; 34 | typedef __int64 jlong; 35 | typedef signed char jbyte; 36 | 37 | #endif /* !_JAVASOFT_JNI_MD_H_ */ 38 | -------------------------------------------------------------------------------- /src/main/c/natives.mk: -------------------------------------------------------------------------------- 1 | # Make is limited in its ability to compose dynamic rules, particularly when 2 | # both the prerequisites and the target sprawl across multiple directories. By 3 | # breaking the guts of the build out into this separate makefile, we can 4 | # compose the rules from static variables passed from the parent makefile. 5 | 6 | include platform.mk 7 | 8 | resources/native/$(platform)/libNRJavaSerial$(variant).$(lib_type): $(addprefix build/$(platform)/,$(join $(addsuffix $(variant),$(basename $(objects))),$(suffix $(objects)))) | resources/native/$(platform) 9 | $(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@ 10 | 11 | resources/native/$(platform): 12 | $(call mkdir,$@) 13 | 14 | build/$(platform)/%$(variant).o: src/%.c | build/$(platform) 15 | $(CC) $(CFLAGS) $^ -o $@ 16 | 17 | build/$(platform)/%$(variant).o: src/windows/%.c | build/$(platform) 18 | $(CC) $(CFLAGS) $^ -o $@ 19 | 20 | build/$(platform): 21 | $(call mkdir,$@) 22 | -------------------------------------------------------------------------------- /src/main/c/platform.mk: -------------------------------------------------------------------------------- 1 | # Platform-dependent definitions of common commands. 2 | # 3 | # “ComSpec” on Windows is similar to the TERM environment variable. It 4 | # indicates the path of cmd.exe. We don't care where cmd.exe is, but we 5 | # _do_ care if we're running under it: it means that we'll be calling Windows 6 | # shell builtins instead of POSIX homonyms, and need to adjust our expectations 7 | # accordingly. Sometimes, we need to use entirely different commands. 8 | # 9 | # Note that this check is intentionally implemented somewhat differently to 10 | # the similar-looking environment check in JAVA_HOME.mk. That check is 11 | # concerned with how the environment will represent paths, and needs to be 12 | # fairly fine-grained; in this case, we just need to know whether we're 13 | # going to end up with a built-in from cmd.exe or not. 14 | ifdef ComSpec 15 | gradlew-build = gradlew.bat build 16 | # MKDIR neither understands nor requires the “-p” flag, but is one of the few 17 | # Windows CLI utilities which relies on Windows path separators (“\”). 18 | mkdir = mkdir $(subst /,\,$(1)) 19 | # So is RMDIR. Note that even though RMDIR /S does remove files under a 20 | # directory, it still can't be called interchangeably on a file or directory 21 | # (unlike `rm -R`). 22 | rmdir_r = -rmdir /s /q $(subst /,\,$(1)) 23 | else 24 | gradlew-build = ./gradlew build 25 | mkdir = mkdir -p $(1) 26 | # Named rmdir_r – not rm_r – to indicate that it should only be used to operate 27 | # on directories due to limitations of the Windows variant of the command. 28 | rmdir_r = rm -Rf $(1) 29 | endif 30 | -------------------------------------------------------------------------------- /src/main/c/resources/native/freebsd/ARM_64/libNRJavaSerialv8.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/freebsd/ARM_64/libNRJavaSerialv8.so -------------------------------------------------------------------------------- /src/main/c/resources/native/freebsd/x86_32/libNRJavaSerial.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/freebsd/x86_32/libNRJavaSerial.so -------------------------------------------------------------------------------- /src/main/c/resources/native/freebsd/x86_64/libNRJavaSerial.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/freebsd/x86_64/libNRJavaSerial.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv5.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv5.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv6.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv6.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv6_HF.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv6_HF.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv7.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv7.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv7_HF.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv7_HF.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv8.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv8.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv8_HF.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/ARM_32/libNRJavaSerialv8_HF.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/ARM_64/libNRJavaSerialv8.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/ARM_64/libNRJavaSerialv8.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/PPC/libNRJavaSerial.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/PPC/libNRJavaSerial.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/x86_32/libNRJavaSerial.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/x86_32/libNRJavaSerial.so -------------------------------------------------------------------------------- /src/main/c/resources/native/linux/x86_64/libNRJavaSerial.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/linux/x86_64/libNRJavaSerial.so -------------------------------------------------------------------------------- /src/main/c/resources/native/osx/libNRJavaSerial.jnilib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/osx/libNRJavaSerial.jnilib -------------------------------------------------------------------------------- /src/main/c/resources/native/windows/x86_32/libNRJavaSerial.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/windows/x86_32/libNRJavaSerial.dll -------------------------------------------------------------------------------- /src/main/c/resources/native/windows/x86_64/libNRJavaSerial.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuronRobotics/nrjavaserial/b1da316827821f6095deb307178fd0f48cafeed6/src/main/c/resources/native/windows/x86_64/libNRJavaSerial.dll -------------------------------------------------------------------------------- /src/main/c/src/fixup.c: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | asm(".section .idata$3\n" ".long 0,0,0,0, 0,0,0,0"); 59 | -------------------------------------------------------------------------------- /src/main/c/src/windows/init.c: -------------------------------------------------------------------------------- 1 | 2 | /* init.c is used for compiling dll's with lcc. More info in Makefile.lcc */ 3 | 4 | #ifdef _WIN32 5 | #include 6 | #include 7 | 8 | /** 9 | * Lcc requuires that there should be LibraryMain function and seeks 10 | * by default for LibMain. This might be someway not usefull for jni 11 | * interface it satisfies lcc linker. 12 | */ 13 | BOOL WINAPI __declspec(dllexport) LibMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved) { 14 | return TRUE; 15 | } 16 | 17 | /** 18 | * This is the standart implementation of Java 2 OnLoad and OnUnload native 19 | * library calls. This template defines them empty functions 20 | * 21 | * Now in SerialImp.c 22 | */ 23 | /* 24 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_2; } 25 | JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {} 26 | */ 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/CommDriver.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | /** 61 | * @author Trent Jarvi 62 | * @version %I%, %G% 63 | * @since JDK1.0 64 | */ 65 | 66 | 67 | public interface CommDriver 68 | { 69 | public abstract CommPort getCommPort(String portName,int portType); 70 | public abstract void initialize(); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/CommPort.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | import java.io.InputStream; 61 | import java.io.OutputStream; 62 | import java.io.IOException; 63 | 64 | /** 65 | * @author Trent Jarvi 66 | * @version %I%, %G% 67 | * @since JDK1.0 68 | */ 69 | 70 | 71 | /** 72 | * CommPort 73 | */ 74 | public abstract class CommPort extends Object { 75 | protected String name; 76 | private final static boolean debug = false; 77 | 78 | public abstract void enableReceiveFraming( int f ) 79 | throws UnsupportedCommOperationException; 80 | public abstract void disableReceiveFraming(); 81 | public abstract boolean isReceiveFramingEnabled(); 82 | public abstract int getReceiveFramingByte(); 83 | public abstract void disableReceiveTimeout(); 84 | public abstract void enableReceiveTimeout( int time ) 85 | throws UnsupportedCommOperationException; 86 | public abstract boolean isReceiveTimeoutEnabled(); 87 | public abstract int getReceiveTimeout(); 88 | public abstract void enableReceiveThreshold( int thresh ) 89 | throws UnsupportedCommOperationException; 90 | public abstract void disableReceiveThreshold(); 91 | public abstract int getReceiveThreshold(); 92 | public abstract boolean isReceiveThresholdEnabled(); 93 | public abstract void setInputBufferSize( int size ); 94 | public abstract int getInputBufferSize(); 95 | public abstract void setOutputBufferSize( int size ); 96 | public abstract int getOutputBufferSize(); 97 | @SuppressWarnings("static-access") 98 | public void close() 99 | { 100 | if (debug) System.out.println("CommPort:close()"); 101 | 102 | try 103 | { 104 | CommPortIdentifier cp = 105 | CommPortIdentifier.getPortIdentifier(this); 106 | if ( cp != null ) 107 | cp.getPortIdentifier(this).internalClosePort(); 108 | } 109 | catch (NoSuchPortException e) 110 | { 111 | } 112 | }; 113 | 114 | public abstract InputStream getInputStream() throws IOException; 115 | public abstract OutputStream getOutputStream() throws IOException; 116 | 117 | public String getName() 118 | { 119 | if (debug) System.out.println("CommPort:getName()"); 120 | return( name ); 121 | } 122 | public String toString() 123 | { 124 | if (debug) System.out.println("CommPort:toString()"); 125 | return( name ); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/CommPortEnumerator.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | import java.util.Enumeration; 61 | 62 | /** 63 | * @author Trent Jarvi 64 | * @version %I%, %G% 65 | * @since JDK1.0 66 | */ 67 | 68 | 69 | @SuppressWarnings("unchecked") 70 | class CommPortEnumerator implements Enumeration 71 | { 72 | private CommPortIdentifier index; 73 | private final static boolean debug = false; 74 | static 75 | { 76 | if (debug) 77 | System.out.println("CommPortEnumerator:{}"); 78 | } 79 | 80 | CommPortEnumerator() 81 | { 82 | } 83 | /*------------------------------------------------------------------------------ 84 | nextElement() 85 | accept: 86 | perform: 87 | return: 88 | exceptions: 89 | comments: 90 | ------------------------------------------------------------------------------*/ 91 | public Object nextElement() 92 | { 93 | if(debug) System.out.println("CommPortEnumerator:nextElement()"); 94 | synchronized (CommPortIdentifier.Sync) 95 | { 96 | if(index != null) index = index.next; 97 | else index=CommPortIdentifier.CommPortIndex; 98 | return(index); 99 | } 100 | } 101 | /*------------------------------------------------------------------------------ 102 | hasMoreElements() 103 | accept: 104 | perform: 105 | return: 106 | exceptions: 107 | comments: 108 | ------------------------------------------------------------------------------*/ 109 | public boolean hasMoreElements() 110 | { 111 | if(debug) System.out.println("CommPortEnumerator:hasMoreElements() " + CommPortIdentifier.CommPortIndex == null ? false : true ); 112 | synchronized (CommPortIdentifier.Sync) 113 | { 114 | if(index != null) return index.next == null ? false : true; 115 | else return CommPortIdentifier.CommPortIndex == null ? 116 | false : true; 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/CommPortOwnershipListener.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | import java.util.*; 60 | 61 | /** 62 | * @author Trent Jarvi 63 | * @version %I%, %G% 64 | * @since JDK1.0 65 | */ 66 | 67 | public interface CommPortOwnershipListener extends EventListener 68 | { 69 | public static final int PORT_OWNED =1; 70 | public static final int PORT_UNOWNED =2; 71 | public static final int PORT_OWNERSHIP_REQUESTED =3; 72 | 73 | public abstract void ownershipChange( int type ); 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/NativeResourceException.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | public class NativeResourceException extends RuntimeException { 61 | /** 62 | * 63 | */ 64 | private static final long serialVersionUID = 1L; 65 | private String message; 66 | 67 | public NativeResourceException(String msg) { 68 | message = msg; 69 | } 70 | 71 | public String toString() { 72 | return message; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/NoSuchPortException.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | /** 61 | * The requested Port does not exist 62 | * @author Trent Jarvi 63 | * @version %I%, %G% 64 | * @since JDK1.0 65 | */ 66 | 67 | @SuppressWarnings("serial") 68 | public class NoSuchPortException extends Exception 69 | { 70 | public NoSuchPortException( String str ) 71 | { 72 | super( str ); 73 | } 74 | public NoSuchPortException() 75 | { 76 | super(); 77 | } 78 | public NoSuchPortException(String message, Throwable cause) { 79 | super(message, cause); 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/PortInUseException.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | /** 61 | * The port requested is currently in use 62 | * @author Trent Jarvi 63 | * @version %I%, %G% 64 | * @since JDK1.0 65 | */ 66 | 67 | 68 | public class PortInUseException extends Exception 69 | { 70 | /** 71 | * 72 | */ 73 | private static final long serialVersionUID = 7233413293849446117L; 74 | /** 75 | the owner of the port requested. 76 | */ 77 | public String currentOwner; 78 | /** 79 | * create a instance of the Exception and store the current owner 80 | * 81 | * @param str detailed information about the current owner 82 | */ 83 | PortInUseException( String str ) 84 | { 85 | super( str ); 86 | currentOwner=str; 87 | } 88 | public PortInUseException() 89 | { 90 | super(); 91 | } 92 | } 93 | 94 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/RXTXVersion.java: -------------------------------------------------------------------------------- 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 1997-2009 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | /** 61 | A class to keep the current version in 62 | */ 63 | 64 | public class RXTXVersion 65 | { 66 | /*------------------------------------------------------------------------------ 67 | RXTXVersion 68 | accept: - 69 | perform: Set Version. 70 | return: - 71 | exceptions: Throwable 72 | comments: 73 | See INSTALL for details. 74 | ------------------------------------------------------------------------------*/ 75 | private static String Version; 76 | 77 | static { 78 | //System.loadLibrary( "rxtxSerial" ); 79 | SerialManager.getInstance(); 80 | 81 | Version = "RXTX-2.2pre2"; 82 | } 83 | /** 84 | * static method to return the current version of RXTX 85 | * unique to RXTX. 86 | * @return a string representing the version "RXTX-1.4-9" 87 | */ 88 | public static String getVersion() 89 | { 90 | return(Version); 91 | } 92 | public static native String nativeGetVersion(); 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/SerialManager.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | public class SerialManager { 61 | 62 | private static SerialManager instance; 63 | private static boolean loaded = false; 64 | private SerialManager() throws NativeResourceException { 65 | if(!loaded) { 66 | loaded = true; 67 | new NativeResource().load("libNRJavaSerial"); 68 | } 69 | } 70 | 71 | public static SerialManager getInstance() throws NativeResourceException { 72 | if(instance == null) { 73 | instance = new SerialManager(); 74 | } 75 | return instance; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/SerialPortEvent.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | import java.util.*; 60 | 61 | /** 62 | * @author Trent Jarvi 63 | * @version %I%, %G% 64 | * @since JDK1.0 65 | */ 66 | 67 | public class SerialPortEvent extends EventObject 68 | { 69 | /** 70 | * 71 | */ 72 | private static final long serialVersionUID = 7933235826241348039L; 73 | public static final int DATA_AVAILABLE =1; 74 | public static final int OUTPUT_BUFFER_EMPTY =2; 75 | public static final int CTS =3; 76 | public static final int DSR =4; 77 | public static final int RI =5; 78 | public static final int CD =6; 79 | public static final int OE =7; 80 | public static final int PE =8; 81 | public static final int FE =9; 82 | public static final int BI =10; 83 | public static final int HARDWARE_ERROR =11; 84 | private boolean OldValue; 85 | private boolean NewValue; 86 | private int eventType; 87 | /*public int eventType =0; depricated */ 88 | 89 | public SerialPortEvent(SerialPort srcport, int eventtype, boolean oldvalue, boolean newvalue) 90 | { 91 | super( srcport ); 92 | OldValue=oldvalue; 93 | NewValue=newvalue; 94 | eventType=eventtype; 95 | } 96 | public int getEventType() 97 | { 98 | return(eventType); 99 | } 100 | public boolean getNewValue() 101 | { 102 | return( NewValue ); 103 | } 104 | public boolean getOldValue() 105 | { 106 | return( OldValue ); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/SerialPortEventListener.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | import java.util.*; 60 | 61 | /** 62 | * @author Trent Jarvi 63 | * @version %I%, %G% 64 | * @since JDK1.0 65 | */ 66 | 67 | 68 | public interface SerialPortEventListener extends EventListener 69 | { 70 | public abstract void serialEvent( SerialPortEvent ev ); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/UnSupportedLoggerException.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | /** 61 | * Exception thrown when a method does not support the requested functionality. 62 | * @author Trent Jarvi 63 | * @version %I%, %G% 64 | * @since JDK1.0 65 | */ 66 | 67 | public class UnSupportedLoggerException extends Exception 68 | { 69 | /** 70 | * 71 | */ 72 | private static final long serialVersionUID = 3270209386138681632L; 73 | /** 74 | * create an instances with no message about why the Exception was thrown. 75 | * @since JDK1.0 76 | */ 77 | public UnSupportedLoggerException() 78 | { 79 | super(); 80 | } 81 | /** 82 | * create an instance with a message about why the Exception was thrown. 83 | * @param str A detailed message explaining the reason for the Exception. 84 | * @since JDK1.0 85 | */ 86 | public UnSupportedLoggerException( String str ) 87 | { 88 | super( str ); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/UnsupportedCommOperationException.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package gnu.io; 59 | 60 | /** 61 | * Exception thrown when a method does not support the requested functionality. 62 | * @author Trent Jarvi 63 | * @version %I%, %G% 64 | * @since JDK1.0 65 | */ 66 | 67 | @SuppressWarnings("serial") 68 | public class UnsupportedCommOperationException extends Exception 69 | { 70 | /** 71 | * create an instances with no message about why the Exception was thrown. 72 | * @since JDK1.0 73 | */ 74 | public UnsupportedCommOperationException() 75 | { 76 | super(); 77 | } 78 | /** 79 | * create an instance with a message about why the Exception was thrown. 80 | * @param str A detailed message explaining the reason for the Exception. 81 | * @since JDK1.0 82 | */ 83 | public UnsupportedCommOperationException( String str ) 84 | { 85 | super( str ); 86 | } 87 | 88 | public UnsupportedCommOperationException(String message, Throwable cause) { 89 | super(message, cause); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/factory/DefaultSerialPortFactory.java: -------------------------------------------------------------------------------- 1 | package gnu.io.factory; 2 | 3 | import gnu.io.NoSuchPortException; 4 | import gnu.io.PortInUseException; 5 | import gnu.io.SerialPort; 6 | import gnu.io.UnsupportedCommOperationException; 7 | 8 | public class DefaultSerialPortFactory implements SerialPortFactory { 9 | 10 | private SerialPortRegistry portRegistry; 11 | 12 | /** 13 | * Constructor 14 | */ 15 | public DefaultSerialPortFactory() { 16 | this.portRegistry = new SerialPortRegistry(); 17 | } 18 | 19 | /* (non-Javadoc) 20 | * @see gnu.io.factory.SerialPortFactory#createSerialPort(java.lang.String) 21 | */ 22 | @Override 23 | public T createSerialPort(String portName, Class expectedClass) throws PortInUseException, NoSuchPortException, UnsupportedCommOperationException{ 24 | SerialPortCreator portCreator = this.portRegistry.getPortCreatorForPortName(portName, expectedClass); 25 | if(portCreator != null) { 26 | return portCreator.createPort(portName); 27 | } 28 | throw new NoSuchPortException(portName + " can not be opened."); 29 | } 30 | 31 | @Override 32 | public SerialPort createSerialPort(String portName) 33 | throws PortInUseException, NoSuchPortException, UnsupportedCommOperationException { 34 | SerialPortCreator portCreator = this.portRegistry.getPortCreatorForPortName(portName, SerialPort.class); 35 | if(portCreator != null) { 36 | return portCreator.createPort(portName); 37 | } 38 | throw new NoSuchPortException(portName + " can not be opened."); 39 | } 40 | 41 | /** 42 | * Gets the {@link SerialPortRegistry} to register/unregister {@link SerialPortCreator}s. 43 | * @return 44 | */ 45 | public SerialPortRegistry getPortRegistry() { 46 | return portRegistry; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/factory/RFC2217PortCreator.java: -------------------------------------------------------------------------------- 1 | package gnu.io.factory; 2 | 3 | import java.net.URI; 4 | import java.net.UnknownHostException; 5 | 6 | import gnu.io.NoSuchPortException; 7 | import gnu.io.PortInUseException; 8 | import gnu.io.UnsupportedCommOperationException; 9 | import gnu.io.rfc2217.TelnetSerialPort; 10 | 11 | public class RFC2217PortCreator implements SerialPortCreator { 12 | 13 | private final static String PROTOCOL = "rfc2217"; 14 | 15 | @Override 16 | public boolean isApplicable(String portName, Class expectedClass) { 17 | try { 18 | if(expectedClass.isAssignableFrom(TelnetSerialPort.class)) { 19 | URI uri = URI.create(portName); 20 | return uri.getScheme().equalsIgnoreCase(PROTOCOL); 21 | } 22 | return false; 23 | } catch(Throwable t) { 24 | return false; 25 | } 26 | } 27 | 28 | /** 29 | * @throws UnsupportedCommOperationException if connection to the remote serial port fails. 30 | * @throws NoSuchPortException if the host does not exist. 31 | */ 32 | @Override 33 | public TelnetSerialPort createPort(String portName) 34 | throws NoSuchPortException, UnsupportedCommOperationException, PortInUseException { 35 | URI url = URI.create(portName); 36 | try 37 | { 38 | TelnetSerialPort telnetSerialPort = new TelnetSerialPort(); 39 | telnetSerialPort.getTelnetClient().connect(url.getHost(), url.getPort()); 40 | return telnetSerialPort; 41 | } 42 | catch(UnknownHostException e) { 43 | throw new NoSuchPortException("Host "+url.getHost()+" not available", e); 44 | } 45 | catch (Exception e) 46 | { 47 | throw new UnsupportedCommOperationException("Unable to establish remote connection to serial port "+portName, e); 48 | } 49 | } 50 | 51 | @Override 52 | public String getProtocol() { 53 | return PROTOCOL; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/factory/RxTxPortCreator.java: -------------------------------------------------------------------------------- 1 | package gnu.io.factory; 2 | 3 | import gnu.io.CommPortIdentifier; 4 | import gnu.io.NoSuchPortException; 5 | import gnu.io.PortInUseException; 6 | import gnu.io.RXTXPort; 7 | import gnu.io.UnsupportedCommOperationException; 8 | 9 | public class RxTxPortCreator implements SerialPortCreator { 10 | 11 | @Override 12 | public boolean isApplicable(String portName, Class expectedClass) { 13 | return expectedClass.isAssignableFrom(RXTXPort.class); 14 | } 15 | 16 | @Override 17 | public RXTXPort createPort(String port) throws NoSuchPortException, UnsupportedCommOperationException, PortInUseException { 18 | RXTXPort comm = null; 19 | CommPortIdentifier ident = null; 20 | if ((System.getProperty("os.name").toLowerCase().indexOf("linux") != -1)) 21 | { 22 | // if ( port.toLowerCase().contains("rfcomm".toLowerCase())|| 23 | // port.toLowerCase().contains("ttyUSB".toLowerCase()) || 24 | // port.toLowerCase().contains("ttyS".toLowerCase())|| 25 | // port.toLowerCase().contains("ACM".toLowerCase()) || 26 | // port.toLowerCase().contains("Neuron_Robotics".toLowerCase())|| 27 | // port.toLowerCase().contains("DyIO".toLowerCase())|| 28 | // port.toLowerCase().contains("NR".toLowerCase())|| 29 | // port.toLowerCase().contains("FTDI".toLowerCase())|| 30 | // port.toLowerCase().contains("ftdi".toLowerCase()) 31 | // ){ 32 | System.setProperty("gnu.io.rxtx.SerialPorts", port); 33 | // } 34 | } 35 | ident = CommPortIdentifier.getPortIdentifier(port); 36 | 37 | comm = ident.open("NRSerialPort", 2000); 38 | 39 | if (!(comm instanceof RXTXPort)) 40 | { 41 | throw new UnsupportedCommOperationException("Non-serial connections are unsupported."); 42 | } 43 | comm.enableReceiveTimeout(100); 44 | return comm; 45 | 46 | } 47 | 48 | @Override 49 | public String getProtocol() { 50 | return LOCAL; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/factory/SerialPortCreator.java: -------------------------------------------------------------------------------- 1 | package gnu.io.factory; 2 | 3 | import gnu.io.NoSuchPortException; 4 | import gnu.io.PortInUseException; 5 | import gnu.io.SerialPort; 6 | import gnu.io.UnsupportedCommOperationException; 7 | 8 | public interface SerialPortCreator { 9 | 10 | final static String LOCAL = "local"; 11 | 12 | /** 13 | * Gets whether this {@link SerialPortCreator} is applicable to create and open the given port. 14 | * @param portName The ports name. 15 | * @return Whether the port can be created and opened by this creator. 16 | */ 17 | public boolean isApplicable(String portName, Class epectedClass); 18 | 19 | /** 20 | * Creates the {@link SerialPort} and opens it for communication. 21 | * @param portName The ports name. 22 | * @return The created {@link SerialPort}. 23 | * @throws NoSuchPortException If the serial port does not exist. 24 | * @throws UnsupportedCommOperationException 25 | * @throws PortInUseException 26 | */ 27 | public T createPort(String portName) throws NoSuchPortException, UnsupportedCommOperationException, PortInUseException; 28 | 29 | /** 30 | * Gets the protocol type of the Port to create. 31 | * @return The protocol type. 32 | */ 33 | public String getProtocol(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/factory/SerialPortFactory.java: -------------------------------------------------------------------------------- 1 | package gnu.io.factory; 2 | 3 | import gnu.io.NoSuchPortException; 4 | import gnu.io.PortInUseException; 5 | import gnu.io.SerialPort; 6 | import gnu.io.UnsupportedCommOperationException; 7 | 8 | public interface SerialPortFactory { 9 | 10 | /** 11 | * Creates a {@link SerialPort} instance out of the given portName. 12 | * @param portName The port's name to parse out whether to create a serial connection or a remote (rfc2217) connection. 13 | * @param expectedClass The {@link SerialPort} class that is expected to return. 14 | * @return The newly created and opened SerialPort. 15 | * @throws PortInUseException 16 | * @throws NoSuchPortException 17 | * @throws UnsupportedCommOperationException 18 | */ 19 | T createSerialPort(String portName, Class expectedClass) 20 | throws PortInUseException, NoSuchPortException, UnsupportedCommOperationException; 21 | 22 | /** 23 | * Creates a {@link SerialPort} instance out of the given portName. 24 | * @param portName The port's name to parse out whether to create a serial connection or a remote (rfc2217) connection. 25 | * @return The newly created and opened SerialPort. 26 | * @throws PortInUseException 27 | * @throws NoSuchPortException 28 | * @throws UnsupportedCommOperationException 29 | */ 30 | SerialPort createSerialPort(String portName) 31 | throws PortInUseException, NoSuchPortException, UnsupportedCommOperationException; 32 | } -------------------------------------------------------------------------------- /src/main/java/gnu/io/factory/SerialPortRegistry.java: -------------------------------------------------------------------------------- 1 | package gnu.io.factory; 2 | 3 | import java.util.Collection; 4 | import java.util.Comparator; 5 | import java.util.TreeSet; 6 | 7 | import gnu.io.SerialPort; 8 | 9 | public class SerialPortRegistry { 10 | 11 | private Collection> portCreators; 12 | 13 | public SerialPortRegistry() { 14 | // register the LOCAL PortCreator as last argument, so that is always taken into account when no other creator is applicable. 15 | this.portCreators = new TreeSet>(new Comparator>() { 16 | 17 | @Override 18 | public int compare(SerialPortCreator o1, SerialPortCreator o2) { 19 | if(o1.getProtocol().equals(SerialPortCreator.LOCAL)) { 20 | return 1; 21 | } 22 | if(o2.getProtocol().equals(SerialPortCreator.LOCAL)) { 23 | return -1; 24 | } 25 | return o1.getProtocol().compareTo(o2.getProtocol()); 26 | } 27 | }); 28 | 29 | registerDefaultSerialPortCreators(); 30 | } 31 | 32 | /** 33 | * Registers the {@link RxTxPortCreator} and the {@link RFC2217PortCreator}. 34 | */ 35 | protected void registerDefaultSerialPortCreators() { 36 | registerSerialPortCreator(new RxTxPortCreator()); 37 | registerSerialPortCreator(new RFC2217PortCreator()); 38 | } 39 | 40 | /** 41 | * Registers a {@link SerialPortCreator}. 42 | * @param creator 43 | */ 44 | public void registerSerialPortCreator(SerialPortCreator creator) { 45 | this.portCreators.add(creator); 46 | } 47 | 48 | /** 49 | * Gets the best applicable {@link SerialPortCreator} for the given portName 50 | * @param portName The port's name. 51 | * @return A found {@link SerialPortCreator} or null if none could be found. 52 | */ 53 | @SuppressWarnings("unchecked") 54 | public SerialPortCreator getPortCreatorForPortName(String portName, Class expectedClass) { 55 | for(@SuppressWarnings("rawtypes") SerialPortCreator creator : this.portCreators) { 56 | try { 57 | if(creator.isApplicable(portName, expectedClass)) 58 | return (SerialPortCreator) creator; 59 | } catch(Exception e) { 60 | System.err.println("Error for SerialPortCreator#isApplicable: " + creator.getClass()+"; " + creator.getProtocol() +" -> " + e.getMessage()); 61 | } 62 | } 63 | return null; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/BaudRateCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 60 | import static gnu.io.rfc2217.RFC2217.SET_BAUDRATE; 61 | 62 | /** 63 | * RFC 2217 {@code SET-BAUDRATE} command. 64 | * 65 | * @see RFC 2217 66 | */ 67 | public class BaudRateCommand extends ComPortCommand { 68 | 69 | private int baudRate; 70 | 71 | /** 72 | * Decoding constructor. 73 | * 74 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 75 | * NullPointerException if {@code bytes} is null 76 | * IllegalArgumentException if {@code bytes} has length that is too short or too long 77 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 78 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#SET_BAUDRATE} (client or server) 79 | */ 80 | public BaudRateCommand(int[] bytes) { 81 | super("SET-BAUDRATE", SET_BAUDRATE, bytes); 82 | this.baudRate = ((bytes[2] & 0xff) << 24) | ((bytes[3] & 0xff) << 16) | ((bytes[4] & 0xff) << 8) | (bytes[5] & 0xff); 83 | } 84 | 85 | /** 86 | * Encoding constructor. 87 | * 88 | * @param baudRate baud rate 89 | * @param client true for the client-to-server command, false for the server-to-client command 90 | */ 91 | public BaudRateCommand(boolean client, int baudRate) { 92 | this(new int[] { 93 | COM_PORT_OPTION, 94 | client ? SET_BAUDRATE : SET_BAUDRATE + SERVER_OFFSET, 95 | (baudRate >> 24) & 0xff, 96 | (baudRate >> 16) & 0xff, 97 | (baudRate >> 8) & 0xff, 98 | baudRate & 0xff, 99 | }); 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return this.getName() + " " + this.baudRate; 105 | } 106 | 107 | @Override 108 | public void visit(ComPortCommandSwitch sw) { 109 | sw.caseBaudRate(this); 110 | } 111 | 112 | public int getBaudRate() { 113 | return this.baudRate; 114 | } 115 | 116 | @Override 117 | int getMinPayloadLength() { 118 | return 4; 119 | } 120 | 121 | @Override 122 | int getMaxPayloadLength() { 123 | return 4; 124 | } 125 | } 126 | 127 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/ComPortCommandSwitch.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | /** 59 | * Visitor pattern interface for {@link ComPortCommand} classes. 60 | * 61 | * @see ComPortCommand#visit 62 | */ 63 | public interface ComPortCommandSwitch { 64 | 65 | void caseSignature(SignatureCommand command); 66 | 67 | void caseBaudRate(BaudRateCommand command); 68 | 69 | void caseDataSize(DataSizeCommand command); 70 | 71 | void caseParity(ParityCommand command); 72 | 73 | void caseStopSize(StopSizeCommand command); 74 | 75 | void caseControl(ControlCommand command); 76 | 77 | void caseNotifyLineState(NotifyLineStateCommand command); 78 | 79 | void caseNotifyModemState(NotifyModemStateCommand command); 80 | 81 | void caseFlowControlSuspend(FlowControlSuspendCommand command); 82 | 83 | void caseFlowControlResume(FlowControlResumeCommand command); 84 | 85 | void caseLineStateMask(LineStateMaskCommand command); 86 | 87 | void caseModemStateMask(ModemStateMaskCommand command); 88 | 89 | void casePurgeData(PurgeDataCommand command); 90 | } 91 | 92 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/ComPortOptionHandler.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import org.apache.commons.net.telnet.TelnetOptionHandler; 59 | 60 | /** 61 | * RFC 2217 telnet COM-PORT-OPTION. 62 | * 63 | * @see RFC 2217 64 | */ 65 | public class ComPortOptionHandler extends TelnetOptionHandler { 66 | 67 | private final TelnetSerialPort port; 68 | 69 | protected ComPortOptionHandler(TelnetSerialPort telnetSerialPort) { 70 | super(RFC2217.COM_PORT_OPTION, true, false, true, false); 71 | if (telnetSerialPort == null) 72 | throw new IllegalArgumentException("null telnetSerialPort"); 73 | this.port = telnetSerialPort; 74 | } 75 | 76 | @Override 77 | public int[] answerSubnegotiation(int[] data, int length) { 78 | 79 | // Copy data into buffer of the correct size 80 | if (data.length != length) { 81 | int[] data2 = new int[length]; 82 | System.arraycopy(data, 0, data2, 0, length); 83 | data = data2; 84 | } 85 | 86 | // Decode option 87 | ComPortCommand command; 88 | try { 89 | command = RFC2217.decodeComPortCommand(data); 90 | } catch (IllegalArgumentException e) { 91 | System.err.println(this.port.getName() + ": rec'd invalid COM-PORT-OPTION command: " + e.getMessage()); 92 | return null; 93 | } 94 | 95 | // Notify port 96 | this.port.handleCommand(command); 97 | return null; 98 | } 99 | 100 | @Override 101 | public int[] startSubnegotiationLocal() { 102 | this.port.startSubnegotiation(); 103 | return null; 104 | } 105 | 106 | @Override 107 | public int[] startSubnegotiationRemote() { 108 | return null; 109 | } 110 | } 111 | 112 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/DataSizeCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.DATASIZE_5; 60 | import static gnu.io.rfc2217.RFC2217.DATASIZE_6; 61 | import static gnu.io.rfc2217.RFC2217.DATASIZE_7; 62 | import static gnu.io.rfc2217.RFC2217.DATASIZE_8; 63 | import static gnu.io.rfc2217.RFC2217.DATASIZE_REQUEST; 64 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 65 | import static gnu.io.rfc2217.RFC2217.SET_DATASIZE; 66 | 67 | /** 68 | * RFC 2217 {@code SET-DATASIZE} command. 69 | * 70 | * @see RFC 2217 71 | */ 72 | public class DataSizeCommand extends ComPortCommand { 73 | 74 | private int dataSize; 75 | 76 | /** 77 | * Decoding constructor. 78 | * 79 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 80 | * NullPointerException if {@code bytes} is null 81 | * IllegalArgumentException if {@code bytes} has length != 3 82 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 83 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#SET_DATASIZE} (client or server) 84 | * IllegalArgumentException if {@code bytes[2]} is not a valid RFC 2217 data size value 85 | */ 86 | public DataSizeCommand(int[] bytes) { 87 | super("SET-DATASIZE", SET_DATASIZE, bytes); 88 | this.dataSize = bytes[2]; 89 | switch (this.dataSize) { 90 | case DATASIZE_REQUEST: 91 | case DATASIZE_5: 92 | case DATASIZE_6: 93 | case DATASIZE_7: 94 | case DATASIZE_8: 95 | break; 96 | default: 97 | throw new IllegalArgumentException("invalid data size value " + this.dataSize); 98 | } 99 | } 100 | 101 | /** 102 | * Encoding constructor. 103 | * 104 | * @param dataSize data size value 105 | * @param client true for the client-to-server command, false for the server-to-client command 106 | * IllegalArgumentException if {@code dataSize} is not a valid RFC 2217 data size value 107 | */ 108 | public DataSizeCommand(boolean client, int dataSize) { 109 | this(new int[] { 110 | COM_PORT_OPTION, 111 | client ? SET_DATASIZE : SET_DATASIZE + SERVER_OFFSET, 112 | dataSize 113 | }); 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | String desc; 119 | switch (this.dataSize) { 120 | case DATASIZE_REQUEST: 121 | desc = "REQUEST"; 122 | break; 123 | case DATASIZE_5: 124 | desc = "5"; 125 | break; 126 | case DATASIZE_6: 127 | desc = "6"; 128 | break; 129 | case DATASIZE_7: 130 | desc = "7"; 131 | break; 132 | case DATASIZE_8: 133 | desc = "8"; 134 | break; 135 | default: 136 | desc = "?"; 137 | break; 138 | } 139 | return this.getName() + " " + desc; 140 | } 141 | 142 | @Override 143 | public void visit(ComPortCommandSwitch sw) { 144 | sw.caseDataSize(this); 145 | } 146 | 147 | public int getDataSize() { 148 | return this.dataSize; 149 | } 150 | 151 | @Override 152 | int getMinPayloadLength() { 153 | return 1; 154 | } 155 | 156 | @Override 157 | int getMaxPayloadLength() { 158 | return 1; 159 | } 160 | } 161 | 162 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/FlowControlResumeCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.FLOWCONTROL_RESUME; 60 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 61 | 62 | /** 63 | * RFC 2217 {@code FLOWCONTROL-RESUME} command. 64 | * 65 | * @see RFC 2217 66 | */ 67 | public class FlowControlResumeCommand extends ComPortCommand { 68 | 69 | /** 70 | * Decoding constructor. 71 | * 72 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 73 | * NullPointerException if {@code bytes} is null 74 | * IllegalArgumentException if {@code bytes} has length != 3 75 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 76 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#FLOWCONTROL_RESUME} (client or server) 77 | */ 78 | public FlowControlResumeCommand(int[] bytes) { 79 | super("FLOWCONTROL-RESUME", FLOWCONTROL_RESUME, bytes); 80 | } 81 | 82 | /** 83 | * Encoding constructor. 84 | * 85 | * @param client true for the client-to-server command, false for the server-to-client command 86 | */ 87 | public FlowControlResumeCommand(boolean client) { 88 | this(new int[] { 89 | COM_PORT_OPTION, 90 | client ? FLOWCONTROL_RESUME : FLOWCONTROL_RESUME + SERVER_OFFSET, 91 | }); 92 | } 93 | 94 | @Override 95 | public String toString() { 96 | return this.getName(); 97 | } 98 | 99 | @Override 100 | public void visit(ComPortCommandSwitch sw) { 101 | sw.caseFlowControlResume(this); 102 | } 103 | 104 | @Override 105 | int getMinPayloadLength() { 106 | return 0; 107 | } 108 | 109 | @Override 110 | int getMaxPayloadLength() { 111 | return 0; 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/FlowControlSuspendCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.FLOWCONTROL_SUSPEND; 60 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 61 | 62 | /** 63 | * RFC 2217 {@code FLOWCONTROL-SUSPEND} command. 64 | * 65 | * @see RFC 2217 66 | */ 67 | public class FlowControlSuspendCommand extends ComPortCommand { 68 | 69 | /** 70 | * Decoding constructor. 71 | * 72 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 73 | * NullPointerException if {@code bytes} is null 74 | * IllegalArgumentException if {@code bytes} has length != 3 75 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 76 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#FLOWCONTROL_SUSPEND} (client or server) 77 | */ 78 | public FlowControlSuspendCommand(int[] bytes) { 79 | super("FLOWCONTROL-SUSPEND", FLOWCONTROL_SUSPEND, bytes); 80 | } 81 | 82 | /** 83 | * Encoding constructor. 84 | * 85 | * @param client true for the client-to-server command, false for the server-to-client command 86 | */ 87 | public FlowControlSuspendCommand(boolean client) { 88 | this(new int[] { 89 | COM_PORT_OPTION, 90 | client ? FLOWCONTROL_SUSPEND : FLOWCONTROL_SUSPEND + SERVER_OFFSET, 91 | }); 92 | } 93 | 94 | @Override 95 | public String toString() { 96 | return this.getName(); 97 | } 98 | 99 | @Override 100 | public void visit(ComPortCommandSwitch sw) { 101 | sw.caseFlowControlSuspend(this); 102 | } 103 | 104 | @Override 105 | int getMinPayloadLength() { 106 | return 0; 107 | } 108 | 109 | @Override 110 | int getMaxPayloadLength() { 111 | return 0; 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/LineStateMaskCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 60 | import static gnu.io.rfc2217.RFC2217.SET_LINESTATE_MASK; 61 | 62 | /** 63 | * RFC 2217 {@code SET-LINESTATE-MASK} command. 64 | * 65 | * @see RFC 2217 66 | */ 67 | public class LineStateMaskCommand extends ComPortCommand { 68 | 69 | private int lineStateMask; 70 | 71 | /** 72 | * Decoding constructor. 73 | * 74 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 75 | * NullPointerException if {@code bytes} is null 76 | * IllegalArgumentException if {@code bytes} has length != 3 77 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 78 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#SET_LINESTATE_MASK} (client or server) 79 | */ 80 | public LineStateMaskCommand(int[] bytes) { 81 | super("SET-LINESTATE-MASK", SET_LINESTATE_MASK, bytes); 82 | this.lineStateMask = bytes[2]; 83 | } 84 | 85 | /** 86 | * Encoding constructor. 87 | * 88 | * @param lineStateMask line state mask value 89 | * @param client true for the client-to-server command, false for the server-to-client command 90 | */ 91 | public LineStateMaskCommand(boolean client, int lineStateMask) { 92 | this(new int[] { 93 | COM_PORT_OPTION, 94 | client ? SET_LINESTATE_MASK : SET_LINESTATE_MASK + SERVER_OFFSET, 95 | lineStateMask 96 | }); 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return this.getName() + " " + Util.decodeBits(this.lineStateMask, Util.LINE_STATE_BITS); 102 | } 103 | 104 | @Override 105 | public void visit(ComPortCommandSwitch sw) { 106 | sw.caseLineStateMask(this); 107 | } 108 | 109 | public int getLineStateMask() { 110 | return this.lineStateMask; 111 | } 112 | 113 | @Override 114 | int getMinPayloadLength() { 115 | return 1; 116 | } 117 | 118 | @Override 119 | int getMaxPayloadLength() { 120 | return 1; 121 | } 122 | } 123 | 124 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/ModemStateMaskCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 60 | import static gnu.io.rfc2217.RFC2217.SET_MODEMSTATE_MASK; 61 | 62 | /** 63 | * RFC 2217 {@code SET-MODEMSTATE-MASK} command. 64 | * 65 | * @see RFC 2217 66 | */ 67 | public class ModemStateMaskCommand extends ComPortCommand { 68 | 69 | private int modemStateMask; 70 | 71 | /** 72 | * Decoding constructor. 73 | * 74 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 75 | * NullPointerException if {@code bytes} is null 76 | * IllegalArgumentException if {@code bytes} has length != 3 77 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 78 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#SET_MODEMSTATE_MASK} (client or server) 79 | */ 80 | public ModemStateMaskCommand(int[] bytes) { 81 | super("SET-MODEMSTATE-MASK", SET_MODEMSTATE_MASK, bytes); 82 | this.modemStateMask = bytes[2]; 83 | } 84 | 85 | /** 86 | * Encoding constructor. 87 | * 88 | * @param modemStateMask modem state mask value 89 | * @param client true for the client-to-server command, false for the server-to-client command 90 | */ 91 | public ModemStateMaskCommand(boolean client, int modemStateMask) { 92 | this(new int[] { 93 | COM_PORT_OPTION, 94 | client ? SET_MODEMSTATE_MASK : SET_MODEMSTATE_MASK + SERVER_OFFSET, 95 | modemStateMask 96 | }); 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return this.getName() + " " + Util.decodeBits(this.modemStateMask, Util.MODEM_STATE_BITS); 102 | } 103 | 104 | @Override 105 | public void visit(ComPortCommandSwitch sw) { 106 | sw.caseModemStateMask(this); 107 | } 108 | 109 | public int getModemStateMask() { 110 | return this.modemStateMask; 111 | } 112 | 113 | @Override 114 | int getMinPayloadLength() { 115 | return 1; 116 | } 117 | 118 | @Override 119 | int getMaxPayloadLength() { 120 | return 1; 121 | } 122 | } 123 | 124 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/NotifyLineStateCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.NOTIFY_LINESTATE; 60 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 61 | 62 | /** 63 | * RFC 2217 {@code NOTIFY-LINESTATE} command. 64 | * 65 | * @see RFC 2217 66 | */ 67 | public class NotifyLineStateCommand extends ComPortCommand { 68 | 69 | private int lineState; 70 | 71 | /** 72 | * Decoding constructor. 73 | * 74 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 75 | * NullPointerException if {@code bytes} is null 76 | * IllegalArgumentException if {@code bytes} has length != 3 77 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 78 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#NOTIFY_LINESTATE} (client or server) 79 | */ 80 | public NotifyLineStateCommand(int[] bytes) { 81 | super("NOTIFY-LINESTATE", NOTIFY_LINESTATE, bytes); 82 | this.lineState = bytes[2]; 83 | } 84 | 85 | /** 86 | * Encoding constructor. 87 | * 88 | * @param lineState line state value 89 | * @param client true for the client-to-server command, false for the server-to-client command 90 | */ 91 | public NotifyLineStateCommand(boolean client, int lineState) { 92 | this(new int[] { 93 | COM_PORT_OPTION, 94 | client ? NOTIFY_LINESTATE : NOTIFY_LINESTATE + SERVER_OFFSET, 95 | lineState 96 | }); 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return this.getName() + " " + Util.decodeBits(this.lineState, Util.LINE_STATE_BITS); 102 | } 103 | 104 | @Override 105 | public void visit(ComPortCommandSwitch sw) { 106 | sw.caseNotifyLineState(this); 107 | } 108 | 109 | public int getLineState() { 110 | return this.lineState; 111 | } 112 | 113 | @Override 114 | int getMinPayloadLength() { 115 | return 1; 116 | } 117 | 118 | @Override 119 | int getMaxPayloadLength() { 120 | return 1; 121 | } 122 | } 123 | 124 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/NotifyModemStateCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.NOTIFY_MODEMSTATE; 60 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 61 | 62 | /** 63 | * RFC 2217 {@code NOTIFY-MODEMSTATE} command. 64 | * 65 | * @see RFC 2217 66 | */ 67 | public class NotifyModemStateCommand extends ComPortCommand { 68 | 69 | private int modemState; 70 | 71 | /** 72 | * Decoding constructor. 73 | * 74 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 75 | * NullPointerException if {@code bytes} is null 76 | * IllegalArgumentException if {@code bytes} has length != 3 77 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 78 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#NOTIFY_MODEMSTATE} (client or server) 79 | */ 80 | public NotifyModemStateCommand(int[] bytes) { 81 | super("NOTIFY-MODEMSTATE", NOTIFY_MODEMSTATE, bytes); 82 | this.modemState = bytes[2]; 83 | } 84 | 85 | /** 86 | * Encoding constructor. 87 | * 88 | * @param modemState modem state value 89 | * @param client true for the client-to-server command, false for the server-to-client command 90 | */ 91 | public NotifyModemStateCommand(boolean client, int modemState) { 92 | this(new int[] { 93 | COM_PORT_OPTION, 94 | client ? NOTIFY_MODEMSTATE : NOTIFY_MODEMSTATE + SERVER_OFFSET, 95 | modemState 96 | }); 97 | } 98 | 99 | @Override 100 | public String toString() { 101 | return this.getName() + " " + Util.decodeBits(this.modemState, Util.MODEM_STATE_BITS); 102 | } 103 | 104 | @Override 105 | public void visit(ComPortCommandSwitch sw) { 106 | sw.caseNotifyModemState(this); 107 | } 108 | 109 | public int getModemState() { 110 | return this.modemState; 111 | } 112 | 113 | @Override 114 | int getMinPayloadLength() { 115 | return 1; 116 | } 117 | 118 | @Override 119 | int getMaxPayloadLength() { 120 | return 1; 121 | } 122 | } 123 | 124 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/PurgeDataCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.PURGE_DATA; 60 | import static gnu.io.rfc2217.RFC2217.PURGE_DATA_BOTH_DATA_BUFFERS; 61 | import static gnu.io.rfc2217.RFC2217.PURGE_DATA_RECEIVE_DATA_BUFFER; 62 | import static gnu.io.rfc2217.RFC2217.PURGE_DATA_TRANSMIT_DATA_BUFFER; 63 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 64 | 65 | /** 66 | * RFC 2217 {@code PURGE-DATA} command. 67 | * 68 | * @see RFC 2217 69 | */ 70 | public class PurgeDataCommand extends ComPortCommand { 71 | 72 | private int purgeData; 73 | 74 | /** 75 | * Decoding constructor. 76 | * 77 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 78 | * NullPointerException if {@code bytes} is null 79 | * IllegalArgumentException if {@code bytes} has length != 3 80 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 81 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#PURGE_DATA} (client or server) 82 | * IllegalArgumentException if {@code bytes[2]} is not a valid RFC 2217 purge data value 83 | */ 84 | public PurgeDataCommand(int[] bytes) { 85 | super("PURGE-DATA", PURGE_DATA, bytes); 86 | this.purgeData = bytes[2]; 87 | switch (this.purgeData) { 88 | case PURGE_DATA_RECEIVE_DATA_BUFFER: 89 | case PURGE_DATA_TRANSMIT_DATA_BUFFER: 90 | case PURGE_DATA_BOTH_DATA_BUFFERS: 91 | break; 92 | default: 93 | throw new IllegalArgumentException("invalid purge data value " + this.purgeData); 94 | } 95 | } 96 | 97 | /** 98 | * Encoding constructor. 99 | * 100 | * @param purgeData purge data value 101 | * @param client true for the client-to-server command, false for the server-to-client command 102 | * IllegalArgumentException if {@code purgeData} is not a valid RFC 2217 purge data value 103 | */ 104 | public PurgeDataCommand(boolean client, int purgeData) { 105 | this(new int[] { 106 | COM_PORT_OPTION, 107 | client ? PURGE_DATA : PURGE_DATA + SERVER_OFFSET, 108 | purgeData 109 | }); 110 | } 111 | 112 | @Override 113 | public String toString() { 114 | String desc; 115 | switch (this.purgeData) { 116 | case PURGE_DATA_RECEIVE_DATA_BUFFER: 117 | desc = "RECEIVE-DATA-BUFFER"; 118 | break; 119 | case PURGE_DATA_TRANSMIT_DATA_BUFFER: 120 | desc = "TRANSMIT-DATA-BUFFER"; 121 | break; 122 | case PURGE_DATA_BOTH_DATA_BUFFERS: 123 | desc = "BOTH-DATA-BUFFERS"; 124 | break; 125 | default: 126 | desc = "?"; 127 | break; 128 | } 129 | return this.getName() + " " + desc; 130 | } 131 | 132 | @Override 133 | public void visit(ComPortCommandSwitch sw) { 134 | sw.casePurgeData(this); 135 | } 136 | 137 | public boolean isPurgeReceiveDataBuffer() { 138 | return (this.purgeData & PURGE_DATA_RECEIVE_DATA_BUFFER) != 0; 139 | } 140 | 141 | public boolean isPurgeTransmitDataBuffer() { 142 | return (this.purgeData & PURGE_DATA_TRANSMIT_DATA_BUFFER) != 0; 143 | } 144 | 145 | @Override 146 | int getMinPayloadLength() { 147 | return 1; 148 | } 149 | 150 | @Override 151 | int getMaxPayloadLength() { 152 | return 1; 153 | } 154 | } 155 | 156 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/SignatureCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import java.io.UnsupportedEncodingException; 59 | 60 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 61 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 62 | import static gnu.io.rfc2217.RFC2217.SIGNATURE; 63 | 64 | /** 65 | * RFC 2217 {@code SIGNATURE} command. 66 | * 67 | * @see RFC 2217 68 | */ 69 | public class SignatureCommand extends ComPortCommand { 70 | 71 | public static final String ENCODING = "ISO-8859-1"; 72 | 73 | private final String signature; 74 | private boolean decodeFailed; 75 | 76 | /** 77 | * Decoding constructor. 78 | * 79 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 80 | * NullPointerException if {@code bytes} is null 81 | * IllegalArgumentException if {@code bytes} has length that is too short or too long 82 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 83 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#SIGNATURE} (client or server) 84 | */ 85 | public SignatureCommand(int[] bytes) { 86 | super("SIGNATURE", SIGNATURE, bytes); 87 | String sig; 88 | boolean failed = false; 89 | try { 90 | sig = new String(this.getPayload(), ENCODING); 91 | } catch (UnsupportedEncodingException e) { 92 | sig = "(string decode failed)"; 93 | failed = true; 94 | } 95 | this.signature = sig; 96 | this.decodeFailed = failed; 97 | } 98 | 99 | /** 100 | * Encoding constructor. 101 | * 102 | * @param signature signature string 103 | * @param client true for the client-to-server command, false for the server-to-client command 104 | */ 105 | public SignatureCommand(boolean client, String signature) { 106 | this(encode(client, signature)); 107 | } 108 | 109 | /** 110 | * Encoding constructor for signature requests. 111 | * 112 | * @param client true for the client command, false for the server command 113 | */ 114 | public SignatureCommand(boolean client) { 115 | this(encode(client, "")); 116 | } 117 | 118 | @Override 119 | public String toString() { 120 | return this.getName() + " " + (this.signature.length() > 0 ? "\"" + this.signature + "\"" : "REQUEST"); 121 | } 122 | 123 | @Override 124 | public void visit(ComPortCommandSwitch sw) { 125 | sw.caseSignature(this); 126 | } 127 | 128 | public String getSignature() { 129 | return this.signature; 130 | } 131 | 132 | public boolean decodeFailed() { 133 | return this.decodeFailed; 134 | } 135 | 136 | @Override 137 | int getMinPayloadLength() { 138 | return 0; 139 | } 140 | 141 | @Override 142 | int getMaxPayloadLength() { 143 | return Integer.MAX_VALUE - 2; 144 | } 145 | 146 | private static int[] encode(boolean client, String signature) { 147 | byte[] buf; 148 | try { 149 | buf = signature.getBytes(ENCODING); 150 | } catch (UnsupportedEncodingException e) { 151 | buf = new byte[] { (byte)'?' }; 152 | } 153 | int[] ibuf = new int[2 + buf.length]; 154 | ibuf[0] = COM_PORT_OPTION; 155 | ibuf[1] = client ? SIGNATURE : SIGNATURE + SERVER_OFFSET; 156 | for (int i = 0; i < buf.length; i++) 157 | ibuf[2 + i] = buf[i] & 0xff; 158 | return ibuf; 159 | } 160 | } 161 | 162 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/StopSizeCommand.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import static gnu.io.rfc2217.RFC2217.COM_PORT_OPTION; 59 | import static gnu.io.rfc2217.RFC2217.SERVER_OFFSET; 60 | import static gnu.io.rfc2217.RFC2217.SET_STOPSIZE; 61 | import static gnu.io.rfc2217.RFC2217.STOPSIZE_1; 62 | import static gnu.io.rfc2217.RFC2217.STOPSIZE_1_5; 63 | import static gnu.io.rfc2217.RFC2217.STOPSIZE_2; 64 | import static gnu.io.rfc2217.RFC2217.STOPSIZE_REQUEST; 65 | 66 | /** 67 | * RFC 2217 {@code SET-STOPSIZE} command. 68 | * 69 | * @see RFC 2217 70 | */ 71 | public class StopSizeCommand extends ComPortCommand { 72 | 73 | private int stopSize; 74 | 75 | /** 76 | * Decoding constructor. 77 | * 78 | * @param bytes encoded option starting with the {@code COM-PORT-OPTION} byte 79 | * NullPointerException if {@code bytes} is null 80 | * IllegalArgumentException if {@code bytes} has length != 3 81 | * IllegalArgumentException if {@code bytes[0]} is not {@link RFC2217#COM_PORT_OPTION} 82 | * IllegalArgumentException if {@code bytes[1]} is not {@link RFC2217#SET_STOPSIZE} (client or server) 83 | * IllegalArgumentException if {@code bytes[2]} is not a valid RFC 2217 stop size value 84 | */ 85 | public StopSizeCommand(int[] bytes) { 86 | super("SET-STOPSIZE", SET_STOPSIZE, bytes); 87 | this.stopSize = bytes[2]; 88 | switch (this.stopSize) { 89 | case STOPSIZE_REQUEST: 90 | case STOPSIZE_1: 91 | case STOPSIZE_2: 92 | case STOPSIZE_1_5: 93 | break; 94 | default: 95 | throw new IllegalArgumentException("invalid stop size value " + this.stopSize); 96 | } 97 | } 98 | 99 | /** 100 | * Encoding constructor. 101 | * 102 | * @param stopSize stop size value 103 | * @param client true for the client-to-server command, false for the server-to-client command 104 | * IllegalArgumentException if {@code stopSize} is not a valid RFC 2217 stop size value 105 | */ 106 | public StopSizeCommand(boolean client, int stopSize) { 107 | this(new int[] { 108 | COM_PORT_OPTION, 109 | client ? SET_STOPSIZE : SET_STOPSIZE + SERVER_OFFSET, 110 | stopSize 111 | }); 112 | } 113 | 114 | @Override 115 | public String toString() { 116 | String desc; 117 | switch (this.stopSize) { 118 | case STOPSIZE_REQUEST: 119 | desc = "REQUEST"; 120 | break; 121 | case STOPSIZE_1: 122 | desc = "1"; 123 | break; 124 | case STOPSIZE_2: 125 | desc = "2"; 126 | break; 127 | case STOPSIZE_1_5: 128 | desc = "1.5"; 129 | break; 130 | default: 131 | desc = "?"; 132 | break; 133 | } 134 | return this.getName() + " " + desc; 135 | } 136 | 137 | @Override 138 | public void visit(ComPortCommandSwitch sw) { 139 | sw.caseStopSize(this); 140 | } 141 | 142 | public int getStopSize() { 143 | return this.stopSize; 144 | } 145 | 146 | @Override 147 | int getMinPayloadLength() { 148 | return 1; 149 | } 150 | 151 | @Override 152 | int getMaxPayloadLength() { 153 | return 1; 154 | } 155 | } 156 | 157 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/TransmitBinaryOptionHandler.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import org.apache.commons.net.telnet.TelnetOptionHandler; 59 | 60 | /** 61 | * Handler for the telnet {@code TRANSMIT-BINARY} option defined by RFC 856. 62 | * 63 | * @see RFC 856 64 | */ 65 | public class TransmitBinaryOptionHandler extends TelnetOptionHandler { 66 | 67 | public static final int TRANSMIT_BINARY_OPTION = 0; 68 | 69 | public TransmitBinaryOptionHandler(boolean initlocal, boolean initremote, boolean acceptlocal, boolean acceptremote) { 70 | super(TRANSMIT_BINARY_OPTION, initlocal, initremote, acceptlocal, acceptremote); 71 | } 72 | 73 | @Override 74 | public int[] answerSubnegotiation(int[] data, int length) { 75 | return null; 76 | } 77 | 78 | @Override 79 | public int[] startSubnegotiationLocal() { 80 | return null; 81 | } 82 | 83 | @Override 84 | public int[] startSubnegotiationRemote() { 85 | return null; 86 | } 87 | } 88 | 89 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/Util.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import java.util.ArrayList; 59 | 60 | /** 61 | * Utility methods. 62 | */ 63 | final class Util { 64 | 65 | static final String[] LINE_STATE_BITS = new String[] { 66 | "TIME_OUT", 67 | "TRANSFER_SHIFT_REGISTER_EMPTY", 68 | "TRANSFER_HOLDING_REGISTER_EMPTY", 69 | "BREAK_DETECT", 70 | "FRAMING_ERROR", 71 | "PARITY_ERROR", 72 | "OVERRUN_ERROR", 73 | "DATA_READY", 74 | }; 75 | 76 | static final String[] MODEM_STATE_BITS = new String[] { 77 | "CARRIER_DETECT", 78 | "RING_INDICATOR", 79 | "DSR", 80 | "CTS", 81 | "DELTA_CARRIER_DETECT", 82 | "TRAILING_EDGE_RING_DETECTOR", 83 | "DELTA_DSR", 84 | "DELTA_CTS", 85 | }; 86 | 87 | private Util() { 88 | } 89 | 90 | static String decodeBits(int value, String[] names) { 91 | ArrayList list = new ArrayList(8); 92 | for (int i = 0; i < 8; i++) { 93 | if ((value & (1 << (7 - i))) != 0) 94 | list.add(names[i]); 95 | } 96 | if (list.isEmpty()) 97 | return "(none)"; 98 | names = list.toArray(new String[list.size()]); 99 | StringBuilder buf = new StringBuilder(); 100 | for (int i = 0; i < names.length; i++) { 101 | if (i > 0) 102 | buf.append(' '); 103 | buf.append(names[i]); 104 | } 105 | return buf.toString(); 106 | } 107 | 108 | static String rawBytes(int[] data, int off, int len) { 109 | StringBuilder buf = new StringBuilder(); 110 | for (int i = 0; i < len; i++) { 111 | if (i > 0) 112 | buf.append(' '); 113 | buf.append(String.format("0x%02x", data[off + i])); 114 | } 115 | return buf.toString(); 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /src/main/java/gnu/io/rfc2217/Version.java: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------- 2 | | RXTX License v 2.1 - LGPL v 2.1 + Linking Over Controlled Interface. 3 | | Copyright 2010 by Archie L. Cobbs and others. 4 | | 5 | | A copy of the LGPL v 2.1 may be found at 6 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 7 | | here for your convenience. 8 | | 9 | | This library is free software; you can redistribute it and/or 10 | | modify it under the terms of the GNU Lesser General Public 11 | | License as published by the Free Software Foundation; either 12 | | version 2.1 of the License, or (at your option) any later version. 13 | | 14 | | This library is distributed in the hope that it will be useful, 15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | | Lesser General Public License for more details. 18 | | 19 | | An executable that contains no derivative of any portion of RXTX, but 20 | | is designed to work with RXTX by being dynamically linked with it, 21 | | is considered a "work that uses the Library" subject to the terms and 22 | | conditions of the GNU Lesser General Public License. 23 | | 24 | | The following has been added to the RXTX License to remove 25 | | any confusion about linking to RXTX. We want to allow in part what 26 | | section 5, paragraph 2 of the LGPL does not permit in the special 27 | | case of linking over a controlled interface. The intent is to add a 28 | | Java Specification Request or standards body defined interface in the 29 | | future as another exception but one is not currently available. 30 | | 31 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 32 | | 33 | | As a special exception, the copyright holders of RXTX give you 34 | | permission to link RXTX with independent modules that communicate with 35 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 36 | | regardless of the license terms of these independent modules, and to copy 37 | | and distribute the resulting combined work under terms of your choice, 38 | | provided that every copy of the combined work is accompanied by a complete 39 | | copy of the source code of RXTX (the version of RXTX used to produce the 40 | | combined work), being distributed under the terms of the GNU Lesser General 41 | | Public License plus this exception. An independent module is a 42 | | module which is not derived from or based on RXTX. 43 | | 44 | | Note that people who make modified versions of RXTX are not obligated 45 | | to grant this special exception for their modified versions; it is 46 | | their choice whether to do so. The GNU Lesser General Public License 47 | | gives permission to release a modified version without this exception; this 48 | | exception also makes it possible to release a modified version which 49 | | carries forward this exception. 50 | | 51 | | You should have received a copy of the GNU Lesser General Public 52 | | License along with this library; if not, write to the Free 53 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 | | All trademarks belong to their respective owners. 55 | --------------------------------------------------------------------------*/ 56 | package gnu.io.rfc2217; 57 | 58 | import java.io.IOException; 59 | import java.io.InputStream; 60 | import java.util.Properties; 61 | 62 | /** 63 | * Contains library version information. 64 | */ 65 | public final class Version { 66 | 67 | /** 68 | * The version of this library. 69 | */ 70 | public static final String JVSER_VERSION; 71 | 72 | private static final String PROPERTIES_RESOURCE = "/jvser.properties"; 73 | private static final String VERSION_PROPERTY_NAME = "jvser.version"; 74 | 75 | static { 76 | Properties properties = new Properties(); 77 | InputStream input = Version.class.getResourceAsStream(PROPERTIES_RESOURCE); 78 | if (input == null) 79 | throw new RuntimeException("can't find resource " + PROPERTIES_RESOURCE); 80 | try { 81 | properties.load(input); 82 | } catch (IOException e) { 83 | throw new RuntimeException("unexpected exception", e); 84 | } finally { 85 | try { 86 | input.close(); 87 | } catch (IOException e) { 88 | // ignore 89 | } 90 | } 91 | JVSER_VERSION = properties.getProperty(VERSION_PROPERTY_NAME, "?"); 92 | } 93 | 94 | private Version() { 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/resources/com/neuronrobotics/nrjavaserial/build.properties: -------------------------------------------------------------------------------- 1 | app.name = nrjavaserial 2 | app.version = 5.2.1 3 | -------------------------------------------------------------------------------- /src/main/resources/jvser.properties: -------------------------------------------------------------------------------- 1 | # $Id: jvser.properties 13 2010-11-22 15:02:45Z archie.cobbs $ 2 | 3 | jvser.version=1.0.48 4 | -------------------------------------------------------------------------------- /test/src/test/NRJavaSerialTest.java: -------------------------------------------------------------------------------- 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 1997-2007 by Trent Jarvi tjarvi@qbang.org and others who 5 | | actually wrote it. See individual source files for more information. 6 | | 7 | | A copy of the LGPL v 2.1 may be found at 8 | | http://www.gnu.org/licenses/lgpl.txt on March 4th 2007. A copy is 9 | | here for your convenience. 10 | | 11 | | This library is free software; you can redistribute it and/or 12 | | modify it under the terms of the GNU Lesser General Public 13 | | License as published by the Free Software Foundation; either 14 | | version 2.1 of the License, or (at your option) any later version. 15 | | 16 | | This library is distributed in the hope that it will be useful, 17 | | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | | Lesser General Public License for more details. 20 | | 21 | | An executable that contains no derivative of any portion of RXTX, but 22 | | is designed to work with RXTX by being dynamically linked with it, 23 | | is considered a "work that uses the Library" subject to the terms and 24 | | conditions of the GNU Lesser General Public License. 25 | | 26 | | The following has been added to the RXTX License to remove 27 | | any confusion about linking to RXTX. We want to allow in part what 28 | | section 5, paragraph 2 of the LGPL does not permit in the special 29 | | case of linking over a controlled interface. The intent is to add a 30 | | Java Specification Request or standards body defined interface in the 31 | | future as another exception but one is not currently available. 32 | | 33 | | http://www.fsf.org/licenses/gpl-faq.html#LinkingOverControlledInterface 34 | | 35 | | As a special exception, the copyright holders of RXTX give you 36 | | permission to link RXTX with independent modules that communicate with 37 | | RXTX solely through the Sun Microsytems CommAPI interface version 2, 38 | | regardless of the license terms of these independent modules, and to copy 39 | | and distribute the resulting combined work under terms of your choice, 40 | | provided that every copy of the combined work is accompanied by a complete 41 | | copy of the source code of RXTX (the version of RXTX used to produce the 42 | | combined work), being distributed under the terms of the GNU Lesser General 43 | | Public License plus this exception. An independent module is a 44 | | module which is not derived from or based on RXTX. 45 | | 46 | | Note that people who make modified versions of RXTX are not obligated 47 | | to grant this special exception for their modified versions; it is 48 | | their choice whether to do so. The GNU Lesser General Public License 49 | | gives permission to release a modified version without this exception; this 50 | | exception also makes it possible to release a modified version which 51 | | carries forward this exception. 52 | | 53 | | You should have received a copy of the GNU Lesser General Public 54 | | License along with this library; if not, write to the Free 55 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 56 | | All trademarks belong to their respective owners. 57 | --------------------------------------------------------------------------*/ 58 | package test; 59 | import java.util.Enumeration; 60 | import java.util.concurrent.locks.Lock; 61 | import java.util.concurrent.locks.ReentrantLock; 62 | 63 | import gnu.io.CommPortIdentifier; 64 | 65 | public class NRJavaSerialTest { 66 | 67 | private static final Lock LOCK = new ReentrantLock(); 68 | private static final String PORT = "/dev/ttyUSB0"; 69 | 70 | public static void main(String[] args) throws Exception { 71 | Thread thread = new Thread(NRJavaSerialTest::printPortIdentifiers); 72 | thread.start(); 73 | Thread.sleep(2000L); 74 | CommPortIdentifier id = CommPortIdentifier.getPortIdentifier(PORT); 75 | id.open(NRJavaSerialTest.class.getSimpleName(), 5000); 76 | System.out.println("Opened: " + PORT); 77 | LOCK.lock(); 78 | } 79 | 80 | @SuppressWarnings("unchecked") 81 | private static void printPortIdentifiers() { 82 | try { 83 | for (int i=0;i<5&&!Thread.currentThread().isInterrupted();i++) { 84 | Enumeration ids = CommPortIdentifier.getPortIdentifiers(); 85 | System.out.println("--- Port Identifiers ---"); 86 | while (ids.hasMoreElements()) { 87 | System.out.println("name: " + ids.nextElement().getName()); 88 | } 89 | System.out.println(); 90 | Thread.sleep(5000L); 91 | } 92 | } catch (InterruptedException e) { 93 | System.out.println("Thread interrupted"); 94 | } 95 | System.exit(0); 96 | } 97 | } -------------------------------------------------------------------------------- /test/src/test/ReadTest.java: -------------------------------------------------------------------------------- 1 | package test; 2 | import java.io.DataInputStream; 3 | import java.io.DataOutputStream; 4 | import java.io.IOException; 5 | import java.util.TooManyListenersException; 6 | 7 | import gnu.io.NRSerialPort; 8 | import gnu.io.SerialPortEvent; 9 | import gnu.io.Zystem; 10 | public class ReadTest { 11 | public static void main(String [] args) { 12 | 13 | String port = ""; 14 | for(String s:NRSerialPort.getAvailableSerialPorts()){ 15 | System.out.println("Availible port: "+s); 16 | port=s; 17 | } 18 | 19 | int baudRate = 115200; 20 | NRSerialPort serial = new NRSerialPort(port, baudRate); 21 | serial.connect(); 22 | DataInputStream ins = new DataInputStream(serial.getInputStream()); 23 | try { 24 | serial.addEventListener(ev->{ 25 | if(ev.getEventType()==SerialPortEvent.DATA_AVAILABLE) { 26 | //while(ins.available()==0 && !Thread.interrupted());// wait for a byte 27 | try { 28 | while(ins.available()>0) {// read all bytes 29 | 30 | char b = (char) ins.read(); 31 | //outs.write((byte)b); 32 | System.out.print(b); 33 | 34 | } 35 | } catch (IOException e) { 36 | // TODO Auto-generated catch block 37 | e.printStackTrace(); 38 | } 39 | }if(ev.getEventType()==SerialPortEvent.HARDWARE_ERROR) { 40 | System.out.println("Clean exit of hardware"); 41 | serial.disconnect(); 42 | } 43 | }); 44 | } catch (TooManyListenersException e) { 45 | // TODO Auto-generated catch block 46 | e.printStackTrace(); 47 | } 48 | 49 | // DataOutputStream outs = new DataOutputStream(serial.getOutputStream()); 50 | // try{ 51 | // byte bytes[] = new byte[10]; 52 | // //while(ins.available()==0 && !Thread.interrupted());// wait for a byte 53 | // while(!Thread.interrupted()) {// read all bytes 54 | // //if(ins.available()>0) { 55 | // //char b = (char) ins.read(); 56 | // int back = ins.read(bytes); 57 | // //outs.write((byte)b); 58 | // for(int i=0;i