線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2386
推到 Plurk!
推到 Facebook!

將取樣資料用 FastLine 畫出會遇到List index out of bounds的問題

缺席
sunwingman
一般會員


發表:26
回覆:47
積分:14
註冊:2008-05-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2016-06-23 10:16:55 IP:101.138.xxx.xxx 訂閱
目前使用 100Hz, -5V~5V, Sine波,  作為我的訊號源

使用DAQ卡取樣, sample rate 200Hz, 取樣數10筆, one channel

現在我用FastLine要將取樣的點畫在Chart上, 程式碼如下:


[code cpp]

//針對Chart屬性先定義, 並動態新增一個series
void __fastcall TForm1::DataOutPrepare()
{
VolChart->BottomAxis->Automatic = false;
VolChart->BottomAxis->Minimum = 0;
VolChart->BottomAxis->Maximum = 9;

VolChart->LeftAxis->Automatic = true;

TFastLineSeries *series = new TFastLineSeries(this);
VolChart->AddSeries(series);
}

//DAQ提供的Callback function, 每取樣10筆當作一次事件進來
int32 CVICALLBACK EveryNCallback(...)
{
Form1->VolChart->Series[1]->Clear();

DAQmxReadAnalogF64(....);

for(int i=0; i<10; i )
Form1->VolChart->Series[1]->Add(data[i*10 1],"",clRed); //取樣的資料都 儲存在data[ ]裡

}
[/code]



但是偶而會產生以下錯誤訊息:
List index out of bounds
如果不管他, FastLine還是會繼續動作, 但最後就會產生 EAccess Violation, 然後程式整個當掉

不知道各位前輩是否有遇過相似的問題?
編輯記錄
sunwingman 重新編輯於 2016-06-23 10:41:52, 註解 無‧
sunwingman 重新編輯於 2016-06-23 10:43:35, 註解 無‧
sunwingman
一般會員


發表:26
回覆:47
積分:14
註冊:2008-05-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2016-06-24 09:11:55 IP:101.138.xxx.xxx 訂閱
花了一個晚上, 自己試出來了


[code cpp]
void __fastcall TForm1::DataOutPrepare()
{
VolChart->BottomAxis->Automatic = false;
VolChart->BottomAxis->Minimum = 0;
VolChart->BottomAxis->Maximum = 9;

VolChart->LeftAxis->Automatic = true;
VolChart->LeftAxis->Increment = 0.01;
//VolChart->LeftAxis->Maximum = 5;
//VolChart->LeftAxis->Minimum = -5;

for(int i=0; i<80; i ){
TFastLineSeries *series = new TFastLineSeries(this);
VolChart->AddSeries(series);
VolChart->Series[i]->FillSampleValues(10); //先把10各點準備好
}

}

int32 CVICALLBACK EveryNCallback(...)
{

for(int i=0; i<80; i ){ //80 channel
for(int j=0; j<10; j ){ //10 samples per channel
Form1->VolChart->Series[i]->YValue[j] = data[j*80 i]; //直接修改10各點即可, 不要用Add, AddY, AddXY...
}
}

}

[/code]

這樣即使有80各Channel同時取樣也不會有問題, 結案!!!
系統時間:2024-04-26 7:43:36
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!