Java-Arduino-Communication-Library icon indicating copy to clipboard operation
Java-Arduino-Communication-Library copied to clipboard

Cannot serialRead in threads

Open yousefamar opened this issue 6 years ago • 3 comments

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 avatar Mar 03 '20 19:03 yousefamar

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

yousefamar avatar Mar 04 '20 14:03 yousefamar

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 avatar Mar 05 '20 06:03 HirdayGupta

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

HirdayGupta avatar Mar 05 '20 06:03 HirdayGupta