When/why did UART.send become UART.write?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
sw_dev
Posts: 7
Joined: Wed Nov 19, 2014 9:27 pm

When/why did UART.send become UART.write?

Post by sw_dev » Mon Feb 16, 2015 11:42 pm

Was having some trouble sending data to an lcd today because of the AttributeError: 'UART' object has no attribute 'send'. Thinking that I'd screwed something up, it took me a long while to finally think to check a dir of the object I'd created:

>>> import pyb
>>> from pyb import UART
>>> lcd = UART(6,9600)
>>> lcd.send('ready')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'UART' object has no attribute 'send'
>>> dir(lcd)
['init', 'deinit', 'any', 'read', 'readall', 'readline', 'readinto', 'write', 'writechar', 'readchar', 'sendbreak', 'RTS', 'CTS']
>>> lcd.write('test')
4

As you can see, it truly has no "send' attribute, and now (Mysteriously) has a "write" attribute. But the UART docs still say that 'send' exists, and works. What's up with this?

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: When/why did UART.send become UART.write?

Post by kfricke » Tue Feb 17, 2015 11:34 am

Starting with version 1.3.4 (Oct 21 2014) the UART interface did change and the current documentation only tells this since then.

The reason is, as far as i did understand, to make it work in asynchronous environments. It also implements an interface similar to other file-like serial communication modules (like CPythons pySerial)

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: When/why did UART.send become UART.write?

Post by pfalcon » Wed Feb 18, 2015 9:29 pm

Are you sure you look at the right docs? https://docs.micropython.org/en/latest/ ... .UART.html says that there're read()/write() methods, but indeed mentioned that in some very old by now version there were send()/recv().

The reason for the change should be obvious: now UART object complies with stream ("file-like") Python interface and can be just used as any other data source/sink.

MicroPython is in active development, and one may expect further changes too, and as it is *Micro*, it doesn't make sense to accumulate "deprecated" stuff, as it will take up all space. This might seem not ideal, but you can be sure that the changes made only to make things more clear/general and more "Pythonic". Otherwise, checking current docs and using dir() should be everyone's best friend (just the same as with "big" Python).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply