Giter VIP home page Giter VIP logo

Comments (10)

kattni avatar kattni commented on June 30, 2024

Seems like having both options could be good. Universally usable code is brilliant, but the option to do it like it's done now also super handy. I don't know if this creates more overhead in the long run though. Having the option to specify UART pins feels like something people will inevitably want.

from adafruit_blinka.

ladyada avatar ladyada commented on June 30, 2024

the thing that will bite people with RX/TX is that you need to map that to the UART name-path ... and that changes sometimes when OS's change :/

from adafruit_blinka.

tannewt avatar tannewt commented on June 30, 2024

We chatted about this earlier and decided to try passing in a Serial object from pyserial instead of adding a busio.UART. The drivers will hopefully just work with it.

from adafruit_blinka.

ladyada avatar ladyada commented on June 30, 2024

@kattni wanna take a look at both our UART and the official 'pyserial' api, see if it matches up? we'll of course try with real code but take a glance! :)

from adafruit_blinka.

kattni avatar kattni commented on June 30, 2024

As long as the options work the same, pyserial does everything our UART does. pyserial does way more than our UART does but all the same options are there. Sounds worth testing!

from adafruit_blinka.

ladyada avatar ladyada commented on June 30, 2024

well, the API is the same, but encoding is Fun - here's the diff i had to make to adafruit_gps, string literals needed a b' prefix. variables needed a bytes(var, encoding="UTF-8")

beyond this it 'just worked' tho

 adafruit_gps.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/adafruit_gps.py b/adafruit_gps.py
index 66d0eee..3086840 100644
--- a/adafruit_gps.py
+++ b/adafruit_gps.py
@@ -115,15 +115,15 @@ class GPS:
         Note you should NOT add the leading $ and trailing * to the command
         as they will automatically be added!
         """
-        self._uart.write('$')
-        self._uart.write(command)
+        self._uart.write(b'$')
+        self._uart.write(bytes(command, encoding="UTF-8"))
         if add_checksum:
             checksum = 0
             for char in command:
                 checksum ^= ord(char)
-            self._uart.write('*')
-            self._uart.write('{:02x}'.format(checksum).upper())
-        self._uart.write('\r\n')
+            self._uart.write(b'*')
+            self._uart.write(bytes('{:02x}'.format(checksum).upper(), encoding="UTF-8"))
+        self._uart.write(b'\r\n')
 
     @property
     def has_fix(self):

from adafruit_blinka.

ladyada avatar ladyada commented on June 30, 2024

circuitpython does not seem to support bytes w/encoding (brennen tried this for me)

@tannewt any ideas?

>>> bytes("Hello world", encoding="UTF-8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: wrong number of arguments

from adafruit_blinka.

tannewt avatar tannewt commented on June 30, 2024

For the record, I think "Hello world".encode("UTF-8") should work. This is risky however because you actually want ascii bytes instead of encoded unicode. So, I recommend using b"Hello world" instead.

from adafruit_blinka.

ladyada avatar ladyada commented on June 30, 2024

ok we resolved this over hipchat, we'll use b' as much as possible and then .encode() when we can't

from adafruit_blinka.

ladyada avatar ladyada commented on June 30, 2024

turns out encode() doesnt work in CircuitPython. the correct universal technique is

bytes("hello world", "utf-8")

going thru libraries now, no changes needed to underlying circuitpython busio device but might be good to restrict circuitpython busio.uart to bytes only, rather than letting strings slide thru (in 4.0?) - lemme know if you agree and i can open an issue

from adafruit_blinka.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.