LabVIEW Embedded

cancel
Showing results for 
Search instead for 
Did you mean: 

how to split a string in LabView?

Hello everyone,

 

I'm using the LabView to control a robot named SHRIMP |||. The robot gets commands in hexadecimal format. I need to process info from the command line and therefore I want to split the string of the command line.

In order to make myself clear this is the case: the command (in hex) is 040100 when 04 is the command itself (set velocity and steering angle), 01 is the velocity to set and 00 is the steering angle. When I read it in Labview I see - /04/01/00. I need to separate the velocity and angle from the string so I used the "search/split string" VI but it doesn't seem to help get rid of the "/" delimiter. I can get only the string before the delimiter or the string with the delimiter inside. When I tried to use offset, it seems that the LabView recognize each part of the command as one char in the string ("/04","/01","/00" are the 3 parts of the string) so I can't use it also. I tried to change the display of the string to hexadecimal format but still no luck- I couldn't convert the string to a number.

 

Any ideas?

 

Thanks,

 

Rap Master

Message 1 of 4
(20,733 Views)

RapMaster,

 

What you probably want in this case is Scan From String. This takes in an input string, a formatter string similar to the ones used in C (here is a refresher if you are not familiar with printf formatters: http://www.psych.upenn.edu/~saul/parasite/man/man3/printf.3.html), as well as some other parameters that are not as important to this project, and then outputs a number for each field that was represented by a formatter (i.e. %x). Double clicking on the VI brings up a window that will walk you through making the formatters, in case you feel more comfortable that way.

 

I'm attaching a VI that does exactly what you requested, using Scan From String. To expand the functionality of this VI, just modify the formatter, and more outputs will appear for each formatter.

David M.
Applications Engineer
National Instruments
Message 2 of 4
(20,727 Views)

Hi David,

 

First, thanks for the solution. Unfortunately it didn't solve my problem. I tried the VI you sent me as well as some others ("search string for tokens", "search-split", "hexadecimal string to number" etc.). What seems to be the problem is that the the command string which consists of 6 chars in hexadecimal format (040100) and 9 chars in back-slashed format (\04\01\00) is treated by labview as array with 3 cells- "\04","\01","\00". It seems the the back-slash is an integral part which cannot be separated. For example when we entered the constant "\01" as input string to the hexadecimal string to number VI with offset 1 we got the number- 1 in the output. But when we splitted the command string and entered "\01" with offset 1 it couldn't recognize it as a number. No matter what display format we used. Any idea what can we do?

 

Thanks,

 

Rap Master and his helper.

 

P.S. attaching a snapshot of the VI's I used.

0 Kudos
Message 3 of 4
(20,688 Views)

RapMaster, 

 

A reason as to why your original VI is not working properly with your Search/Split String is that you are only feeding in an offset into the function, not search. A search input is required, and this can be used in order to output your desired hex commands into each string indicator 

 

The response by David does perform what you requested, but perhaps we are confused on the exact formats that you are receiving from your VISA function. Are they coming into the Search/Split String functions as ASCII characters? Or a string displayed in Hex formatting? 

Huntington W
National Instruments
Applications Engineer

***Don't forget to give Kudos and Accepted as Solution where it is deserved***
0 Kudos
Message 4 of 4
(20,650 Views)