How to manipulate a datastream between UART and uos.dupterm

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
drs
Posts: 2
Joined: Sun Mar 22, 2020 1:39 pm

How to manipulate a datastream between UART and uos.dupterm

Post by drs » Sun Mar 22, 2020 2:08 pm

A big Hello and thanks to all of the forum members and admin for doing such a great work!

I have a big dot matrix lcd monitor, i can only send ascii characters via serial to it.
Therefore i need to change the datastream of the REPL to display it right.

I use a NUCLEOF401RE board.

The piece of code is my approach, and its not working, the error i got is:
"ampy.pyboard.PyboardError: ('exception', '', 'Traceback (most recent call last):\r\n File "<stdin>", line 43, in <module>\r\nOSError: stream operation not supported\r\n')"

I read the docs about dupterm, and thought this could work: https://docs.micropython.org/en/latest/ ... os.dupterm

Is it the wrong STREAM class or what am i doing wrong ?


thanks in advance, drs

Code: Select all

from pyb import UART
from time import sleep
import time, uos, uio

uart = UART(6, 19200)

class QC(uio.IOBase):
  def write(self, buf):
    print('write', repr(buf))
    return len(buf)
    
  def ioctl(self):
    return None
    
  def read(self, nbytes):
    if uart.any():
      return uard.read(nbytes)
    else:
      return('None')
      
  def readinto(self, buf):
    if uart.any():
      for i in length(buf):
        if uart.any():
          buf[i] = uard.read()
        else:
          return buf
    else:
      return(None)
    print('readint', repr(buf))


uos.dupterm(QC)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: How to manipulate a datastream between UART and uos.dupterm

Post by jimmo » Mon Mar 23, 2020 12:07 am

The last line -- "uos.dupterm(QC)" should be "uos.dupterm(QC())" (you need to create an instance of the QC class).

It's generally a good idea to pass the "slot index" to dupterm too. (There's three slots, you manage them independently. Slot 1 is by default the USB VCP if enabled. If you don't specify an index, you use slot 0).

drs
Posts: 2
Joined: Sun Mar 22, 2020 1:39 pm

Re: How to manipulate a datastream between UART and uos.dupterm

Post by drs » Thu Mar 26, 2020 5:48 am

Its Working :D
Thanks a lot Jimmo !!!

And thx for the slotIndex info, i was scratching my head about that too.

Post Reply