Page 1 of 1

How to manipulate a datastream between UART and uos.dupterm

Posted: Sun Mar 22, 2020 2:08 pm
by drs
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)

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

Posted: Mon Mar 23, 2020 12:07 am
by jimmo
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).

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

Posted: Thu Mar 26, 2020 5:48 am
by drs
Its Working :D
Thanks a lot Jimmo !!!

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