如何提高visual basic中的数据记录速度

问题描述:



i想要将我的应用程序中的温度数据记录到txt文件@ 1000个样本/秒。但我每秒只得到4到5个样本。我正在使用温度值来自设备的串行通信(USB),并在屏幕上进行监控并记录下来以供进一步参考。



我想以1000个样本的速率记录数据/秒。



我尝试了什么:



这是我的代码


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"
            SaveFileDialog1.ShowDialog()
            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

引用:

我想以1000个样本/秒的速率记录数据。

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

使用这样的数据速率进行温度测量(通常是温度)通常没有意义变化很慢)。除非你有充分的理由反对,否则就放弃这样的要求。



数据速率取决于传感器采集速率和串行通信速度。您应该检查这两个参数,以便说明可行性。



[更新]

At 9600 波特,很可能是串行通信速度是速率限制因素。

假设 20 $ c每个度量$ c>字节消息,每秒最多可获得 48 度量值。

因此,如果可以,请增加波特率。

[/ update]

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.

[update]
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.
[/update]


尝试将文本数据存储(连接)到stringbuilder对象中,并每10或100行写入一次文件。内存处理操作比实际文件打印快得多。



或者比这简单,使用StreamWriter对象来简化&加快文件操作。
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.


首先,此代码未完成,如果结构未关闭且读取的部分数据丢失。

无法帮助您,因为您没有告诉我们传感器链接的速度,每次读取时要读取的数据量,您对该数据的处理方式保存到文件之前。

我唯一可以告诉你的是你可能会为链接速度做太多事情。



使用补充数据改进您的问题。
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.