Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

[OT] Filtering / Highlighting serial port input / PuTTY output

by afoken (Canon)
on Aug 13, 2020 at 15:24 UTC ( #11120683=perlquestion: print w/replies, xml ) Need Help??

afoken has asked for the wisdom of the Perl Monks concerning the following question:

Hi!

I'm working with two systems, both without real(TM) operating systems. One is a microcontroller, running our software on bare metal, the other is my PC running Windows 7. The microcontroller writes debug output to one of its serial ports, which is connected to the PC. On the PC, putty simply displays whatever text is written to the debug port. A common setup at work, but I'm drowning in debug output. All of it is kind-of relevant, but usually only a little bit of the debug output is relevant for the current problem.

(And no, I can't disable the irrelevant debug output on the microcontroller in reasonable time.)

On a real operating system, I would run something like this:

stty raw 115200 < /dev/ttyS0 grep --perl '^(Foo|Bar):' < /dev/ttyS0

But I'm stuck on Windows. I need some way to print input from a serial port to a fully resizeable window, optionally with a filter that either omits or highlights incoming lines. PuTTY does all I need, except for filtering. Trying to run anything perl in a command window already fails, because the console window has a maximum width of 80 characters, which is little more than a third of the screen width.

And I don't have the time to hack a special version of PuTTY or a large perl application.

A Google search for "putty filter" and similar combinations results in lots of ugly teapots, anti-glare filters, and some other wierd stuff, but nothing even close to filtering output from PuTTY.

Any hints? E.g. how to get that !%&%$*! standard console window to allow free resizing? Or a tool that can do what I want?

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re: [OT] Filtering / Highlighting serial port input / PuTTY output
by Corion (Pope) on Aug 13, 2020 at 18:22 UTC

    You can resize the console window either using Win32::Console (from within your filter) or the mode command (before launching your filter command). Also you can define the console width/height when launching it as a .cmd file.

Re: [OT] Filtering / Highlighting serial port input / PuTTY output
by aitap (Curate) on Aug 13, 2020 at 19:27 UTC
    If you just need a resizeable terminal to run Perl in, you could always use Cygwin's mintty or ConEmu.
      If you just need a resizeable terminal to run Perl in, you could always use Cygwin's mintty or ConEmu.

      ConEmu did the trick, combined with pryrt++'s plink idea. It took a little configuration to make it look like a boring console window again, mainly invoking cmd.exe without parameters, using the default windows color scheme, and hiding the status bar and the tab bar.

      Thank you!

      And now that perl is involved, and ConEmu supports ANSI, I already consider using ANSI sequences to highlight matching lines instead of filtering out all irrelevant lines ...

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        Getting rid of unwanted lines:

        plink -serial COM24 -sercfg 115200,8,n,1,N | perl -ne "/^(Pct|NRS)/ && + print"

        Highlighting interesting lines instead:

        plink -serial COM24 -sercfg 115200,8,n,1,N | perl -MTerm::ANSIColor -n +e "print colored($_, /^(Pct|NRS)/ ? 'bright_yellow' : 'white')"

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: [OT] Filtering / Highlighting serial port input / PuTTY output
by jo37 (Pilgrim) on Aug 13, 2020 at 15:50 UTC

    I'm not sure, but maybe under Cygwin you can access the serial port. Cygwin makes the Redmond-thing an "almost-real" OS.

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$
      ... cygwin ...
      Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\alex>apt-get install cygwin 'apt-get' is not recognized as an internal or external command, operable program or batch file. C:\Users\alex>sudo apt-get install cygwin 'sudo' is not recognized as an internal or external command, operable program or batch file. C:\Users\alex>

      *SCNR*

      Yes, it might work, but I had some unpleasent encounters with cygwin, and so I would prefer not to have cygwin installed on my PC.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Since cygwin is undesirable, maybe Windows Subsystem for Linux?

        Or use gnuwin32's grep on the output of putty's plink.exe (which is the command-line client). I am able to successfully plink -batch -ssh ... | grep ... for what I need.

        What were you trying to do with these commands? UPDATE: Sorry, overlooked your SCNR
        At work I use Cygwin every day and for decades and I am glad that it exists. Never had any problems with it.

        Greetings,
        -jo

        $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11120683]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2020-09-18 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (113 votes). Check out past polls.

    Notices?