Giter Site home page Giter Site logo

jserialcomm's Introduction

jSerialComm

A platform-independent serial port access library for Java.

Usage

For usage examples, please refer to the Usage wiki.

If you intend to use the library in multiple applications simultaneously, you may need to set the fazecast.jSerialComm.appid property before accessing the SerialPort class so that applications don't accidentally delete each others' temporary files during boot-up (this should almost never be necessary):

System.setProperty("fazecast.jSerialComm.appid", "YOUR_APPLICATION_IDENTIFIER")

Alternately, if you plan to use the library within an Apache Tomcat application, please set the jSerialComm.library.randomizeNativeName property to true before accessing the SerialPort class to address an issue whereby the Tomcat bootloader tries to reinitialize the library multiple times. This can either be done using -DjSerialComm.library.randomizeNativeName="true" as a command line parameter or by calling the following within your own application before using any SerialPort functionality:

System.setProperty("jSerialComm.library.randomizeNativeName", "true")

In order to use the jSerialComm library in your own project, you must simply include the JAR file in your build path and import it like any other Java package using import com.fazecast.jSerialComm.*;.

Alternately, you can automatically add jSerialComm to your project as a dependency from the Maven Central Repository. Use the following dependency declaration depending on your build system:

  • Maven:
<dependency>
  <groupId>com.fazecast</groupId>
  <artifactId>jSerialComm</artifactId>
  <version>[2.0.0,3.0.0)</version>
</dependency>
  • Ivy:
<dependency org="com.fazecast" name="jSerialComm" rev="[2.0.0,3.0.0)"/>
  • Groovy:
@Grab(group='com.fazecast', module='jSerialComm', version='[2.0.0,3.0.0)')
  • Gradle:
compile 'com.fazecast:jSerialComm:[2.0.0,3.0.0)'
  • Gradle (.kts):
compile("com.fazecast:jSerialComm:[2.0.0,3.0.0)")
  • Buildr:
compile.with 'com.fazecast:jSerialComm:jar:[2.0.0,3.0.0)'
  • Scala/SBT:
libraryDependencies += "com.fazecast" % "jSerialComm" % "[2.0.0,3.0.0)"
  • Leiningen:
[com.fazecast/jSerialComm "[2.0.0,3.0.0)"]

Finally, if you are working on a device that provides no other means of allowing temporary native files to run, jSerialComm supports loading a pre-extracted version of its native library from a user-defined location using the startup flag: -DjSerialComm.library.path="<LIB_PATH>", where LIB_PATH can either be a directory containing the single native jSerialComm library for your correct architecture or the entire extracted arch-specific directory structure from inside the jSerialComm JAR file; however, this should be used as a last resort as it makes versioning and upgrading much more difficult and error-prone.

Troubleshooting

If you are using Linux and this library does not appear to be working, ensure that you have the correct permissions set to access the serial port on your system. One way to test this is to run your application as root or by using the sudo command. If everything works, you will need to either run your application as root in the future or fix the permissions on your system. For further instructions, refer to the Troubleshooting wiki.

On some very few systems which use custom ARM-based CPUs and/or have extremely restrictive permissions, the library may be unable to determine that the underlying system architecture is ARM. In this case, you can force the library to disable its auto-detect functionality and instead directly specify the architecture using the Java os.arch_full system property. Acceptable values for this property are currently one of: armv5, armv6, armv7, armv8_32, armv8_64, ppc64le, x86, or x86_64.

Additionally, some systems may block execution of libraries from the system temp folder. If you are experiencing this problem, you can specify a different, less restrictive temp folder by adding System.setProperty("java.io.tmpdir", "/folder/where/execution/is/allowed") to your program before the first use of this library. When doing this, make sure that the folder you specify already exists and has the correct permissions set to allow execution of a shared library.

Optionally, the same result can be achieved by running your Java application from the command line and specifying the java.io.tmpdir directory as an additional parameter, e.g.: java -Djava.io.tmpdir=/folder/of/your/choice -jar yourApplication.jar

