08-10-2021 05:56 PM
Hi, I am trying to sort out ESC characters from a file when reading it. This is a constant read of a serial port that has some alignment characters in the form of the ECS button. I can't get the matching expression to work,
As an example this is part of the string :
13;25H 0.0 / 0.0, 0.0 87[14;25H 0.0 / 0.0, 3.0 87[11;40H Rev: 2000.01 Update: 217 87[15;25H 0.00, 0.00,87[15;37H 0.650/0.650 87[16;25H 0.00,0.37,0.02 /87[19;71H 03ff 87[20;71H 07ff 87[21;71H 0256 87[22;71H 0080 87[23;71H 30 87[13;25H 0.0 / 0.0, 0.0 87[14;25H 0.0 / 0.0, 3.0 87[11;40H Rev: 2000.01 Update: 20 87[15;25H 0.00, 0.00,87[15;37H 0.650/0.650 87[16;25H 0.00,0.37,0.02 / 0.43,0.43,0.43 87[17;25H 0.00,0.00,0.00 / 1.15,1.15,1.15
Regards,
Hans
Solved! Go to Solution.
08-10-2021 06:55 PM - edited 08-10-2021 06:59 PM
If I remove the serial communications and just parse the sample text with your code, this is what I get:
Is this not what you wanted?
If you didn't want the Esc character plus the following character to be the "whole match", then what did you want? If it's just the escape character, you can remove the "." in the search string.
Or did you want more? I see that there's a repeated string that looks like "87[15;25H", with the last two numbers changing, is that whole thing what you want? If so, then you need a much different search string, since "." is just a wildcard for any one single character, and you'll need to add more to get the whole thing. This one seems to get it all:
\[0-9\;\[H]+
08-10-2021 07:52 PM
Hi Kyle,
now I got the following response
"LabVIEW: One of the string parameters contains a null character. LabVIEW does not support null characters for regular expression matching."
What I want is something tat looks like the screen shot from Putty:(attached).
The code that outputs the numbers on the serial port is adjusting the cursor position vertically and horizontally when the ESC character appears.
08-11-2021 03:57 AM - edited 08-11-2021 03:59 AM
Hi Hasse,
@hasse wrote:
What I want is something tat looks like the screen shot from Putty:(attached).
The code that outputs the numbers on the serial port is adjusting the cursor position vertically and horizontally when the ESC character appears.
These are not just ESC chars, but complete ESC sequences (like described here)!
Those string contains formatting codes for terminals (or terminal emulators) and you need to parse them correctly when you want to achieve the very same appearance of your text!
I guess something like "<ESC>[14;25H" describes the cursor position on your (virtual) terminal screen…
08-11-2021 11:31 AM
Hi Gerd,
I am curious why it is working when I use Putty if it needs special parsing?
Hasse
08-11-2021 11:43 AM - edited 08-11-2021 11:46 AM
@hasse wrote:
Hi Gerd,
I am curious why it is working when I use Putty if it needs special parsing?
Hasse
It works with PuTTY because it is a terminal program and is processing the terminal escape sequences. The escape sequences do things like control where the cursor is on your screen in a terminal and whether text and/or the cursor are blinking (and with later terminals, the color of the text). You have to parse those sequences and do something similar. Read up on terminal emulation.
It's conceptually similar to hypertext, I suppose.
08-11-2021 12:36 PM
@hasse wrote:
Hi Gerd,
I am curious why it is working when I use Putty if it needs special parsing?
Hasse
Think of it this way. The escape characters and sequence are conceptually similar to the following string of data:
Hello! [Move cursor to next line command] World! [Move cursor to next line command] My name is Bert! [Move cursor to next line command] [Move cursor to center of screen] The quick brown fox jumped over the lazy dog.
A terminal program would see this and display it as:
Hello!
World!
My name is Bert!
The quick brown fox jumped over the lazy dog.
LabVIEW would read this same command and would simply display the entire raw data stream to you. The terminal program reads the raw command stream data, then actually interprets it for you. This is because the terminal is expected to deal with people who need to see things displayed in certain ways. LabVIEW is more general-purpose than that. If you want to emulate a terminal, you can do so, but the native "Read serial" will just give you the raw data stream. How you interpret it is up to you. Perhaps you are writing a sniffer program, and you'd prefer to view the data in a raw format, like this:
H
e
l
l
o
!
[New line]
W
o
r
l
d
!
[New line]
(etc)
Well, you can do that too. LV returns the raw data stream, and leaves the interpreting and display up to the programmer.
08-13-2021 11:01 PM
Hi, I am still struggling with this.
I am not sure if I shall use the Match regular expression or just use a read and parse it. I tried to find the Internet addon 2012, there shall be a Terminal function there but I could not find that anywhere. I don't know if I shall use Telnet, xterm or VT100+ . It is so confusing.
There must be some examples out there?
08-14-2021 03:15 AM
Here's a list of VT100 Commands. Maybe you could build your own? (If you do, you might want to make it its own library so you can use it elsewhere.)
08-16-2021 09:15 AM - edited 08-16-2021 09:21 AM
@hasse wrote:
Hi, I am still struggling with this.
I am not sure if I shall use the Match regular expression or just use a read and parse it. I tried to find the Internet addon 2012, there shall be a Terminal function there but I could not find that anywhere. I don't know if I shall use Telnet, xterm or VT100+ . It is so confusing.
There must be some examples out there?
it looks like, you are not meant to use it anymore
when I use "search and replace string" (with right click: ✓ regular expressions) instead of "match regular expression", I can turn your example into this:
notice the escape character \ before the [
furthermore, when adding [0-9]+;[0-8]+H you get rid off the none constant string parts at the "beginning"
optionally: add a second stage by applying the same function again with a different search string (regular expressions must'n be turn on here) to get rid off the "end"