LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

loop with every set number of string character

I am processing a string of data that comes in through the serial port. Each package of data is about 31 bytes. I have created a vi that processes the data package with deleting certain bytes at a certain offset within the package and sorting certain bytes into arrays. How do I create a loop such that it counts every 31 bytes(each package) and loop back to go through the same process?
The string length command didn't seem to help me since it returns the total number of bytes. Thank you very much for your help.
0 Kudos
Message 1 of 5
(3,252 Views)
If each packet is exactly 31 bytes, you could process each one right after receiving, then read the next packet in the next iteration of the loop. Each loop would contain a UDP read (or TCP, depending on your situation) and packet processing in series.

If each packet contains multiple data "packages" (length is a multiple of 31), you could process it in a FOR loop with n=length/31. Insert the FOR loop to get the substring with start=I*31 (I=iteration terminal) and lenght=31, the process one substring per iteration.

If this is not what you need, please provide more details and maybe attach a simplified sample of your code.
0 Kudos
Message 2 of 5
(3,247 Views)
Here is what the package of data are always 31 bytes each and look like:
-3 bytes of opening characters.
-2 bytes of group ID(1st byte is 00, only need second byte)
-3 bytes of miscellaneous info, don't need
-20 bytes of sensor data
-3 bytes of closing characters.

I have included the VI I have so far. First it reads in the string from the serial port. Then it eliminates the 3 opening characters. Next step is identifying which group ID it is to save data to different files. Then elimnate the miscellaneous bytes and the closing bytes. The remaining 20 bytes of sensor data are decimated into 4 arrays for 4 sensors.
My previous question is: how do I loop the same exact process for every 31 bytes of data in the string.
I also have some problem with plotting the arrays of sensor data on the same wavechart. I used the bundle command, but it didn't work.
As for saving the sensors data in excel, can you tell me how to save the data such that each array is saved in 1 column of the same file.

All of this needs to be done as data is received continously. Sorry for asking many questions at the same time. I really need help with this, and I don't have much time left.
***Please save any modification to Vi as version 6. Thank you very much for your help.
0 Kudos
Message 3 of 5
(3,241 Views)
You can repeat the entire sequence by simply drawing a while loop around the entire code (not including the configure VI, there's no need to configure more than once). You should also place a VISA close after the loop. In addition, I would suggest cleaning up your wires a bit.

A chart does not accept arrays. If your arrays are the same size, you can draw a for loop around the bundle and chart and the arrays will auto index. Keep in mind that a chart bases its X values on time, so if those are important to you, you will have to find some way to sync them.

To save to the file, just wire the 1D array into the file and wire T into append. If you want seperate columns, you can build the arrays you seperated into a 2D array and wire that in.

To learn more, I suggest you read the LabVIEW user manual. Also, try searching this site and google for LabVIEW tutorials. Here is one you can start with and here is another. You can also contact your local NI office and join one of their courses.
In addition, I suggest you read the LabVIEW style guide.

As a last request, please don't post the same question to multiple threads. It does no good.

___________________
Try to take over the world!
0 Kudos
Message 4 of 5
(3,235 Views)
"As a last request, please don't post the same question to multiple threads. It does no good. "


Thanks, I started a new thread to ask a question to anybody who can help but then I wanted to response directly to Chilly Charly in the last post because he was very helpful, and it would be nice if he can provide some addition to his last suggestions. I didn't mean to be repetitive. Sorry!
0 Kudos
Message 5 of 5
(3,214 Views)