On Windows, you may be able to achieve the same result by setting the TMP environment variable (either through the Settings->System Properties->Environment Variables GUI or via SET TMP=C:\Desired\Tmp\Folder in a command terminal), although setting this variable through Java is preferable when possible.

An additional note for Linux users: If you are operating this library in event-based mode, the LISTENING_EVENT_DATA_WRITTEN event will never occur. This is not a bug, but rather a limitation of the Linux operating system.

For other troubleshooting issues, please see if you can find an answer in either the Usage-Examples wiki or the Troubleshooting Wiki.

If your question is still not answered, feel free to open an issue report on this project's GitHub page, and we will be glad to look into it.

Building

Building this library yourself is not advised (at least not for distribution) since it requires native compilation across multiple platforms. It is recommended to simply use the pre-built jSerialComm library in your application. For installation/usage instructions, please skip to the usage section.

If you do choose to build this library from source, please follow the instructions in the Building Tutorial to set up the required toolchains.

jserialcomm's People

Contributors

amitjoy avatar arth-ur avatar feclare avatar frhun avatar gradle-update-robot avatar hedgecrw avatar javmarina avatar jlubawy avatar jskubick avatar kc3spw avatar kevinherron avatar nuntipat avatar rbanalagay avatar redirion avatar rusefillc avatar sirhcel avatar swilson avatar viktorpenelski avatar yigitpirildak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jserialcomm's Issues

SerialPortDataListener.serialEvent time-sensitive on Windows (and not Linux)?

Hi! We've found what appears to be an inconsistency between Linux and Windows using this library.

On Linux we can do long tasks within our serialEvent callback (even Thread.sleep for a few seconds if we wish), whereas in Windows we lose events if our serialEvent callback takes too long.

For now we are looking to work around this by making serialEvent return control to your library as quick as possible, but this does appear to be a bug. Thoughts?

All baudrates become 9600 on Mac OSX for some devices

We're in the process of switching one of the programs at my workplace from RXTX (because it is insane) to jSerialComm (because it seems nice) and so far it works beautifully in both Windows and Linux. However, it seems that no matter what we set the baudrate to on Mac it remains at 9600. Reading and writing to a 9600 baudrate device works fine regardless of what we ask jSerialComm to use, so it looks like everything else apart from setting the baudrate is fine.

