Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
313d1ac
Readme update
scream3r Mar 11, 2013
0a8f690
File.txt
scream3r Mar 11, 2013
c5cb719
Revert "File.txt"
scream3r Mar 11, 2013
f24c629
Added timeouts for read operations and SerialPortTimeoutException class
scream3r Mar 12, 2013
33e88f6
Project dates update
scream3r Mar 12, 2013
7395dd0
Added support of Linux ARM and *.jnilib->*.dylib MacOS X 10.8 fix
scream3r Mar 12, 2013
7dddbec
Windows native lib: port name string cancatenation fix, to prevent ex…
scream3r Mar 12, 2013
ffd0a5e
NULL port name fix
scream3r Mar 12, 2013
8ae8491
Readme extention change
scream3r Mar 13, 2013
61096c5
Zeroing COMMTIMEOUTS structure, because it can be changed by previous…
scream3r Apr 5, 2013
6eded5c
_nix based. Fixed clearing exclusive access on port close.
scream3r Apr 9, 2013
f368d5d
Changed years in license comment
scream3r Apr 10, 2013
c0727b8
Rewrited comparator for sotring port names. Now it's cross-platform
scream3r Apr 10, 2013
2819f0c
Added private getUnixBasedPortNames() method. It it a universal metho…
scream3r Apr 10, 2013
57863fa
Update README.txt
scream3r Apr 11, 2013
821c2a1
If port name == null, exception with TYPE_NULL_NOT_PERMITTED will be …
scream3r Apr 11, 2013
d54cdf7
Update README.txt
scream3r Apr 11, 2013
f3cec9a
Readme.txt update
scream3r Apr 11, 2013
1d6724c
Cleared SerialPortList class
scream3r Apr 12, 2013
c03f188
Cleared SerialPortList class (deleting of unused imports)
scream3r Apr 12, 2013
03356b7
Cleared body duplicating in addEventListener() methods
scream3r Apr 12, 2013
6baab11
Added support of errorOccurred method for SerialPortEventListener. On…
scream3r Apr 12, 2013
2590ae3
Fixed path to jssc_SerialNativeInterface.h in _nix_based source file
scream3r Apr 17, 2013
618d773
Added serialPort.closePort() to getUnixBasedPortNames()
scream3r Apr 17, 2013
fa056da
Added TYPE_PERMISSION_DENIED exception to SerialPortException class
scream3r Apr 17, 2013
82a0132
Added SerialPortException.TYPE_PERMISSION_DENIED support into SerialP…
scream3r Apr 17, 2013
c2c52e1
Added termios structure checking while port opening, and "Permission …
scream3r Apr 17, 2013
5a2f801
Rewrited native readBytes function, now it use termios structure for …
scream3r Apr 17, 2013
223740a
Updated jssc_SerialNativeInterface.h header file
scream3r Apr 17, 2013
ebcb3d8
Updated _nix_based jssc.cpp, added keys for disabling TIOCEXCL and pr…
scream3r Apr 17, 2013
273e132
Added useTIOCEXCL and invokedByPortList keys into native openPort() m…
scream3r Apr 17, 2013
6d542e0
Fixed "openPort()" invocations in considering of last changes
scream3r Apr 17, 2013
49c677a
Expanded javadoc for native openPort() method
scream3r Apr 18, 2013
f4e7252
Removed using of "invockedByPortList" parameter. Using of F_GETFL/F_S…
scream3r Apr 18, 2013
e23a292
Cleared "getUnixBasedPortNames()" method is SerialPortList class
scream3r Apr 18, 2013
d0b558a
Updated comment for openPort() in _nix_based jssc.cpp
scream3r Apr 18, 2013
521909e
Updated Windows native "openPort()" function signature, and function …
scream3r Apr 18, 2013
279c8b3
Readme file update
scream3r Apr 18, 2013
235f677
Readme file update
scream3r Apr 18, 2013
e4076c5
Readme file update
scream3r Apr 18, 2013
6d05623
Copyright symbol fix in native header file
scream3r Apr 18, 2013
2d481ff
Added JSSC_NO_TIOCEXCL property for disable using exclusive access to…
scream3r Apr 18, 2013
8e5a797
Added bluetooth serials to Linux port list search "rfcomm"
scream3r Apr 19, 2013
e8df646
jSSC version number changed in SerialNativeInterface class
scream3r Apr 19, 2013
cd4f05d
Added "getPortNames(String searchPath)" method and maded a little cha…
scream3r Apr 19, 2013
6ab3e83
Added method "getPortNames(String searchPath, Pattern pattern, Compar…
scream3r Apr 19, 2013
1043354
Added methods for advanced port listing by using another search path,…
scream3r Apr 19, 2013
df65d88
Added 3 constants to SerialNativeInterface class, and made a little r…
scream3r Apr 22, 2013
73c7a68
Added constants into jssc_SerialNativeInterface.h header file
scream3r Apr 22, 2013
ef28e80
Linux native jssc.cpp little refactoring
scream3r Apr 22, 2013
44f6fea
Added "ERR_INCORRECT_SERIAL_PORT" into SerialNativeInterface class an…
scream3r Apr 22, 2013
5b5a604
Added using of "ERR_INCORRECT_SERIAL_PORT" into SerialPort class. Als…
scream3r Apr 22, 2013
f756417
Linux native part, used "ERR_INCORRECT_SERIAL_PORT" instead of "ERR_P…
scream3r Apr 22, 2013
9544ad4
Windows native part. Added using of "ERR_INCORRECT_SERIAL_PORT", chec…
scream3r Apr 22, 2013
3363195
Removed port opening only for Linux in "getUnixBasedPortNames()" meth…
scream3r Apr 22, 2013
394bebd
Added fix for issue #10. If user home folder is read-only, the native…
scream3r Apr 23, 2013
7f44d12
Removed 0.9 Windows native libs
scream3r Apr 23, 2013
e8cfc9b
Added 2.3 Windows native libs
scream3r Apr 23, 2013
c7a199c
Readme update
scream3r Apr 24, 2013
d818ecb
Changed port handle from "int" to "long" type, to prevent Win64 HANDL…
scream3r Apr 24, 2013
f83f0d3
Updated "jssc_SerialNativeInterface.h" header file. jint changed to j…
scream3r Apr 24, 2013
aa73dea
Updated _nix "jssc.cpp" file. jint changed to jlong
scream3r Apr 24, 2013
33d9953
Updated library version to 2.4
scream3r Apr 24, 2013
771f1ca
Updated Windows "jssc.c++" file. jint changed to jlong
scream3r Apr 24, 2013
30accf3
Readme file update
scream3r Apr 25, 2013
d613a3d
Enabled using of TIOCEXCL and TIOCNXCL for Solaris OS (SunOS)
scream3r Apr 25, 2013
9b2554b
Removed Solaris native libs
scream3r Apr 25, 2013
5aaaf63
Added 2.4 Solaris native libs
scream3r Apr 25, 2013
4f3f66c
Readme update
scream3r Apr 25, 2013
4b4ad8b
Removed 0.9 native libs for MacOS X
scream3r Apr 25, 2013
d47f257
Added 2.4 MacOS X native libs
scream3r Apr 25, 2013
432eed1
Removed Windows 2.3 native libs
scream3r Apr 26, 2013
0bfbc3e
Added Windows 2.4 native libs
scream3r Apr 26, 2013
bfbd2d2
Removed Linux 0.9 native libs
scream3r Apr 26, 2013
14963e8
Added Linux 2.4 native libs
scream3r Apr 26, 2013
8d1652d
Removed Linux ARM 0.9 soft-float native lib
scream3r Apr 26, 2013
db6c082
Added Linux ARM 2.4 soft-float native lib
scream3r Apr 26, 2013
da5f023
Removed Linux ARM 0.9 hard-float native lib
scream3r Apr 26, 2013
906964f
Added Linux ARM 2.4 hard-float native lib
scream3r Apr 26, 2013
eada9f7
Readme file update
scream3r Apr 26, 2013
7a166d0
Rewrited _nux native "readBytes()" function to prevent problems with …
scream3r Apr 27, 2013
99938e2
Replaced Linux 2.4 native libs to 2.5
scream3r Apr 27, 2013
00dc395
Renamed Windows native libs
scream3r Apr 27, 2013
b835781
Replaced MacOS X 2.4 native libs to 2.5
scream3r Apr 27, 2013
e427624
Replaced Solaris 2.4 native libs to 2.5
scream3r Apr 27, 2013
3cd01f9
Replaced Linux ARM 2.4 native libs to 2.5
scream3r Apr 27, 2013
e383239
Changed jSSC library version to 2.5.0
scream3r Apr 27, 2013
7419d9b
Readme file update
scream3r Apr 27, 2013
4d98a70
Added include of <string.h> for SunOS into _nix "jssc.cpp" file
scream3r Apr 27, 2013
48af99b
Readme update
scream3r May 31, 2013
c5dfff9
Added os.name - "Darwin" and os.arch - "universal" to SerialNativeInt…
scream3r May 31, 2013
d57c122
Added ttyO to Linux RegExp for finding serial ports provided by Linux…
scream3r May 31, 2013
a9b6a00
Added support of "int flags" for "setParams()" method, and also added…
scream3r Jun 1, 2013
b63e7db
Added generics for "Comparator" parameters
scream3r Jun 1, 2013
20171d9
Added const-s for properties: PROPERTY_JSSC_NO_TIOCEXCL, PROPERTY_JSS…
scream3r Jun 1, 2013
72fa4b5
Removed Linux native libs
scream3r Jun 1, 2013
c4581b5
Added Linux x86 and x86-64 native libs
scream3r Jun 1, 2013
44a750f
Added "jint flags" to Windows-native setParams() method, for compatib…
scream3r Jun 1, 2013
f24483e
Replaced 2.5 Windows-native libs with 2.6
scream3r Jun 1, 2013
d2d3473
Replaced 2.5 Solaris-native libs with 2.6
scream3r Jun 1, 2013
d668c2c
Replaced 2.5 MacOSX-native libs with 2.6
scream3r Jun 1, 2013
bc29b60
Added Linux-ARM 2.6 native libs
scream3r Jun 1, 2013
b61c224
Updated release info
scream3r Jun 1, 2013
a743b53
Fix for a "file handler" leak in native openPort method.
cmaglie Jan 18, 2014
5a32b4b
Merge pull request #36 from cmaglie/fix-file-handle-leak
scream3r Jan 20, 2014
1f322aa
Added 'since' comment and changed comment date
scream3r Jan 20, 2014
21fa240
Updated dates and jSSC lib version
scream3r Jan 20, 2014
b813f26
Windows 2.6 native libs replaced with 2.7
scream3r Jan 20, 2014
d8eaf04
Added 'since' comment for *nix_based native source and updated genera…
scream3r Jan 20, 2014
11b163f
Replaced Linux 2.6 x86 and x86-64 libs with 2.7
scream3r Jan 20, 2014
e7885cc
Solaris native 2.6 replaced with 2.7
scream3r Jan 20, 2014
ef6a837
MacOS X 2.6 native libs replaced with 2.7
scream3r Jan 20, 2014
791a995
Replaced ARM 2.6 native libs with 2.7
scream3r Jan 20, 2014
3c05bed
Readme update
scream3r Jan 20, 2014
e56d39f
Added "writeString(String string, String charsetName)" method
scream3r Jan 24, 2014
5d1515a
Added "getNativeLibVersion" method and and version mismatch check on …
scream3r Jan 24, 2014
a02a5f1
Replaced Windows 2.7 native library with 2.8
scream3r Jan 24, 2014
8533cbe
Fixed copyright symbol
scream3r Jan 24, 2014
4cc7332
Added "getNativeLibraryVersion" for "*nix" based systems
scream3r Jan 24, 2014
b9b2b12
Replaced Linux 2.7 native libs with 2.8
scream3r Jan 24, 2014
cbf5d60
Updated "getNativeLibraryVersion" javadoc
scream3r Jan 24, 2014
1d63a06
Replaced Solaris 2.7 native libs with 2.8
scream3r Jan 24, 2014
c83343e
Replaced MacOS X 2.7 native libs with 2.8
scream3r Jan 24, 2014
8fb7e3d
c symbol
scream3r Jan 24, 2014
63a7fb6
Replaced Windows 2.7 native libs with 2.8
scream3r Jan 24, 2014
9bd64e5
Replaced ARM Linux 2.7 native libs with 2.8
scream3r Jan 24, 2014
f556486
Readme update
scream3r Jan 24, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added timeouts for read operations and SerialPortTimeoutException class
  • Loading branch information
