Click here to Skip to main content
15,877,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to log the temperature data in my application to a txt file @ 1000 samples/sec.but i am getting only 4 to 5 samples per second.i am getting tempearture values using serial communication(USB) from the device, and monitoring it on the screen and log it for further reference.

I want to log data at the rate of 1000 samples/sec.

What I have tried:

here is my code
'data log button code

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        bt_count1 = bt_count1 + 1
        If bt_count1 <= 1 Then
            Button1.Text = "STOP"
            Button1.ForeColor = Color.Red
            SaveFileDialog1.FileName = DateTime.Now.ToString("ddMMyyyy") & "_" & DateTime.Now.ToString("HHmmss") & ".txt"
            txtfileName = SaveFileDialog1.FileName
            enable_log1hzdata = True
            FileOpen(1, txtfileName, OpenMode.Append)
            logprint1hz(log1hzdata_filename, "  DATE" & vbTab & "  TIME" & vbTab & "Pol" & vbTab & "HSW1,HSW2,VSW1,VSW2" &
                        vbTab & "H-TR1" & vbTab & "H-TR2" & vbTab & "H-Attn" & vbTab & "H-Ph" & vbTab & "Pol" & vbTab & "HSW1,HSW2,VSW1,VSW2" &
                        vbTab & "V-TR1" & vbTab & "V-TR2" & vbTab & "V-Attn" & vbTab & "V-Ph")
End sub
Updated 28-Dec-16 2:01am

I want to log data at the rate of 1000 samples/sec.
It would usually makes no sense using such a data rate for a temperature measure (usually temperature is slow changing). Unless you have a very good reason for doing the opposite, just discard such a requirement.

Data rate depends on the sensor acquisition rate and on serial communication speed. You should check both of these parameters in order to just state the feasibility.

At 9600 baud, very likely it is the serial communication speed the rate limiting factor.
Assuming a 20 bytes message per measure, you get a maximum of 48 measures per second.
Hence, if you can, increase the baudrate.
Share this answer
Member 12659926 28-Dec-16 6:13am    
thanks for reply,along with temperature i have some other datas that will change frequently,i am operating at a baud rate at 9600 bps,using usb 2.0 for serial communication,i want to know is their any way to increse the data logging speed through my code.
is their any parameter which modify the data logging speed.
CPallini 28-Dec-16 6:28am    
See my updated solution.
Member 12659926 28-Dec-16 6:33am    
Thanks for reply, my message consist of 96 bits,i have increase the baud rate to 115200,then also i have not got 1000 samples/sec.
is their any other way to increase data logging rate
CPallini 28-Dec-16 6:38am    
Assuming your message is 96 bytes you need a at least a 960000 baud serial communication.
You have also to check the acquisition speed of your sensors.
Member 12659926 28-Dec-16 6:42am    
is 960000 baud rate possible,my data is of 12 bytes(96 bits) not 96 bytes.
try storing (concatenation) text data into stringbuilder object, and write to file every 10 or 100 lines once. The memory processing operation is much faster than actual file printing.

Or simpler than that, using StreamWriter object to ease & speed up the file operation.
Share this answer
First, this code is not complete, the if structure is not closed and the part that read the data is missing.
It is not possible to help you because you didn't told us the speed of the link with sensor, the amount of data to read with each reading, what you do with that data before saving to file.
The only thing I can tell you is that you probably do too much things for the speed of link.

Improve your question with complementary data.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900