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?
When/why did UART.send become UART.write?
Re: When/why did UART.send become UART.write?
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)
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)
Re: When/why did UART.send become UART.write?
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).
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/
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/