LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scanning an ascii string for a start and end character

I would like to watch data lines on a com port and pick off a part of a line that starts with a "$" and ends with a CR. I would like the felxibility to select different start and end characters also. Is this doable with LabView? I have the com port monitoring done I need to separate incoming strings. I can't count chacters because the data lines varies in length each time the data line comes in. Thanks in advance fir the help.

ssmith@bnl.gov
0 Kudos
Message 1 of 7
(3,888 Views)

The following diagram will perform what you want.  However, if using a special character, like $, for start or end, you must precede that character with a backslash.  So put \$ instead of just $ for the start character.  Special characters are $, *, .(period), \ (use \\), ^, and some others you could find by going to the help screen for Match Pattern.  For your application, start char would be \$ and end char would be \n with the end char control set to display \Codes.

Message Edited by tbob on 12-06-2005 12:14 PM

Message Edited by tbob on 12-06-2005 12:16 PM

- tbob

Inventor of the WORM Global
Message 2 of 7
(3,886 Views)
tbob--
    I should use a"\$" for the start but what do I use for the carriage return?? Just hit the return key in the control window or use the "\r" in the control window?? Also do you know what error number 85 means, and is there someplace to find out what error codes mean?? Thanks in advance.

ssmith@bnl.gov
0 Kudos
Message 3 of 7
(3,864 Views)
if you hit the return key you get carriage return linefeed if you right click the control in the front panel or right click the constant in the diagram and choose "codes view" then you can use \r
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 4 of 7
(3,856 Views)

Are you familiar with \codes?  A new line is represented by \n.  A carraige return is represented by \r.  I think a line feed is \l.  The Enter (Return) key is \n which is the same as carraige return and line feed (\n=\r\l).  If you place the cursor in the End Char control and just press the Enter button, you will have the proper character in the control, but it is an unprintable character.  Now if you right click on the control and select "\codes Display", you will see the display box change to \n.  This is way to visibly see the new line character, or any special character like Tab, Space, etc...

Where does the error code come from?  Error codes mean different things depending on who is generating the error.

 

Message Edited by tbob on 12-06-2005 02:36 PM

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 7
(3,849 Views)

If you don't want to mess with having to decide whether or not you need to pre-pend a "\" to the character you are feeding into the match-pattern function then you could just do it all with byte arrays like in the attached example. The example also shows various ways that ASCII controls & indicators can be configured to allow you to more easily handle non-visible characters (just right-click on the front panel control/indicator and select normal, \ codes, hex or password).

As far as your question about the error code meaning, you can right-click on a front-panel error cluster and select the "explain error" option to see all the known causes of the error. You have to then interpret this in the context of what you were doing. When I drop an error cluster on a front panel, set status to Error and code to 85, I can right click on it, select "explain error" and get this:

"Error 85 occurred at an unidentified location
Possible reason(s):
LabVIEW:  Scan failed."

 ...and that sounds to me like (as a WAG) you might be trying to use the Scan From String function with input data that does not match the format string.

0 Kudos
Message 6 of 7
(3,832 Views)
tbob--
    The little piece of code worked great!! I wanted the start character and the end character with everything in between. So using what you gave me and a couple of concatenate vis I was able to get what I wanted. Thank You very much for the help. You da man!!!

ssmith
0 Kudos
Message 7 of 7
(3,805 Views)