HirdayGupta / Java-Arduino-Communication-Library

Serial Communication between JAVA and Arduino made easy. Source code and importable JARs available in this repo.
https://sourceforge.net/projects/javaarduinolibrary/
43 stars 18 forks source link

Cannot serialRead in threads #12

Open yousefamar opened 4 years ago

yousefamar commented 4 years ago

Hi, love the library! I came across an issue and just wanted to mention it here for posterity in case someone comes across the same. serialRead only works properly in the main thread and otherwise returns empty strings.

yousefamar commented 4 years ago

I solved this by simply using jSerialComm directly: https://github.com/Fazecast/jSerialComm/wiki/Event-Based-Reading-Usage-Example

HirdayGupta commented 4 years ago

Hey @yousefamar, glad you're enjoying the library and thanks for flagging this!

I had not developed this with thread-safety in mind. I'm glad you were able to figure it out by using the underlying jSerialComm library. I'll leave this issue open so that people with this problem can see what you did.

If I get some time in the upcoming months, I can work on adding thread safety to this library.

HirdayGupta commented 4 years ago

Also, I am definitely accepting pull requests to this repo, so if you can find a way to take your approach from the jSerialComm guide and weave it into this library - i'd be more than happy to help with and support such an effort! @yousefamar