From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

CR character in String control

Hello there,
 
I'm trying to create a VI that recognizes Carriage Return character (ASCII code 13) entered to a String control.
I use Match Pattern function and tried some different constants as a pattern: \r, CR constant, LF constant.  Nothing works.
Could anybody help me with this to be easy task?
 
Thanks,
Greg
0 Kudos
Message 1 of 14
(4,365 Views)
Works here just fine. Use a "\r" as pattern (normal display for the string constant!).
 
If this does not work, maybe you can make a small example that shows the problem.
 
Are you sure your string contains a \r? Set it to '\codes' display to be sure.
0 Kudos
Message 2 of 14
(4,362 Views)
<< Are you sure your string contains a \r? >>
I type some characters into a String control and hit "Enter" key.  I want to catch this character and perform some actions on this event.
Please see attached VI written in LabView 7.0
Thanks,
Greg
0 Kudos
Message 3 of 14
(4,342 Views)
Hey Greg:

Had a quick look at your code ... remove the quotes from the constant and change the string control to "\" codes display.  Enter \r into the control and everything works the way it should.  Don't need the quotes.  Good Luck.

Greycat
0 Kudos
Message 4 of 14
(4,336 Views)
You have your string control set to "limit to single line". This means that [enter] terminates the input and is not added to the text string.
 
Also: LabVIEW generates a newline (\n) when you press enter on a string that allows multiple lines. (\r) never happens!
Also: remove the quotes from the pattern input. THe pattern should be a plain two-character string: \n
Also: If you want to check the input while typing (and it seems you want to), you need to set the control to "update while typing".
 
See if you can now figure it out. Good luck! 🙂
0 Kudos
Message 5 of 14
(4,330 Views)

Thanks guys,
Greycat wasn't exactly right. Recommendations of Altenbach helped me.
It's good to know that LabView doesn't generate CR character.  So, if I want to send that string to a COM port I have to append CR.  I came to LabView from "traditional" programming and this fact seems a bit strange to me.

If interested, see final working version.

Thanks,

Greg

0 Kudos
Message 6 of 14
(4,319 Views)
Well, all these wires and loops seem somewhat silly because what you really want seems to be already offered by the "limit to single line" option. I would suggest:
  1. Set the string control to "limit to single line"
  2. Disable "update value while typing" so the code waits until [enter] is pressed.
  3. Use an event structure for "value change", it will be trigered once you hit [enter].
  4. Append \r to the string before sending it to the serial port.

Attached picture shows a "semi-equivalent" code construct. It might just do what you need without polling. Of course real code should do some syntax checking on the string and loop over the event structure until things are OK. Modify as needed.

Message Edited by altenbach on 04-26-2007 12:23 PM

0 Kudos
Message 7 of 14
(4,311 Views)
Hi Greg, altenbach:

Yes, I wasn't exactly right ... I read the posts too quickly ... I now see what you were after ... sorry for not taking the time I should have before answeringSmiley Tongue .. Glad you are on your way to getting it to work. 

Greycat
0 Kudos
Message 8 of 14
(4,304 Views)

enter action.PNG

Why when I press enter it dosen´t work? I mean de NS that I introduce disappears when I press enter

0 Kudos
Message 9 of 14
(3,057 Views)

Attach a VI rather than a picture.  That way we can see the things that can't be seen in a picture.

 

My guess is.

1.  Your \n is still not showing in \codes mode.

2.  Your NS control is still set for multiple lines, thus when you hit enter it appears to disappear.

0 Kudos
Message 10 of 14
(3,050 Views)