-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvements to interface, testing, and examples #61
Conversation
… SerialPort.is_open. Remove Base function name qualifications now that they are imported.
…h is unused and completely redundant with open.
… except for byte reading. Use new nonblocking_read name for old behavior.
I know @ianshmean had some particular use cases that were causing him trouble, perhaps it's worthwhile seeing if he has time to comment? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I hadn't realized that a conversion from the enum type SPResult
returned by handle_error to Int
is needed. Can we not do this in the first line of function handle_error
, by changing that to ret >= SP_OK && return Int(ret)
? (Or have multiple versions of handle_error
, one of which returns an Int
and one of which returns nothing
?) It would be nice to have most wrapper functions consist of just a single line, and move all the return-value processing functionality required into (a version of) handle_error()
. Then commit fb64277 would become unnecessary: whatever the handle_error() call in the last line of the wrapper function returns also becomes the return value of the wrapper function.
Overall the PR looks like a big step in the right direction, thanks! Note that I just use a USB serial adapter with its RX and TX wires directly connected with each other, so just a hardware loopback wire and no Arduino board involved. I suspect that is why the tests still fail for me:
It would be nice if the tests could also be made to work with such a very basic “loopback” wire. At least, Idea: In the absence of a port parameter, |
…no or a USB-to-UART adapter in loopback mode.
Ok, thanks, the tests now work also for a simple loop-back wire, except that I still need to uncomment the switches to 6-bit frames as mentioned in #55. |
…h any loopback device
… originally thought they did.
I think I have addressed all review comments received so far. I still haven't implemented anything sophisticated with read timeouts, but I'm not convinced that we need to do anything more than set All the examples and tests work for me with three different hardware configurations (which are listed atop runtests.jl). This is unfortunately a fairly big change set. It would not be simple to split up. In the end, some of the biggest problems were in the tests more than the library code under test. I have not done any Windows testing, so it would be great if anyone could easily do that. |
Hello, I was just about to open a PR for an extra
What's the proposed alternative for getting the same functionality after the changes made in this PR? Will the user need to roll their own alternative to the Base extension methods of |
Since LibSerialPort.SerialPort is an IO subtype, the readuntil method is provided by Julia's base module (see here). You should just be able to call e.g. |
I miss the function |
The solution to users not understanding that standard methods for the |
In
If
The loopback tests should only be run by
|
(Apologies for the late response, I'm back now!) When I run the tests on Ubuntu 18.04, I get many (shortened output)
When doing binary tests that include the bytes 0x11 (Ctrl-Q, XON) and 0x13 (Ctrl-S, XOFF), XON/XOFF flow control obviously must be switched off first. The documentation string for
Could you please explicitly switch off flow control, at least in the tests? It might even be a good idea to make flow-control a default-off parameter of |
Can I make a PR for this branch ama/fix-read-methods ? Based on branch ama/fix-read-methods and master branch, I make a new |
What is wrong with the existing readuntil method? It works fine in my tests. |
@touchft What is wrong with the existing implementation of Base.readuntil, which is already working for If this is about timeouts: we are going to implement timeouts in read() and unsafe_read() via an exception and a new timeout parameter inside the |
Nothing wrong. Three things I consider for the change are: Maybe I am too greedy ^-^ Code is here:
|
The existing
So no need to “reinvent the wheel” inside this package's high-level API, which is essentially just the serial-port driver for the
That sounds like a perfectly reasonable pull request for base/io.jl, as there is nothing specific to this feature request for The only other feature of your routine, the timeout, we will be doing in a way that works fine with all the many different readuntil methods in Base. |
Great! I think I miss checking the master branch of LibSerialPort.jl (I checked the Julia repo and branch ama/fix-read-method ). I found that one useful blocking read method is missing in the master and ama/fix-read-method branch, i.e, "readavailable(::SerialPort)". [In branch: ama/fix-read-method]: [in branch master]: |
…ow-control setting in tests) (#74) * fix test_low_level_api() by actually disabling flow control This test routine claimed in a comment to disable flow control. It actually requires the serial port to be transparent for all 256 byte values, which in turn requires deactivation of software flow control, because otherwise the byte-transparency tests fail for bytes 0x11 (Ctrl-Q, XON) and 0x13 (Ctrl-S, XOFF) on systems such as Ubuntu Linux where software flow control is active by default. * completed read/write timeout implementation in high-level API Added new functions to set and clear cumulative timeouts for blocking read and write functions, a new `Timeout` exception that will be thrown, and time-tracking code in calls to the blocking read/write functions. This way, users can now set overall timeouts on other IO functions, such as `readuntil`, that make multiple calls to our blocking functions. * change close(::SerialPort) to return nothing That what other close(::IO) methods in Base do. It looks quite odd in the REPL to get the entire closed SerialPort object thrown back at you. * build HTML documentation using Documenter.jl also polished some docstrings and fixed a parameter name inconsistency * split low-level API into separate module (#68) The low-level API wrappers now sit in a submodule LibSerialPort.Lib. The high-level API currently still re-exports a few symbols from that low-level API module, to preserve backwards compatibility. This is due to * my previously started attempt to merge the low and high-level APIs for the three functions sp_flush, sp_drain, and sp_output_waiting * the fact that several high-level APIs currently still refer to enum types and constants defined by the low-level API We may want to phase out either or both in future, for a cleaner separation, and a more Julian high-level API. * documentation typo fixed * allow arm64 to fail Arm64 builds have long filed, therefore let's allow them to fail in Travis until that problem is fixed, such that PR authors for other issues do not get build errors that they are not responsible for.
This PR is intended to follow up on work done by @mgkuhn in #56. The scope has grown from a focus on read methods to a package-wide overhaul.
read
methods defined in high-level-api.jl were mostly removed, allowing io.jl in the Julia Base module to do its job. See avoid duplicating read functions from base/io.jl #58.read_timeout_ms
field was added to the SerialPort type.write
in Fixes for issues #50, #53, #54 #56, theread
method now calls intosp_blocking_read
instead of the nonblocking version.nonblocking_read
function. This is likely a breaking change.@test
.readline()
example in README.md does not work #52).I still haven't fully worked out the timeout logic for the blocking read methods. @mgkuhn provided valuable suggestions in #58, which I have partially implemented. All tests and examples now work on my computer (macOS Catalina) with an Arduino Uno running serial_example.ino.