09-23-2016 10:28 AM - edited 09-23-2016 10:32 AM
Hello,
I am communicating to a robot from LabVIEW (2013) via sockets and TCP/IP. The robot is the server, and LV is the client.
I am starting with the target data in this format (in a string):
"[0~100~0]~[0.96593~-0.25882~0~0]~[1~0~0~0]~[150~50]"
[X,Y,Z],[Q1,Q2,Q3,Q4],[C1,C4,C6,Cx],[TCPVel,OrientVel] except replacing the "," (commas) with a "~" (tilde) because I am loading the target data in from a spreadsheet that is a comma delimited file.
In LV, I am taking that string, scanning from the string and splitting up the individual elements. I then output the single elements as single, 32-bit reals. I take each of these, and convert them individually back into a string, and then concatenate them and send them to the robot. The robot unpacks these raw bytes individually and converts them into a robot target (position in space).
I am trying (in LV) to check if the user sent a bad character (non-numeric character) in the target data. Example of this is:
[-50~-150~0]~[0.96593~-0.B2A5D882~0~0]~[1~-1~0~0]~[150~50]
Now, in LV, when I am scanning from the string, these bad character turns the whole element to zero, and any other elements afterwards to zero as well. See attached screen shot for similar example.
My question is, in my VI, can I parse out any non-numeric characters (that are inside the brackets and characters that are NOT a "~" (tilde))? That way, I can still get the numbers of that element and not have that element or the other elements turn to zero?
Thanks in advance for any help!
Sorry for the essay question 😛
SM
Solved! Go to Solution.
09-23-2016 10:51 AM
This sounds like a job for Regular Expressions. But I'm not an expert on them to be able to tell you what the string would like.
09-23-2016 10:57 AM - edited 09-23-2016 11:05 AM
Well is there a way to like scan the string and if it contains non-numeric values in the brackets and/or in between the tilde's, just discard it and keep the number values?
Attached is a word document which is a list of all the possible bad inputs for the string.
I need to be able to parse out any of the bad data and keep the numeric values. Or at least alert the user that a bad string has been input. For instance if I input #1 from the attached document, that's a non-numeric character, but a non-numeric character is supposed to be there (a tile "~"). However, it's the incorrect non-numeric character. So at that point could I either replace that bad character with a tilde, or at least alert the user that bad string has been input?
Regular expression doesn't really help me much...
Thanks,
SM
09-23-2016 11:06 AM - edited 09-23-2016 11:07 AM
You also have periods (decimal delimiters) that you probably want to keep, right?
What about the lettter "E or e" as in 0.5e-1?
09-23-2016 11:08 AM - edited 09-23-2016 11:12 AM
Correct. I need the decimals and negative signs. But I believe that is all. I probably need to check also for 2 periods (1..234) or 2 negative signs (--123). There's just so many possiblities of bad inputs.... I think the "E" or exponential will be ok
Thanks,
SM
09-23-2016 11:59 AM
@SteMob wrote:Regular expression doesn't really help me much...
I think it will help you a lot. Because it can include characters, exclude characters, and understands position withing the string and the difference between numeric and non-numeric. It seems like your strings are pretty well defined used the tildes and brackets and is ideally suited for regular expressions so that you can find the bad characters and replace them with nothing. The hard part is determining the correct regex string. Others on the forum are regex wizards. Me, I'm just beginning to study them.
09-23-2016 12:05 PM
Oh ok, that makes sense. I guess I just didn't understand what that function did.
That being said, can somone with more experience with Regular Expression formatting help me or show me an example of something like this?
Thanks for the help,
SM
09-23-2016 02:14 PM
I usually just pound my head against the wall until I come up with a RegEx expression that does the job. 😉
09-23-2016 02:16 PM
Yes, that's what I have been doing for hours... Does anyone know how to write a format for Regular Expression for what I need?
Thanks for any help,
SM
09-23-2016 03:18 PM
It all just seems way too fragile. What if the extra characters happen to be numeric? Maybe you also need to send a checksum or similar to validate the message.