crayzeewulf / libserial

Serial Port Programming in C++
BSD 3-Clause "New" or "Revised" License
398 stars 141 forks source link

Added try/catch cases for catching ReadTimeout exceptions to examples #95

Closed mcsauder closed 6 years ago

mcsauder commented 6 years ago

This PR just adds try/catch statements to the example code.

Let me know if you have any questions!

-Mark

wade-fs commented 6 years ago

No. In the SerialPort::Read() implementation code.... must be do { .. } while(); not the original while () { ... } Please look at my patch.

mcsauder commented 6 years ago

Hi @wade-fs ,

Could you help me localize this issue between the master branch and the c++14 branch? Could you tell me if the problem exists in both the master and the c++14 branches? I'm not quite understanding how changing the while() loop to a do(){...} while() loop is fixing the issue.

Thank you for helping me localize and understand what you are seeing.

-Mark

mcsauder commented 6 years ago

Hi @wade-fs ,

Also, there is a known issue with the master branch in threaded applications. The master branch will not function as expected in a threaded application. If you are using the master branch in a threaded application could you try the c++14 branch and let us know if that resolves the issue? Thank you for your work on this!

-Mark

wade-fs commented 6 years ago

Just for Timeout issue for c++14 branch: Please apply the patch. And, I am not using multi-threading....so...

Patch-SerialPort.txt

crayzeewulf commented 6 years ago

@wade-fs Please see this comment.

wade-fs commented 6 years ago

I don't think so.

If numberOfBytes is zero, then this method will keep reading data till no more data is available at the serial port.

Keep reading data : It must wait for data coming, and then....read till no more data is available...

Best Regards

自由的精靈, 狂想的空間 Free Spirit, Fantasy Space

On Fri, Dec 1, 2017 at 2:57 PM, CrayzeeWulf notifications@github.com wrote:

@wade-fs https://github.com/wade-fs I believe that the implemented behavior is intentional and matches the documentation. As the documentation says:

If numberOfBytes is zero, then this method will keep reading data till no more data is available at the serial port.

The intention is to return all currently available data when numberOfBytes is set to 0. If no data is available then it should return immediately and dataBuffer should be empty.

Hope this makes sense. If not, please give us an example of how you are intending to use this method and what you expect it to do. Maybe there is another way to achieve the affect you want.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/crayzeewulf/libserial/pull/95#issuecomment-348417089, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGglTOwhJWnIMG220ZqYCQTycYs2ubkks5s76NogaJpZM4Qx3B9 .

crayzeewulf commented 6 years ago

How about we move/continue the discussion to #93 where you posted the original patch so all comments stay in once place. Sound good?

mcsauder commented 6 years ago

Perfect! And thanks for helping us put down breadcrumbs for future readers!

Thanks again!

-Mark