2009-07-23 2 views
0

함께 작동하는 두 가지 방법이 있으며 큰 배수 배열 (매 1/1000000S 5000 항목)을 만들고이 배열에는 차트 (Dundas 차트)가 표시되어야합니다. 그러나 차트가 업데이트되지 않습니다.도움 차트 업데이트

도와주세요!

내 나쁜 영어로 죄송합니다.

이 내 코드 :

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using System.IO; 
using System.Runtime.InteropServices; 
using System.Threading; 
using Dundas.Charting.WinControl; 
using Dundas.Charting.WinControl.Utilities; 


namespace Online_Detector 
{ 
    public partial class frmMain : Form 
    { 
     public frmMain() 
     { 
      InitializeComponent(); 
     } 

     #region Fields 
     double fName = 0; 
     public object dataDigitalGlobal; 
     long num; 
     #endregion 

     #region Method 
     private void ManualSavetoFile(double Value, double Time) 
     { 
      //Get Path 
      //fName += 1; 
      string IntLocation = Convert.ToString(fName) + ".txt"; 

      #region Write File 

      FileStream FOut = null; 

      try 
      { 

       if (File.Exists(IntLocation)) 
        FOut = new FileStream(IntLocation, FileMode.Append, FileAccess.Write, FileShare.ReadWrite, 4096, true); 
       else 
        FOut = new FileStream(IntLocation, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 4096, true); 

       StreamWriter SOut = new StreamWriter(FOut); 


       // <Add Line To Export File > 
       lock (this) 
       { 
        if (FOut.CanWrite) 
        { 
         SOut.WriteLine(Value); 
         SOut.WriteLine(Time); 
        } 
       } 
       // <Add Line To Export File > 

       SOut.Close(); 
       FOut.Close(); 

      } 

      catch (IOException Err) 
      { 
       MessageBoxManager.OK = "&تاييد"; 
       MessageBoxManager.Register(); 
       MessageBox.Show("خطاي زير در عمليات تهيه فايل خروجي رخ داد:" + "\r" + Err.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); 
       MessageBoxManager.Unregister(); 
      } 

      catch (FieldAccessException Err) 
      { 
       MessageBoxManager.OK = "&تاييد"; 
       MessageBoxManager.Register(); 
       MessageBox.Show("خطاي زير در عمليات تهيه فايل خروجي رخ داد:" + "\r" + Err.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); 
       MessageBoxManager.Unregister(); 
      } 

      catch (Exception Err) 
      { 
       MessageBoxManager.OK = "&تاييد"; 
       MessageBoxManager.Register(); 
       MessageBox.Show("خطاي زير در عمليات تهيه فايل خروجي رخ داد:" + "\r" + Err.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading); 
       MessageBoxManager.Unregister(); 
      } 

      finally 
      { 
       FOut.Close(); 
      } 

      #endregion //Write File 

     } 
     #endregion 

     #region Event on Tab Report 
     private void btnStart_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       //check all the setting 
       axAdvAICtrl.ChannelScanStart = Convert.ToInt32(txtChannelStart.Text); 
       axAdvAICtrl.ChannelScanCount = Convert.ToInt32(txtChannelCount.Text); 

       int count = int.Parse(txtDataCount.Text); 

