You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
_writeBytes just returns true/false on success/failure without any further details. But write() would provide (potentially useful) error details (For example see a list at its man page).
Further, SerialPort.writeBytes just communicates errors by returning false. This has potential to fool java developers. As they're used to get exceptions thrown if someting is wrong. Java code, checking for returned success/failure codes is something I see seldom. I even found exactly this mistake in our projects codebase which is using jssc. This is not meant to blame java devs. It's just when writing java, one easily overlooks this as one is used to exceptions and does not expect a method where the return value suddenly should be checked (in contrast of all other methods around id).
Expected Behavior
IMHO we should provide more error details to our caller. I see multiple ways to do so. Eg we could throw java exceptions (for example from SerialPort class but also from native code would be possible). Or returning numerical codes, Or providing some kind of getError() method (not very nice, but better than nothing) alongside with the returned boolean where caller can retrieve an error message. Or ... whatever.
Activity
Make 'write()' return number of bytes written
hiddenalpha commentedon Apr 26, 2023
Relates to #136 and #138 (in perspective of missing errorhandling)
hiddenalpha commentedon Dec 13, 2023
Fixed through #146 and #152.