LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed setting up an accelerometer via serial port

Hoping you might be able to give me some advice and point me in the right direction as my experience with labview is limited.

 

I am wanting to read data from an accelerometer streaming through a serial port. Using the labview examples i have no problems in connecting to the device and seeing the data but i am going around in circles trying to work out where to from now.  

 

I need to create a VI which would show data streaming and then gives the user the ability to save data for various time periods to a text file. I am getting stuck as the data from the accelerometer is constantly streaming in 20byte packets every 2ms in the following format: 7E 00 0E 83 00 00 26 00 01 0E 00 02 00 01 F9 02 64 E5, where 00 02 01 F9  02 64 is the data of interest and of course when starting to read from the device it isnt necessary going to begin at the start of the packet.

 

I am assuming that inside the while loop i need to get the vi to scan the string to find the start of the first packet and then begin writing it to an array using a shift register for each sample with the left over from the string if not reading the full packet being attached to the next read, then if the data is to be saved to a txt file get it to enter a for loop for the user to define the number of samples to be saved or use an index array option to save a subset of data to a txt file.

 

Would greatly appreciate any device or examples of the most efficient way to set this up before i lose my sanity!  

0 Kudos
Message 1 of 3
(2,767 Views)

Hi Doofus,

 

Thank you for posting on our forum, i understand your issue and belive the question may be more suited in this section of our forum.

If you could repost it in the part of the forum you will get responses by people who are more specialised in that area.

If you could also attach your VI at the current stage that it is that would be very helpful, as it sounds that you know the general outlay of what you what your program to do!

 

Kind Regards,

John McLaughlin
Academic Account Manager
National Instruments UK & Ireland
0 Kudos
Message 2 of 3
(2,746 Views)

The easy way is a three step process.

 

First, acquire 2n-1 bytes (39 in your case) so you are sure you have a full set of data.  Parse out the first full set using the string utilities (match pattern, split string, etc.).  The remainder of the string is the start of your next data set.

 

Second, acquire enough points to get the next data set and parse it.

 

Third, continue looping and getting 20 bytes (keep verifying your start and end so you know if there are glitches).

 

A harder, but far more robust, way, is the following:

 

Read in data until you get your start sequence.  A circular buffer would be useful for this (you will need to implement this yourself).

 

Read in your data of interest and record/save/...

 

Read in the terminator.

 

Repeat as needed.

 

For all of these, you can use a flat sequence in a loop, but a state machine is far easier and more flexible in the long run.  Check out the LabVIEW help and these forums for how to create and use a state machine.

 

It is often easier to use arrays of U8s instead of strings for this type of data manipulation.  Under the hood, they are the same thing, so the conversions between the two are highly efficient.

 

Let us know about any problems you run into.

0 Kudos
Message 3 of 3
(2,735 Views)