Menu
JAQForum Ver 26.09

Forum Index : Microcontroller and PC projects : Redirecting Text Output

Posted: 06:50am
22 Oct 2026
Copy link to clipboard
PilotPirx
Senior Member


Hello,
Is it possible with MMBasic to redirect text output, such as OPTION LIST, to a COM port? (PRINT #1)?
I have a printer connected to COM1 and would like to print OPTION LIST.
 
Posted: 10:12am
22 Oct 2026
Copy link to clipboard
Mixtel90
Guru


I don't know, it's not something I've ever wanted to do. I can't think of a way to do it directly from the Pico. OPTION LIST is a console command and displays on the console. Anything that is normally sent to a COM port is from the user's program.
 
Posted: 12:18pm
22 Oct 2026
Copy link to clipboard
PilotPirx
Senior Member


I can print a screen dump, but then I have too much white space on the printout.
 
Posted: 12:29pm
22 Oct 2026
Copy link to clipboard
Martin H.
Guru


how about

option console serial


  Quote  OPTION CONSOLE output
Specifies where print statements will output. Valid settings are BOTH (i.e.
SCREEN and SERIAL), SERIAL, SCREEN, NONE. This is a temporary
option that is reset when a program exits.

Edited 2026-10-22 22:30 by Martin H.
 
Posted: 12:40pm
22 Oct 2026
Copy link to clipboard
Volhout
Guru


  PilotPirx said  I can print a screen dump, but then I have too much white space on the printout.


Maybe I my memory is confused, but before the WYSIWYG age printing ALWAYS wasted paper before you got it right.
Apple fixed it with the MAC, and soon after that Windows.

Volhout
 
Posted: 01:02pm
22 Oct 2026
Copy link to clipboard
ville56
Guru

PilotPirx,

you could try MMCC start/end capture. Everything that prints to the serial console can be captured and processed later, no matter how long the output is (more or less). Very handy IMHO and often used to  document output.

Gerald
 
Posted: 01:03pm
22 Oct 2026
Copy link to clipboard
PilotPirx
Senior Member


"option console serial" uses COM3, but i use COM1.
You can redirect it with OPTION CONSOLE PORT 1, but this causes a reset and its permanent. Thats not a good solution.
 
Posted: 01:05pm
22 Oct 2026
Copy link to clipboard
PilotPirx
Senior Member


  Quote  Maybe I my memory is confused, but before the WYSIWYG age printing ALWAYS wasted paper before you got it right.

That's true...
 
Posted: 01:38pm
22 Oct 2026
Copy link to clipboard
Mixtel90
Guru


Patient: "It hurts when I do this, Doctor."
Doctor:  "Don't do it then. Next please!"

:)
 
Posted: 08:46pm
22 Oct 2026
Copy link to clipboard
phil99
Guru


  Quote  before the WYSIWYG age printing ALWAYS wasted paper before you got it right.
Off topic, but with 3D printers history repeats.
 
Posted: 04:59pm
25 Oct 2026
Copy link to clipboard
mozzie
Guru

G'day PilotPirx,
This is something that I too have wanted on several occasions in the past, but up until now could not think of a solution.

For PicoMite RP2350 only (I think)

The program below is probably not the ideal way to achieve this but it does work. It allows the output to the console to be read back and the do:loop can be used to store it in a file or sent to a COM port, it could also be saved in a longstring for further manipulation.

'prog to test UART loopback

Option default integer
Open "com7:" As #1 'test BT Serial
'Open "A:\Looptest.txt" For append As #1

Poke word &h40078030,&h381 'loopback on UART1 (COM2)

Option list ' something to test
'List pins
'Bluetooth status

Pause 50

Do While Loc(#0)
 Print #1,Input$(32,#0); 'print to BT or file
 Pause 50
Loop

Poke word &h40078030,&h301 'loopback off UART1 (COM2)

Close #1

End


This works by poking a 1 to bit 7 of the UARTCR register that enables LOOPBACK for that UART, so everything sent to the serial console is also looped back to the receiver.
This will only work on a serial console. If you are not using the serial console you could enable it and use the same program, DO NOT loop the pins unless it is disabled at the command prompt, it'll loop around forever.

For UART0 (COM1) use address &h40070030 instead. The delays are needed for COM7 @ 9600 baud.

Hope this is useful.

Regards, Lyle.
Edited 2026-10-26 03:07 by mozzie
 
Posted: 05:29pm
25 Oct 2026
Copy link to clipboard
matherp
Guru

On non-USB builds you can use OPTION SERIAL CONSOLE command with the both option and you will get the console output on both the USB and nominated serial port.
 
Posted: 03:28pm
26 Oct 2026
Copy link to clipboard
mozzie
Guru

G'day,
Peter:
that initially sounds counter-intuitive but is of course correct, it does however mean those 2 pins are unable to be used for anything else.
I have now realized the 1024 byte buffer on the console means this is not as useful as hoped, Stepper status over-runs that with ease.

All:
Within the 1024 character limit of the input buffer, this slightly more streamlined version will allow the output of text sent to the console to be captured to a longstring for further analysis or to be saved to a file. I will use this when testing to be able to save diagnostic data to a text file on a system with no PC etc as console.

'prog to test UART loopback

Option default integer
Dim RecStr(511)

'Lpbk_REC "Stepper status"

Lpbk_REC "Option List"

'Lpbk_REC "List Pins"

'Lpbk_REC "BlueTooth Status"

'Lpbk_REC "Memory"

'Lpbk_REC "List System I2C"

Print :Print "OUTPUT LONGSTRING:"
LongString print RecStr()
End

Sub Lpbk_REC Lpbk_COM$
 Poke Word &h40078030,&h381 'loopback on UART1 (COM2)
 Execute Lpbk_COM$
 Pause 1
 Do While Loc(#0)
   LongString Append RecStr(),Input$(32,#0)
   Pause 1
 Loop
 Poke Word &h40078030,&h301 'loopback off UART1 (COM2)
End Sub


For RP2350:
UART0 (COM1) = &h40070030
UART1 (COM2) = &h40078030

For RP2040:
UART0 (COM1) = &h40034030
UART1 (COM2) = &h40038030

Regards, Lyle.
 


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026