A bit of Google-fu turns up this related chrome issue:
http://code.google.com/p/chromium/issues/detail?id=337482
It is a very similar setup (we're also using a USB<->serial chip, in this case the Arduino Uno r2) and it looks like IOSSIOSPEED could be resetting the speed to 9600 because it may be unsupported with the driver used for this board.

How to know when bytes have been written?

Hi Will, is there anyway that I can determine when a buffer has been completely written out of the port?
Our UART port is connected to an RS485 chip that is uni-directional in that I have to switch it into write mode, send the data, then switch it to read mode to get the response.
If I set it to read before the buffer has completely written, it will fail.
I'm handling it at the moment by creating suitable timer delays but if there is a better way.

Connection problems on the RaspberryPI with Raspbian

Hi,
I'm currently having an issue when I try to use the library on my RaspberryPI with Raspbian. The problem occours when I call the write method on the SerialPort object. It throws an IOException("This port appears to have been shutdown or disconnected."). I tried the steps which are discribed in the troubleshooting page in the wiki. Maybe someone who got the library working on the RaspberryPi2 could help me to solve this problem.

symlinks are not visible (linux)

Currently there is no way to select a serial port by using one of its symlinks. The problem with Linux systems is, that the usb port mapping changes with every reboot. Currently I use three serial ports simultanously for different external hardware components. The only way to make the ports usable (with same name) after reboot is to define some udev rules. Thus mapping connected devices to some predefines names depending on their properties (serial, manufacturer etc.), e.g. ttyUSB1 -> ttyUSBMyDevice.

In my current implementation I use four different Java serial drivers (I make them selectable): SimpleSerial, SerialComm, RXTX and PureJavaSerial. As far as I know all implementations (except PureJavaSerial which uses JNA) use some C counterpart which in turn filters all available devices by using RegularExpression (or similar). So for example SimpleSerial makes symlinks availble with name patterns ttyUSB* and ttyS*.

Are there any plans to make symlinks usable with SerialComm? Or at least symlinks with some specific name (e.g. ttyUSB...)?

Thanks in advance,

Slavi

When using the InputStream of a port, it seems to buffer hundreds of lines

Hello,

When reading a port's InputStream, it seems to buffer for a few hundred lines before allowing any text to be read out. After the buffer fills (or whatever is causing the problem) all of the text gets immediately dumped, so nothing seems to be lost.

For example, if I have a micocontroller sending a constant stream of lines (ASCII text) over a USB UART, appromixately 250 lines seem to get "buffered" before Scanner.hasNextLine() returns. My code is as follows:

...
SerialPort port = SerialPort.getCommPort("COM4");
port.setBaudRate(115200);
port.setComPortTimeouts(SerialPort.TIMEOUT_READ_BLOCKING | SerialPort.TIMEOUT_WRITE_BLOCKING, 0, 0);
port.setFlowControl(SerialPort.FLOW_CONTROL_DISABLED);
if(port.openPort() == false) {
System.err.println("Unable to open the port.");
return;
}
Scanner s = new Scanner(port.getInputStream());
while(s.hasNextLine()) {
String line = s.nextLine();
System.out.println("Line of text from serial port: " + line);
}
...

Lines of text are being sent by the microcontroller several times per second, but they get buffered and all dumped in a fraction of a second, in bursts of approximately 250 lines at a time.

I'm not sure if this is due to an incorrect setting on my part, or maybe a bug in the library.

In my testing I have tried/verified the following:

  1. This problem occurs with two different computers and microcontrollers. Same behavior in Windows Vista and Windows 10 Technical Preview.
  2. The hardware and computers seem to be fine, as I can read the lines of text perfectly with Tera Term and other terminal programs.
  3. The RXTX library for Java works fine for me, but is less convent to use than your library.

Any ideas?

Thanks,

-Farrell

Trouble Finding Serial Ports using jSerialComm on Linux

Hey, I ran all the commands to add myself to the groups, (i believe dialout was the one that owned ttyS0) and when I run the following code:
System.out.println(SerialPort.getCommPorts()[0]);
I get:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at com.logansnow.jSerialCommRunner.main(jSerialCommRunner.java:11) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Which is weird because when I use the jssc library I am able to connect to my Arduino. Thanks
Additional information:
I am running an Arduino Uno that is constantly sending 0's or 1's through serial
I am on Elementary OS which is Ubuntu based
I am definitely in the dialout group based on the output of groups ${USER}

Cant see ports using socat

I need to emulate two serial ports and bind them (one for write and the other to read), in Windows I use com0com and works fine but in Ubuntu I try to use Socat (https://help.ubuntu.com/community/VirtualSerialPort) and I cant see the two ports I create.

I use this command:
sudo socat PTY,link=/dev/ttyACM1 PTY,link=/dev/ttyACM2

Do you have any idea why this happens? or any solution for Ubuntu?

The funny thing is that for example on the Arduino IDE i can see the two ports that i create using the SOCAT command.

Any type of help or guidance is really appreciate.

Thanks and best wishes.

Timeouts not functioning

I'm in the process of upgrading the j2mod library to version 2.0 which replaces the cursed RxTxComm library with the rather splendid jSerialComm.

The migration to jSerialComm has been pretty painless but I've come up against a problem with blocking IO.

It doesn't seem to matter what timeout policy I set and what value I use for the timeout, the read always blocks indefinitely.
Conversely, the write doesn't seem to block at all and returns immediately.

Is there anything I can do to give you more to go on?
The environment is Pi2 running Wheezy.

I also tried running the same code on my Mac and the same thing happens, the read never times out.
I must be doing something pretty basically wrong somewhere.

Setting IOCTL_SERIAL_LSRMST_INSERT and IOCTL_SERIAL_SET_HANDFLOW

Hi,
I am facing a couple of issues as follows:
1> I'm currently using jSerialComm to interface with an Event based RS232 port, I wanted to set the IOCTL_SERIAL_LSRMST_INSERT for which I do not find any API or parameter to do it. The server requires me to set its value to LSRMST_INSERT - 0x00000000, please let me know if there is a way to do it in jSerialComm, I have gone through the API docs and could not find anything to do this.

2> I'm calling the SerialPort.setFlowControl(SerialPort.FLOW_CONTROL_DISABLED) but in the request buffer the flow control is still enabled as shown below:

IRP_MJ_DEVICE_CONTROL - Request operates a serial port
    STATUS_SUCCESS
IOCTL_SERIAL_SET_HANDFLOW - Request sets the configuration of handshake flow control
ControlHandShake - 1
FlowReplace      - 0x80000040
XonLimit         - 2048
XoffLimit        - 512

Please let me know if there is any solution to these issues.
Thanks & Regards,
Nachiketh

Linux (Raspberry PI3 Ubuntu Mate)

I have been cracking my head on getting my java jframe (not android) connect to /dev/rfcomm0.
Able to see data flowing thru /dev/rfcomm0. using 3rd party linux hyperterminal apps cutecom.
By the way only able to list /dev/ttyS0 and /dev/ttyAMA0 but NOT /dev/rfcomm0

Is the jserialcomm support on rfcomm (Linux) ? Maybe I am not sure how to do it or use it wrongly.

It works perfectly with windows. Please help me.

readBytes hangs on Raspberry Pi2

Hi,

I using LISTENING_EVENT_DATA_AVAILABLE event in listener and after some time of my application running OK the readBytes method hangs forever. I can see that I have 9 bytes available but the call to readBytes is not ending. I am using default ComPort timeout.

Everything work on my desktop Ubuntu.

Add support for opening multiple ports in the same program

It is currently not possible to open more than one serial port in the same program using this library. (As a matter of fact, I just tried this library today because RXTX and its forks have the same limitation.)

I've tried this on Mac OS 10.10.3 with two USB-Serial adapters (specifically, two Arduinos with their builtin adapters), using Java 8.

From the symptoms I've observed, there is some confusing inside the library regarding the input and output streams.

At first I tried using event-based input from the two ports, which did not work (no events were created, without any errors).

Then I switched over to loop-based reading. In my use-case, I send out some data on one port, which sends back some acknowledge string, and sends over the data to the device on the other port, where the data comes back in. So I open the ports, write the command on the outgoing port, then enter a loop like:

        while (true) {
            if (outPort.inputStream.available() > 0) {
                len = outPort.inputStream.read(data, 0, 1024);
                if (len > 0) {
                    System.out.println("Out " + new String(data, 0, len));
                }
            }
            if (outPort.inputStream.available() > 0) {
                len = outPort.inputStream.read(data, 0, 1024);
                if (len > 0) {
                    System.out.println("In " + new String(data, 0, len));
                }
            }
        }

inPort and outPort are adapter objects for SerialPort, but their inputStream fields are exactly the streams returned by the SerialPort instances.

When I run this, I get the acknowledge string -- but someones on the "Out" line and sometimes on the "In" line, and sometimes spread over the two. The incoming string (which should come from inPort) is never received.

Error when compiling for Android

Hi!

When I'm trying compile the project for Android, I get the following error:

cp -rf libs/* ../../resources/Android
process_begin: CreateProcess(NULL, cp -rf libs/* ../../resources/Android, ...) failed.
make (e=2): The system cannot find the file specified.
make.exe: *** [all] Error 2

Which file is missing? Or did it fail to create a certain file?

Thanks in advance.

Cannot close port after data recieve

Hi,
When I try to close connection after data recive, the method which close port connection freez. I testetd this behavior on Windows 10 and Windows 7 64 bit. I tried to remove listner from port but this method also freez.

inputStream and OutputStream/JAVAFX

Not sure if this is an issue:

I was wondering of anyone is using this library to continuously receive from the serial port parsing data (I am using a buffered input reader to parse comma delimited lines) while at the same time using a JavaFX control (like a button) to have data send to the serial port over an Bufferedoutput stream on an say button click event. I have looked over all the examples and documentation, and I really can not find one that shows the construct of a SerialPort.getOutputStream combined with an input reader/streamer. Is this possible with this library, or will there be blocking issues? Can someone please point me in the right direction/show an example? I guess bottom line, is it possible to Receive data completely Asynchronously through a port listening event, and send data through a button event handler? This is what I am struggling with.....

java.lang.UnsatisfiedLinkError on Android

HI, sorry for my english. I'm trying to use jSerialComm.jar in my android project.
Device is Android 4.4.2 with phisical serial ports (no usb to rs232)

In my build.grandle i've set
compile 'com.fazecast:jSerialComm:1.3.11'

than in app/src/main I've created jniLibs with structure and .so files.

in mainActivity

System.loadLibrary("jSerialComm"); //no errors
SerialPort[]    sp= null;
try
 {
    sp= SerialPort.getCommPorts(); //error !!!!
 }
catch(Exception ex)
{
 ex.printStackTrace();
 }

When start project on device i run into an error:
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.apiciolabs.easycash/cache/1463764816989-libjSerialComm.so" is too small to be an ELF executable at java.lang.Runtime.load(Runtime.java:333) at java.lang.System.load(System.java:512) at com.fazecast.jSerialComm.SerialPort.<clinit>(SerialPort.java:181) at com.apiciolabs.easycash.ControlApplication.onCreate(ControlApplication.java:192) at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:326) at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325) at android.app.ActivityThread.access$1400(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1457) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4998) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:811) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:627) at dalvik.system.NativeStart.main(Native Method)

in data/data/com.apiciolabs.easycash/cache/1463764816989-libjSerialComm.so is 0 byte. I can't understand what is wrong . Can you help me please?
Best regards

jSerialComm on Android

Hello.
I'm trying to use this library in an Android application project, but I've noticed that the *.so library files aren't actually included in the .apk that is generated by Android Studio. So the application crashes when trying to use the library. Can you suggest any solution?

Edit: solved this with a workaround. I had to manually include the libs in the jniLibs folder and edit the path in the SerialPort source code, as follows
libraryPath = (line.indexOf(',') == -1) ? "lib/" + line.substring(line.indexOf('=')+1) : "Android/" + line.substring(line.indexOf('=')+1, line.indexOf(','));

Open arbitrary port

Hi,
thank you for your work. I really enjoy using your library as a replacement for rxtx.
Would it be possible to open an arbitrary port, in case the library does not find it.
I am using a Keyspan High-Speed USB to Serial Adapter and cannot find the ports.
I would like to set the path to the ports manually.
Regards,
Frederik

Sleep timers can cause poor performance

There are quite a few Thread.sleep() calls in the library, most without much in the way of explanation but these can seriously hamper performance if the user isn't aware.

For instance, there is a 200ms delay every time any setting is changed on an open connection, a 500ms on every port.open() call.

The settings ones we can work around (make sure everything is set before the port is opened) but the open() we can't.

Write doesn't work on Rs422

Hi,

I have tried to use the lib for replacing RxTx (this lib is a mess unmaintained for almost a decade now...) but i got the same issue has jssc, i can read data on port Rs422 but i can't write on it, even if the lib doesn't send back any error... The port work with 4 wires (2 rx, 2 tx (1 Negative, 1 positive)), and for writing while reading i know we must keep the RTS to 1. It's almost all i know about this kind of port...

PS: I use loopback (Tx linked to Rx) wire for debugging so i'm sure that the data doesn't come out of the port.

Here some description of the wire.
Tx+ 2 Rx+ 3
Rx+ 3 Tx+ 2
Tx- 1 Rx- 4
Rx- 4 Rx+ 1
GND 5 GND 5

NOT a bug: setComPortTimeouts()

On Linux and Mac OS the timeout is rounded to the nearest 1/10th of a second.
Because of this, if you call setComPortTimeouts() with a timeout of, say, 10, it will be rounded to zero, causing calls to block forever.

This works as documented, but maybe it woud be better to force the timeout to 100 when setComPortTimeouts() is passed a value greater than 0 (and less than 150), to avoid the round-to-zero trap. This looks closer to the, I guess, to the intended behavior when you pass a small number, meaning the smallest possible timeout, not an infinite one ;)

SerialPort.getCommPort not working on OSX

If I do: SerialPort comPort = serialPorts[0];, I get a working object. If I do SerialPort comPort = SerialPort.getCommPort(serialPorts[0].getDescriptivePortName());, it doesn't work.

If I printout the result of serialPorts[0].getDescriptivePortName(), I get: FT232R USB UART.

Any ideas?

Sometimes serial port cannot be opened (VMware)

First of all: good work! Thank you!

The issue: The opening of the serial port sometimes fails (in about 50% of the cases). The port is listed correctly with SerialPort.getCommPorts() and a simple retry may open the port after a few times. For me this looks like a timeout or something like this... (it takes about 1 second or so for open() to return with false). Once the port is opened everything runs fine.

I tried other applications (the Arduino IDE), which can open the port in 100% of the cases. For me this looks like a timeout or something like this... (it takes about 1 second or so for open() to return with false). Once the port is opened everything runs fine.

The OS is Ubuntu 14.04.1 running in a VMware VirtualMachine with a USB serial port adapter attached (QinHeng USB-2.0 Serial device). I'm using jSerialComm v1.3.7

It also would be great if an error code could be provided in case that the port cannot be opened.

RaspberryPi support

Hello!
jSerialComm was told to be running on ARM based platforms. Now, as I try to run it on RapberryPi (Raspbian), I've get an error message:
java.lang.UnsatisfiedLinkError: /tmp/tomcat7-tomcat7-tmp/libjSerialComm.so: /tmp/tomcat7-tomcat7-tmp/libjSerialComm.so: cannot open shared object file: No such file or directory (Possible cause: can't load IA 32-bit .so on a ARM-bit platform)

Can you please compile a version supporting Linux ARM for raspberry pi?!
Thx!

Allow Mac OS X call-in port selection

When using this library under Mac OS X, only the callout (/dev/cu.) serial port is enumerated. While this is the desired port for most users, there may be times when the user wants to open a port that blocks while awaiting incoming serial connections. On a Mac, this port is identified by /dev/tty.. Enable enumeration of these call-in ports and specify that they are only for "incoming" serial connections.

jSerialComm with Java applet

Hello everyone,
I 'm currently building a web application that requires a serial port communication, does jSerialComm work in a signed Java applet ?
if you have any idea...
thank you in advance for any response

T.Vilin

Support for 9 bit serial

Does jSerialComm support 9 bit serial if the hardware and driver supports it? (9600N91)
If yes, how does one use it? Besides setNumDatabits(9)...

Method to check if a SerialPort is open

It would be handy if SerialPort had a isOpen() method that just returns whether the port is currently open or not.

In my case, I want to check if a port is open, and open it if it isn't. The openPort() method does this and won't attempt to open the port again if it is already open, but

  1. the Javadoc does not explicitly say it's safe to call openPort() on a port that's already open, so I consider that to be undocumented behavior
  2. openPort() always sleeps for 0.5 seconds (or 1 second if running on Android) even if the port is already open, which makes it expensive to call that method

Feature request: event for lost connections (e.g. USB UART gets unplugged)

Hi,
It looks like there is no way to get an event for when a connection is dropped. As far as I can tell, the only way to know is if you transmit something and the number of transmitted bytes is incorrect.

I know for a traditional serial port (not a USB or Bluetooth adapter) there is no practical way to know if the cable is unplugged, but since most people use USB or Bluetooth adapters these days, I assume the OS presents a way to check for a lost connection?

Thanks,
Farrell

Feature request: Ability to get detailed device name

Hi,

With an FTDI adapter it is possible to set a "Product Description" string, and this string can be used to give the adapter a more descriptive name than the generic "USB Serial Port" name. I believe this feature is not specific to FTDI either, since I have other USB UART devices that do not use FTDI chips, and that have descriptive names shown in Windows. At least with Windows 10, the OS seems to be able to show this name so I'm guessing it's also exposed through the OS is some way. It would be nice if we could get this Product Description string since finding the right COM port can be a hassle on a system with many adapters.

Neither the getDescriptivePortName() nor getSystemPortName() methods return this string.

I have attached a screenshot. The Devices screen of the Windows 10 Settings App shows the string, as does the FTDI FT Prog program (which I used to assign the string.) This "Pink USB DB9 Adapter (FT232R)" happens to be COM9 on my system, but I have no way to associate the COM9 port with that string when using the jSerialComm library.

Thanks,
Farrell

jserialcomm_feature_request

OpenPort doesnt sleep in Java Aplication

Everytime i want to Open a port in a Java Aplication without gui, it doesnt sleep and some write actions after OpenPort doesnt work. I Have to sleep the Thread manually.

Example:
serial.openPort("COM3", 38400);
serial.write("Hi"); // write doesn't work

serial.openPort("COM3", 38400);
System.sleep("2000");
serial.write("Hi"); // write work flawessly

But, if i put de OpenPort code in a Swing button it sleeps and everything works.

I'm working with NetBeans Windows 10 64bits.

BTW Great work!! =D

PD: Sorry for my english, I'm from Chile

Timeout value sanity/error checks on Linux

The code that configures timeouts in the Linux implementation could use some additional checks.

  1. The Linux implementation only supports decisecond granularity, but the native code just blindly does timeout / 100. I had the timeout set to 50 and got non-blocking behavior because 50 / 100 = 0 with integer division. It would be good to verify that the timeout is a multiple of 100, and throw an exception or log a warning if it isn't.

  2. While I was trying to figure out the above, I looked at the man page for tcsetattr. The return value section states: "Note that tcsetattr() returns success if any of the requested changes could be successfully carried out. Therefore, when making multiple changes it may be necessary to follow this call with a further call to tcgetattr() to check that all changes have been performed successfully." The man page doesn't clarify what counts as a change, so I'm not sure if the whole c_cc field counts as one change or if each element of c_cc is a separate change. If the latter, it would be possible for the native code to return success even if only one of VMIN or VTIME was applied, since it only checks the return value.

  3. I didn't see the decisecond granularity limitation documented anywhere. Also, from looking at the native code, it appears write timeouts aren't applied at all on Linux. It would be nice if these OS-specific issues were documented somewhere.

Check if port open before write

Hi,

Thanks for that great work, I am new to serial communication and your project is very helpful.
Could you add some validation if port is not opened before writing.

Thanks

MSB missing

Dear Team,

Thanks for great work on JSerialComm. I use it as a multi platform solution to support home automation systems like KNX. This works great on Windows for plain TPUART and BCU connections.

It also works works basically on opensuse 13.2, but after a few data packages I miss for some reason the MSB for all bytes. It doesn't matter if I read integer with is.read() or bytes using is.read(byte[]). I build the binary for 1.1.1 on opensuse 13.2 and used pre build binaries from 1.0.1, 1.11. and 1.2.0 but this did not solve the problem.

It would be really great if you could help to make this work.

Best Regards
Dirk

Change/Retrieve states of control signals

Hi,
I thought of another feature which could be helpful. Do you think it would be possible to change the state of the control signals (DSR, DTR, ...) and/or be notified if one of their states changes?
This would be helpful to emulate a serial device and do some testing.

OSGi Support

It would be helpful if this library can be packaged as an OSGi bundle so that it can be made available in lots of Open Source OSGi based IoT frameworks.

Receive unknown data from atmega8 proteus

Hello,

I received an unknown character which the codes can't convert into integer. Therefore I cannot draw the line graph. How can I resolve this?

Here is the error:
Exception in thread "Thread-2" java.lang.NumberFormatException: For input string: "��"

Thank You in advance.

Significant rise of used RAM at periodic reopen of serial port

Hi everyone,
at first I would like to compliment you for your nice library. Good documentation, examples, platform support, ...
At moment I am performing some tests to get a deeper insight of the functions. At one of these tests I found that a period reopen (about hundreds times) of the same serial port (ttyUSB0) results in an significant rise of used RAM. No writing or reading was done at all, only opening serial port, input and output streams and closing them again at a reopen cycle.
When I started my test application it used approximately 29.5 MB RAM.
After some time (27 minutes later) it used approximately 56.5 MB RAM.
And after some more time (16 hours later) it used approximately 78.6 MB RAM.

Here my setup:
jSerialComm-1.3.8.jar
OS: x86_64 GNU/Linux; Kernel: 3.19.8
GNU C Library 2.21
jre1.8.0_60

What could be the reason for that rise of used RAM?

Thanks in advance for any response
Michael K.

Line speed setup on Linux

Hi!
I had trouble reading data from a USB attached APM2.5 autopilot board in my x86_64 Linux. This device shows up as /dev/ttyACM0 and works at 115200bps with 8N1, RTS/CTS settings with other software but not jSerialComm. My Java code was pretty straightforward so I started to investigate jSerialComm source code. Turned out setting a custom baud rate doesn't work in my case. Changing the speed setup code to use cfsetispeed() and cfsetospeed() with B115200 did the trick for me, maybe others had similar issue.

regards,
Benamin Budai

Time gaps between readings

Hi,
I'm using this library for reading data from sensor ,
I'm using the inputStream.read()
to get the data from the port.
On getting the data I store it with timestamp in a blockingQueue since there is other thread that dumps the data from the queue to a log file.

I noticed that every ~650mSec there is a delay, meaning when I later plot the data vs timestamp, its not evenly distributed .

I tried several solutions according to the wiki without success.
I attached the plot...

Any suggestion?

Regards,
IssakD

image

Allow use of pseudo-terminals

I would like to test my code using pseudo-terminals setup using socat -d -d pty,raw,echo=0 pty,raw,echo=0. This creates two pseudo-terminals at /dev/pts/14 and /dev/pts/15 which I can then use like so:

cat < /dev/pts/14
echo "test" | /dev/pts15

Unfortunately jSerialcomm only allows me to connect to ports in /dev/ and not in /dev/pts/.

Is it possible to allow me to connect to pseudo terminals? I don't know much about serial connections / pseduo-terminals so there may be some reason for this, if so could you recommend an alternative way to test my application when I don't have the serial device connected to the computer I'm working on.

Cheers

Closing port not returning on Windows

When I try to close the port on Windows, the call never returns. I do the following:
Open the port, add a DataListener, remove the DataListener and close the port.
It doesn't matter if I remove the DataListener or not, because closing the port and removing the DataListener do basically the same thing.
I think the whole thing hangs when you call Thread.join() when removing the DataListener.

Problem to read serial COM

Hi,

i'm implementi a binding to implement my domotic system in openhab, that talk by serial COM port.
Now, i integrate jSerialComm in mt plugin project and when i implement the following code:

SerialPort seriallPorts[] = SerialPort.getCommPorts();
for (SerialPort serialPort : seriallPorts) {
System.out.println(serialPort.getSystemPortName());
}

the system stay blocked in the first line, withouth give any error. I try the sibrary in a common java
project, and the library work fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.