       // Ocx allocate the buffer of DataDigital ,equal to new object!    
       dataDigitalGlobal = null; 
       // Engage the FAI with Asychronous mode 
       count = axAdvAICtrl.AcquireBulkDataToMemory(count, out dataDigitalGlobal, -1, chkCylic.Checked, false); 
       num = 0; 
       // Disable all controls on the form 
       btnStart.Enabled = false; 
       // and only Enable the Stop button 
       btnEnd.Enabled = true; 
      } 
      catch (Exception err) 
      { 
       MessageBox.Show(err.Message, "Error"); 
       axAdvAICtrl.StopAcquireBulkData(0); 
      } 

     } 

     private void btnEnd_Click(object sender, EventArgs e) 
     { 
      //stop the acquisition 
      axAdvAICtrl.StopAcquireBulkData(0); 

      // Enable all controls on the form 
      btnStart.Enabled = true; 
      // and only Disable the Stop button 
      btnEnd.Enabled = false; 
     } 

     #endregion 
     //this event every 1/500000 
     private void axAdvAICtrl_OnFirstHalfBulkDataReady(object sender, AxAdvAILib._IAdvAIEvents_OnFirstHalfBulkDataReadyEvent e) 
     { 
      #region "Get Data " 
      try 
      { 
       object analogArray = e.analogArray; 
       long i; 

       if (analogArray != null) 
       { 
        float[] voltage; 
        voltage = (float[])analogArray; 
        for (i = 0; i < Convert.ToInt32(txtDataCount.Text)/2; i++) 
        { 
         // Write Data To Manual file 
         ManualSavetoFile(voltage[i], (num/axAdvAICtrl.DataSampleRate)); 

         // Define some variables 
         int numberOfPointsInChart = Convert.ToInt32(txtDataCount.Text); 
         int numberOfPointsAfterRemoval = 1; 

         chaIon.Series["Series1"].Points.AddXY(xValue[arrayCounter], yValue[arrayCounter]); 

         // Keep a constant number of points by removing them from the left 
         while (chaIon.Series[0].Points.Count > numberOfPointsInChart) 
         { 
          // Remove data points on the left side 
          while (chaIon.Series[0].Points.Count > numberOfPointsAfterRemoval) 
          { 
           chaIon.Series[0].Points.RemoveAt(0); 
          } 

         } 
         chaIon.Invalidate(); 
         num++; 
        } 
       } 
      } 
      catch (Exception err) 
      { 
       threadChart.Abort(); 
       MessageBox.Show(err.Message, "Error"); 
      } 
      #endregion 
     } 

     //this event every 1/500000 
     private void axAdvAICtrl_OnSecondHalfBulkDataReady(object sender, AxAdvAILib._IAdvAIEvents_OnSecondHalfBulkDataReadyEvent e) 
     { 
      #region "Get Data " 
      try 
      { 
       object analogArray = e.analogArray; 
       long i; 

       if (analogArray != null) 
       { 
        float[] voltage; 
        voltage = (float[])analogArray; 
        for (i = 0; i < Convert.ToInt32(txtDataCount.Text)/2; i++) 
        { 
         // Write Data To Manual file 
         ManualSavetoFile(voltage[i], (num/axAdvAICtrl.DataSampleRate)); 

         // Define some variables 
         int numberOfPointsInChart = Convert.ToInt32(txtDataCount.Text); 
         int numberOfPointsAfterRemoval = 1; 

         chaIon.Series["Series1"].Points.AddXY(xValue[arrayCounter], yValue[arrayCounter]); 

         // Keep a constant number of points by removing them from the left 
         while (chaIon.Series[0].Points.Count > numberOfPointsInChart) 
         { 
          // Remove data points on the left side 
          while (chaIon.Series[0].Points.Count > numberOfPointsAfterRemoval) 
          { 
           chaIon.Series[0].Points.RemoveAt(0); 
          } 

         } 
         chaIon.Invalidate(); 
         num++; 
        } 
       } 
      } 
      catch (Exception err) 
      { 
       threadChart.Abort(); 
       MessageBox.Show(err.Message, "Error"); 
      } 
      #endregion 
     } 

     private void frmMain_FormClosing(object sender, FormClosingEventArgs e) 
     { 
      axAdvAICtrl.StopAcquireBulkData(0); 
     } 
    } 
} 
+0

몇 가지 예제 코드를 제공 할 수 있습니까? –

+0

게시 코드를 시도해보십시오. 우리가 어떤 것을 볼 때까지 어떤 일이 벌어지고 있는지 알 수 없습니다. – AlbertoPL

+0

일부 코드의 예가 유용합니다. – AnthonyWJones

답변

1

일반적으로 UI 구성 요소에 대한 업데이트가 Control.Invoke를 통해 UI 스레드에서 수행 (또는 WPF에 해당)해야합니다. 변경 사항으로 인해 어딘가에 삼키는 예외가 발생할 수 있습니다.

코드가 UI 스레드에서 작동합니까? BackgroundWorker을 계속 사용할 수 있습니다. Invoke을 통해 업데이트 (이상적으로는 일괄 적으로)를 수행하면됩니다.