Click here to Skip to main content
15,888,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
Actually I am working on streamer .the data is coming from fx3 board
that data is storing in buffer from that buffer I am copying to another buffer and then saving to pc . after reaching limit of the buffer size it is throwing an exception .so I want to do this for continuously save data without stoping the streamer . I want to clear the buffer after copied the data from that buffer to another buffer. the functions which I tried is attached below .I hope some one will help to sort out of this problem

What I have tried:

byte[] temp=new byte[100*1024*1024];

if (Save == true)   //Check if save Button is marked
              {



                          byte[] temp1 = new byte[Offset];

                          Buffer.BlockCopy(temp, 0, temp1, 0, Offset);  // copy the contents received on  temp[] to temp1[]
                          string res = string.Join("", temp1);
                                                          // Put all the data streamed to a single string
                          string file_name = "C:\\user\\mady\\desktop\\myData.txt";    // Write the string to mady.txt
                          System.IO.StreamWriter objWriter;
                          objWriter = new System.IO.StreamWriter(file_name);
                          objWriter.WriteLine(res);

                          objWriter.Close();




                  }
Posted
Updated 13-Jun-17 22:33pm
Comments
Richard MacCutchan 14-Jun-17 4:15am    
What is the exception and where does it occur? Also you should open the StreamWriter outside this method and hold it open as long as more data is being received.
Veerendra-13142768 14-Jun-17 4:34am    
actually exception is Occurring because of buffer can hold only byte[100*1024*1024] so i want to clear that buffer after copying to temp1 so it will receive data from fx3 continuously.
Richard MacCutchan 14-Jun-17 4:52am    
I suspect that it is more likely that your index into the buffer is going beyond its limit. You need to reset the value of offset each time you copy data from the buffer.

There is a lot of redundant code in your routine above. Why do you need to copy the data from one buffer to another, and then create a string from that, just to write it to the file? Why not just write direct from the original buffer? You know how much data is to be written and where it starts from.
Veerendra-13142768 14-Jun-17 4:59am    
yup it is exceeding the limit when operation is started. so to prevent that
i want to move data from buffer if i did like that mean buffer will be free each time so it can run for long time .any suggestion to do like this if i am correct.else can u guide me little bit.
Richard MacCutchan 14-Jun-17 5:03am    
Like I said, you need to reset the buffer index as soon as you have written the data to the file.

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