NotImplementedError uart.any()

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
eduardo
Posts: 31
Joined: Mon Jan 05, 2015 6:48 pm

NotImplementedError uart.any()

Post by eduardo » Wed Jan 14, 2015 9:02 pm

>>> uart.any()
False
>>> if uart.any==False:
... print("FALSCH")
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NotImplementedError: equality for 'bound_method' and 'bool' types not yet implemented
>>>

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: NotImplementedError uart.any()

Post by Turbinenreiter » Wed Jan 14, 2015 9:11 pm

You forget the braces after any.

This should work.

Code: Select all

if uart.any()==False:

eduardo
Posts: 31
Joined: Mon Jan 05, 2015 6:48 pm

uart.readline()

Post by eduardo » Wed Jan 14, 2015 9:55 pm

I got the following problem:

I can send commands to the modem, and get answers back.
But the answer is in a "binary" format like b´text´

How can I convert it to normal text without the CR and other formating characters?

thank you

>>> uart.write("at\r\r\n")
5
>>> while uart.any()==True:
... uart.readall()
...
b'\r\nOK\r\n'
>>>

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: NotImplementedError uart.any()

Post by Damien » Wed Jan 14, 2015 10:15 pm

Yes, looks like you missed the parenthesis! But now the bug comparing bound_method to bool is fixed as well.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: uart.readline()

Post by Damien » Wed Jan 14, 2015 10:20 pm

eduardo wrote:I got the following problem:

I can send commands to the modem, and get answers back.
But the answer is in a "binary" format like b´text´

How can I convert it to normal text without the CR and other formating characters?

thank you

>>> uart.write("at\r\r\n")
5
>>> while uart.any()==True:
... uart.readall()
...
b'\r\nOK\r\n'
>>>
First, note that (if you haven't already) you probably want to init the UART with an inter-char timeout, like:

Code: Select all

uart = pyb.UART(1, 9600, timeout_char=1)
This will make sure that when you read it waits a little between chars, giving you a longer string than just 1 character.

To get rid of the newlines, use the .strip() method: text.strip()

To convert to a string, do: str(b'123', 'utf8')

These are all normal Python programming techniques.

Post Reply