Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Disable REPL to use usb as serial pipe
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Disable REPL to use usb as serial pipe

by bluthen on Wed Apr 01, 2020 9:15 pm

Loving Circuitpython so far. How do you disable REPL so you can use stdin as a serial pipe from a host computer that is connected with a USB cable?

I understand there is supervisor.runtime.serial_bytes_available But the first time the host sends a character it goes into REPL.

I was hoping to do something like this:

Code: Select all | TOGGLE FULL SIZE
def read_cmd():
    s = ""
    found_at = False
    start = time.time()
    while time.time() - start < .1:
        avail = supervisor.runtime.serial_bytes_available()
        if avail > 0:
            s += sys.stdin.read(avail)
            start = time.time()
        if not found_at:
            idx = s.find('@')
            if idx >= 0:
                s = s[idx:]
                found_at = True
        if found_at:
            idx = s.find('!')
            if idx >= 0:
                s = s[:idx + 1]
                return s
        time.sleep(0.01)
    return ''


while True:
    if supervisor.runtime.serial_bytes_available:
        cmd = read_cmd()
        if cmd == ...
        ...
    ...
    ... Other code ...


Thanks!

bluthen
 
Posts: 3
Joined: Wed Apr 01, 2020 9:10 pm

Re: Disable REPL to use usb as serial pipe

by bluthen on Wed Apr 01, 2020 9:32 pm

I feel silly, it was because it was erroring out. I needed to use time.monotonic() instead of time.time().

This is very cool!

bluthen
 
Posts: 3
Joined: Wed Apr 01, 2020 9:10 pm

Re: Disable REPL to use usb as serial pipe

by tannewt on Thu Apr 02, 2020 1:51 pm

Beware that using the serial link will work fine for all binary values except control sequences such as ctrl-c. Much more background on improving how this works is here: https://github.com/adafruit/circuitpython/issues/231

Glad you made progress!

tannewt
 
Posts: 1852
Joined: Thu Oct 06, 2016 8:48 pm

Re: Disable REPL to use usb as serial pipe

by makenbake on Sat Jul 18, 2020 8:16 pm

I'm trying to achieve something similar but I keep getting the message back
AttributeError: 'Runtime' object has no attribute 'serial_bytes_available'
Any suggestions?

makenbake
 
Posts: 3
Joined: Sat Jul 18, 2020 5:08 pm

Re: Disable REPL to use usb as serial pipe

by bluthen on Sat Jul 18, 2020 10:38 pm

I always made sure to update my circuit python to the latest. Maybe yours came with an older version before that feature was added.

bluthen
 
Posts: 3
Joined: Wed Apr 01, 2020 9:10 pm

Please be positive and constructive with your questions and comments.