scream3r committed Mar 12, 2013
commit f24c6296628249abaedf1b2d964f445d6d8d141e
143 changes: 139 additions & 4 deletions src/java/jssc/SerialPort.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2011.
* © Alexey Sokolov (scream3r), 2010-2013.
*
* This file is part of jSSC.
*
Expand Down Expand Up @@ -417,7 +417,7 @@ public String readString(int byteCount) throws SerialPortException {
}

/**
* Read Hex string from port (example: FF OA FF). Separator by default is a space
* Read Hex string from port (example: FF 0A FF). Separator by default is a space
*
* @param byteCount count of bytes for reading
*
Expand All @@ -433,7 +433,7 @@ public String readHexString(int byteCount) throws SerialPortException {
}

/**
* Read Hex string from port with setted separator (example if separator is "::": FF::OA::FF)
* Read Hex string from port with setted separator (example if separator is "::": FF::0A::FF)
*
* @param byteCount count of bytes for reading
*
Expand Down Expand Up @@ -509,6 +509,141 @@ public int[] readIntArray(int byteCount) throws SerialPortException {
return intBuffer;
}

private void waitBytesWithTimeout(String methodName, int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException {
checkPortOpened("waitBytesWithTimeout()");
boolean timeIsOut = true;
long startTime = System.currentTimeMillis();
while((System.currentTimeMillis() - startTime) < timeout){
if(getInputBufferBytesCount() >= byteCount){
timeIsOut = false;
break;
}
try {
Thread.sleep(0, 100);//Need to sleep some time to prevent high CPU loading
}
catch (InterruptedException ex) {
//Do nothing
}
}
if(timeIsOut){
throw new SerialPortTimeoutException(portName, methodName, timeout);
}
}

/**
* Read byte array from port
*
* @param byteCount count of bytes for reading
* @param timeout timeout in milliseconds
*
* @return byte array with "byteCount" length
*
* @throws SerialPortException
* @throws SerialPortTimeoutException
*
* @since 2.0
*/
public byte[] readBytes(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException {
checkPortOpened("readBytes()");
waitBytesWithTimeout("readBytes()", byteCount, timeout);
return readBytes(byteCount);
}

/**
* Read string from port
*
* @param byteCount count of bytes for reading
* @param timeout timeout in milliseconds
*
* @return byte array with "byteCount" length converted to String
*
* @throws SerialPortException
* @throws SerialPortTimeoutException
*
* @since 2.0
*/
public String readString(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException {
checkPortOpened("readString()");
waitBytesWithTimeout("readString()", byteCount, timeout);
return readString(byteCount);
}

/**
* Read Hex string from port (example: FF 0A FF). Separator by default is a space
*
* @param byteCount count of bytes for reading
* @param timeout timeout in milliseconds
*
* @return byte array with "byteCount" length converted to Hexadecimal String
*
* @throws SerialPortException
* @throws SerialPortTimeoutException
*
* @since 2.0
*/
public String readHexString(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException {
checkPortOpened("readHexString()");
waitBytesWithTimeout("readHexString()", byteCount, timeout);
return readHexString(byteCount);
}

/**
* Read Hex string from port with setted separator (example if separator is "::": FF::0A::FF)
*
* @param byteCount count of bytes for reading
* @param timeout timeout in milliseconds
*
* @return byte array with "byteCount" length converted to Hexadecimal String
*
* @throws SerialPortException
* @throws SerialPortTimeoutException
*
* @since 2.0
*/
public String readHexString(int byteCount, String separator, int timeout) throws SerialPortException, SerialPortTimeoutException {
checkPortOpened("readHexString()");
waitBytesWithTimeout("readHexString()", byteCount, timeout);
return readHexString(byteCount, separator);
}

/**
* Read Hex String array from port
*
* @param byteCount count of bytes for reading
* @param timeout timeout in milliseconds
*
* @return String array with "byteCount" length and Hexadecimal String values
*
* @throws SerialPortException
* @throws SerialPortTimeoutException
*
* @since 2.0
*/
public String[] readHexStringArray(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException {
checkPortOpened("readHexStringArray()");
waitBytesWithTimeout("readHexStringArray()", byteCount, timeout);
return readHexStringArray(byteCount);
}

/**
* Read int array from port
*
* @param byteCount count of bytes for reading
* @param timeout timeout in milliseconds
*
* @return int array with values in range from 0 to 255
*
* @throws SerialPortException
* @throws SerialPortTimeoutException
*
* @since 2.0
*/
public int[] readIntArray(int byteCount, int timeout) throws SerialPortException, SerialPortTimeoutException {
checkPortOpened("readIntArray()");
waitBytesWithTimeout("readIntArray()", byteCount, timeout);
return readIntArray(byteCount);
}

/**
* Read all available bytes from port like a byte array
*
Expand Down Expand Up @@ -609,7 +744,7 @@ public String[] readHexStringArray() throws SerialPortException {
* @since 0.8
*/
public int[] readIntArray() throws SerialPortException {
checkPortOpened("readHex()");
checkPortOpened("readIntArray()");
int byteCount = getInputBufferBytesCount();
if(byteCount <= 0){
return null;
Expand Down
64 changes: 64 additions & 0 deletions src/java/jssc/SerialPortTimeoutException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* jSSC (Java Simple Serial Connector) - serial port communication library.
* © Alexey Sokolov (scream3r), 2010-2013.
*
* This file is part of jSSC.
*
* jSSC is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jSSC is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with jSSC. If not, see <http://www.gnu.org/licenses/>.
*
* If you use jSSC in public project you can inform me about this by e-mail,
* of course if you want it.
*
* e-mail: scream3r.org@gmail.com
* web-site: http://scream3r.org | http://code.google.com/p/java-simple-serial-connector/
*/
package jssc;

/**
*
* @author scream3r
*/
public class SerialPortTimeoutException extends Exception {

private String portName;
private String methodName;
private int timeoutValue;

public SerialPortTimeoutException(String portName, String methodName, int timeoutValue) {
super("Port name - " + portName + "; Method name - " + methodName + "; Serial port operation timeout (" + timeoutValue + " ms).");
this.portName = portName;
this.methodName = methodName;
this.timeoutValue = timeoutValue;
}

/**
* Getting port name during operation with which the exception was called
*/
public String getPortName(){
return portName;
}

/**
* Getting method name during execution of which the exception was called
*/
public String getMethodName(){
return methodName;
}

/**
* Getting timeout value in millisecond
*/
public int getTimeoutValue(){
return timeoutValue;
}
}