locked
Logging Sensor Data in a Text File

    Question

  • As the subject line reads, I am trying to log accelerometer data into a text file.  Right now I have the UI being updated with the accelerometer readings, and I want to take those accelerometer readings and create a text file.  The data will be written to the text file when the user presses the start button, and then when the users press the stop button, the data being written to the text file will stop.  I am using the Isolated Storage API, however, when I am running the app with all the code written the app crashes when the accelerometer started.  If there is any way to handle this, please let me know.  I will really appreciate the assistance!
    Monday, October 06, 2014 5:19 PM

Answers

  • Hello,

    >How would I handle the change of the incoming readings when using an array?  That's one question, second being, what type of array would you recommend using, a string array? 

    Define a classAccelerometerData class to hold the X, Y, Z and time. In accelerometer_CurrentValueChanged event, you should add the object of classAccelerometerData into the array. If you want to handle the change of the incoming readings, just find the previous object of classAccelerometerData in the array, comparing the X, Y, Z and you will know the changing details. I modified your project and you will see the changes in AccelerometerPage.xaml. Code looks like the following.

    Define a class.

     public class classAccelerometerData
    
        {
    
            public float X { get; set; }
    
            public float Y { get; set; }
    
            public float Z { get; set; }
    
            public DateTime Time { get; set; }
    
    }
    

    Create an array.

    private List<classAccelerometerData> list;

    In UpdateUI method.

    //if we log as the first one below, there will be so many data. so log it per second
    
                //list.Add(new classAccelerometerData() { X = acceleration.X, Y = acceleration.Y, Z = acceleration.Z, Time = DateTime.Now });
    
                if (list.LastOrDefault() != null && DateTime.Now.Second == list.LastOrDefault().Time.Second)
    
                {
    
                }
    
                else {
    
                    list.Add(new classAccelerometerData() { X = acceleration.X, Y = acceleration.Y, Z = acceleration.Z, Time = DateTime.Now });
    
                }
    

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, October 09, 2014 3:18 AM
    Moderator

All replies

  • Hi Pranav,

    There is less information for me to know why your app crashes when start logging the accelerometer. You should find more details about this crashes and post them here.

    > Right now I have the UI being updated with the accelerometer readings, and I want to take those accelerometer readings and create a text file. 

    I assume the crash is related to the collecting accelerometer data operation. Did you write the AccelerometerReading data into storage file in ReadingChanged event handler? I would recommend you create an array to collect these data. When the user press the stop button, read the accelerometer data and then write to storage file.

    It’s helpful if you can provide a repro project. Use your OneDrive and share a link here.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 07, 2014 6:19 AM
    Moderator
  • Hi Herro, 

    Thank you, thank you, thank you for showing your willingness to help!  I'll definitely put a zip file on my OneDrive and share it with you.  When I wrote the code, I created a method called WriteFile() which I labeled as async, and I made the reference to that method in the ReadingChanged event handler.  I don't have those lines of code now because at the moment I am able to have the phone report the accelerometer readings to the local console just to make sure that I am getting a stream of data.  

    When you mentioned about using an array to collect the data, I tried that approach, but one question I have is this, when using an array as in this case, would you create a string array?  Here is why I ask.  I have the following information that is to be written into an array: x, y, and z components to the accelerometer, date, and timestamp.  So as an example, you'd see something like this:  

    0.23515 -0.00892 0.99876 10/7/2014 -4:00

    That line of text above keeps changing automatically as new readings are being shown.  How would I handle the change of the incoming readings when using an array?  That's one question, second being, what type of array would you recommend using, a string array?  

    Again, I thank you very much for your willingness to help out!

    Regards, 

    Pranav

    Tuesday, October 07, 2014 3:07 PM
  • Hi Herro, 

    I had said that I will be giving you the OneDrive link.  Here it is.  Please can you help me and show me how to properly use the Isolated Storage capabilities such that I can log sensor data as either a .txt file or as a .csv file.  

    I appreciate the help a lot!  Thank you!

    Pranav 

    Link: https://onedrive.live.com/redir?resid=A6AAD4594FCECC1%218464

    Wednesday, October 08, 2014 2:52 PM
  • At the moment, I have the code reporting to the console debugger, I would like to have it such that I want to have it write to the file immediately.  Again, thank you for the help!  

    Wednesday, October 08, 2014 2:53 PM
  • Hello,

    >How would I handle the change of the incoming readings when using an array?  That's one question, second being, what type of array would you recommend using, a string array? 

    Define a classAccelerometerData class to hold the X, Y, Z and time. In accelerometer_CurrentValueChanged event, you should add the object of classAccelerometerData into the array. If you want to handle the change of the incoming readings, just find the previous object of classAccelerometerData in the array, comparing the X, Y, Z and you will know the changing details. I modified your project and you will see the changes in AccelerometerPage.xaml. Code looks like the following.

    Define a class.

     public class classAccelerometerData
    
        {
    
            public float X { get; set; }
    
            public float Y { get; set; }
    
            public float Z { get; set; }
    
            public DateTime Time { get; set; }
    
    }
    

    Create an array.

    private List<classAccelerometerData> list;

    In UpdateUI method.

    //if we log as the first one below, there will be so many data. so log it per second
    
                //list.Add(new classAccelerometerData() { X = acceleration.X, Y = acceleration.Y, Z = acceleration.Z, Time = DateTime.Now });
    
                if (list.LastOrDefault() != null && DateTime.Now.Second == list.LastOrDefault().Time.Second)
    
                {
    
                }
    
                else {
    
                    list.Add(new classAccelerometerData() { X = acceleration.X, Y = acceleration.Y, Z = acceleration.Z, Time = DateTime.Now });
    
                }
    

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, October 09, 2014 3:18 AM
    Moderator