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
Change a UART instance's timeout #3434
Comments
I think you need to call uart.init() again with the new timeout value. This type of question is best posted in the forum. |
Thank you @peterhinch. I must admit, I didn't pose this as a question because I think it's more intuitive to be able to change the timeout as I've described There are a few reasons for this:
So it seems this is an improvement suggestion, not a bug, but still a legitimate issue. |
An alternative to having a separate |
@dpgeorge I agree that's an alternative, but it doesn't solve the ambiguity of user code. class UART:
@property
def timeout(self):
return self._timeout
@timeout.setter
def timeout(self, value):
self.init(timeout=value) |
What do you mean by this? Can you give an example of such code?
The thing with properties is that they are more expensive (in code space) than adding keyword arguments to a method like Alternatively, since a UART is like a stream, it could make sense to add |
I just mean that, for someone not familiar with this discussion, the following: uart.timeout = 0.2
uart.init(timeout=0.2) may be functionally different:
I understand that the 2 lines could be functionally the same, but it's not clear until you read the documentation.
Yep! That's a big 👍 from me. |
That would be my choice. |
It may be less obvious, but having extra methods is also expensive - each method adds quite a bunch of boilerplate beyond the code which actually does something useful. So, reading docs/adding code comments is imperative. |
At first I thought that would be nice, but then there would be not default parameters any more in the init() call, or the instantiation of a uart object. So keeping it like it is may be the better option. |
Another approach would be to have 2 functions. One like .init() which assumes that it's initializing everything and arguments have default values which are reasonable. The second would be something like .set_parameter() and would take all of the same keyword arguments as init but it would only act on the ones which were actually provided. .init() could call .set_parameter. This still doesn't cover retrieving values, but I thought I'd throw it out as an idea. |
We also use properties a lot more freely, though we don't provide access to everything that way. (We trade being Pythonic against performance; I understand why you've gone the other way.)
|
And indeed, listing specific default param values is the root of problem. Instead of being documented as
as
That would make it clear what's meant by the calls
MicroPython already has solution for setting and querying arbitrary params on an object: http://docs.micropython.org/en/latest/library/network.html?highlight=network#network.AbstractNIC.config , readily applicable to |
Changing a UART's
timeout
behaviour would be fantastic.However, changing the timeout isn't supported (yet 😉)
The text was updated successfully, but these errors were encountered: