Serial through V5 controller

I’ve figured out how to read from the brain, because it has the user and the comm ports but the controller only has 1.
I know it’s possible just because of the fact that the VS Code extension is able to do it but I can’t figure out how. I know I could use websockets that the vscode extension provides but I want to avoid the need for vscode for running it.

The brain is simple enough with this simple python script I can easily read the serial from the brain but when you plug it into the controller it doesn’t work.

import serial

def read_serial_data():
    try:
        ser = serial.Serial('COM17', 115200, timeout=1)
        print('Connected to VEX V5 controller.')
        
        while True:
            if ser.in_waiting > 0:
                line = ser.readline().decode('utf-8').rstrip()
                print(line)
    except serial.SerialException as e:
        print(f'Error: {e}')
    except KeyboardInterrupt:
        print('Program interrupted by user.')
    finally:
        ser.close()
        print('Serial connection closed.')

if __name__ == '__main__':
    read_serial_data()

There’s some extra work needed. It appears that you must request bytes from the controller by sending a special command. Additionally, the controller may need to be in download mode (well, the PROS CLi sets it to download mode when doing wireless debugging). This section of code in the PROS CLI might help you get started:

2 Likes

I’ve recently had to deal with this same problem for a CLI tool that i’ve been working on. The controller has a specialized packet for obtaining/sending user program stdio from only a V5 system port. If you aren’t working off a codebase with an existing V5 implementation for packet exchange on the system port, it might be a lot of work. Along with what charles has provided, I can point you to the _txrx_ext_packet function in pros-cli for how you can exchange extended commands.

I’m going to say that ive also had replies taken down in the past that just covered VEX tools dealing with the serial protocol, so i’m not going to go further in-depth on this forum unfortunately. My best advice is to look at the pros-cli implementation that charles linked, although from some personal testing their code misunderstands the packet structure (it does still work, though).

4 Likes