Skip to content

Commit

Permalink
Changes to migrate from rxtx libs to jssc the better serial communica…
Browse files Browse the repository at this point in the history
…tions lib.
  • Loading branch information
sbamamoto committed Mar 8, 2015
1 parent ecb5c4d commit 67c2aad
Show file tree
Hide file tree
Showing 26 changed files with 215 additions and 696 deletions.
11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.rxtx</groupId>
<artifactId>rxtx</artifactId>
<version>2.1.7</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.scream3r</groupId>
<artifactId>jssc</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
</project>
139 changes: 0 additions & 139 deletions src/main/java/com/dummy/DummyRXTXPort.java

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/com/dummy/DummySerialPortEvent.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/com/dummy/DummySerialPortEventListener.java

This file was deleted.

11 changes: 8 additions & 3 deletions src/main/java/com/lhf/jobexftp/StandAloneApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jssc.SerialPortException;
import jssc.SerialPortTimeoutException;


/**
*
Expand All @@ -59,7 +62,7 @@ public static void main(String[] args) {
}
}
new StandAloneApp().exec(args);
} catch (gnu.io.NoSuchPortException e) {
} catch (SerialPortException e) {
Log.info("Fatal: Port is unavaliable.", e);
System.exit(1);
} catch (Exception e) {
Expand Down Expand Up @@ -232,7 +235,7 @@ private void updateDir(UserInterface ui, OBEXClient obexClient) {
ui.setDir(obexClient.getCurrentFolder().getPath() + "/");
}

private void processUserInterface(ATConnection device, UserInterface ui) throws IOException {
private void processUserInterface(ATConnection device, UserInterface ui) throws IOException, SerialPortException, SerialPortTimeoutException {
OBEXClient obexClient = new OBEXClient(device);
try {
String cmdline;
Expand Down Expand Up @@ -391,7 +394,7 @@ private boolean sjra(ATConnection device, String absolutePath) throws IOExceptio

private void printAbout(UserInterface ui, ATConnection device, OBEXClient obexClient) {
String helper;
ui.println("Connected to: " + device.getCommPortIdentifier().getName());
ui.println("Connected to: " + device.getComPortIdentifier());
ui.println("Device identified: " + device.getDevice().name());
switch (device.getFlowControl()) {
case ATConnection.FLOW_XONXOFF:
Expand Down Expand Up @@ -426,6 +429,8 @@ private void printAbout(UserInterface ui, ATConnection device, OBEXClient obexCl
ui.println("Disk free space: " + Utility.humanReadableByteCount(obexClient.getFreeSpace(), true));
} catch (IOException ex) {
Logger.getLogger(StandAloneApp.class.getName()).log(Level.SEVERE, null, ex);
} catch (SerialPortException ex) {
Logger.getLogger(StandAloneApp.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/lhf/obexftplib/etc/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.lhf.obexftplib.io.obexop.GetResponse;
import com.lhf.obexftplib.io.obexop.Header;
import com.lhf.obexftplib.io.obexop.Response;
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.DateFormat;
Expand Down Expand Up @@ -85,17 +83,17 @@ public static String readStandardInput() {
return buf.toString().trim();
}

/**
* This is a hack to ports like /dev/ttyACM0 work in RxTx.
* @param connPortPath the port path to add;
* @since 1.0
*/
public static CommPortIdentifier addPortToRxTx(final String connPortPath) throws NoSuchPortException {
if (connPortPath.indexOf("ttyS") < 0 && connPortPath.indexOf("COM") < 0 && connPortPath.indexOf("tty.") < 0) {
System.setProperty("gnu.io.rxtx.SerialPorts", connPortPath);
}
return CommPortIdentifier.getPortIdentifier(connPortPath);
}
// /**
// * This is a hack to ports like /dev/ttyACM0 work in RxTx.
// * @param connPortPath the port path to add;
// * @since 1.0
// */
// public static CommPortIdentifier addPortToRxTx(final String connPortPath) throws NoSuchPortException {
// if (connPortPath.indexOf("ttyS") < 0 && connPortPath.indexOf("COM") < 0 && connPortPath.indexOf("tty.") < 0) {
// System.setProperty("gnu.io.rxtx.SerialPorts", connPortPath);
// }
// return CommPortIdentifier.getPortIdentifier(connPortPath);
// }

/**
* Checks for the combination looking from end to begining, in the whole array
Expand Down Expand Up @@ -197,7 +195,9 @@ public static byte[] intToBytes(final int integer, final int bLength) {
*/
public static int bytesToInt(final byte[] bytes) {
int result = 0;

if (bytes == null ) {
return 0;
}
for (int i = 0; i < bytes.length; i++) {
int temp = (int) bytes[i];
if (temp < 0) {
Expand Down
Loading

0 comments on commit 67c2aad

Please sign in to comment.