terry000
一般會員
發表:17 回覆:14 積分:6 註冊:2003-10-22
發送簡訊給我
|
請問一下各位高手大大: 小弟現在有做一個介面是利用8051抓訊號透過rs232經過bcb所寫的程式顯示出來~~~可是現在利用訊號產生器來測試~~發現bcb的介面波形不符合我們所加的頻率~~請問一下問題是出在哪裡呢??
|
李國維
高階會員
發表:42 回覆:287 積分:235 註冊:2003-02-07
發送簡訊給我
|
terry000:
請教一下.你所謂的bcb介面波形是指什麼?
是指收到RS232的訊號解碼後所得的資料,在paint上面有問題.
還是.無法接收到RS232的資料.
|
terry000
一般會員
發表:17 回覆:14 積分:6 註冊:2003-10-22
發送簡訊給我
|
大大~我所指的是編碼過後在paint的問題~~~編碼方面是沒有問題~~~~~~
問題是我使用信號產生器調整頻率~~~~結果paint上的波形變化不一~~~~~~
可以說無法控制~~~~
|
李國維
高階會員
發表:42 回覆:287 積分:235 註冊:2003-02-07
發送簡訊給我
|
terry000:
在請問一下
1.在Panit之前有確認過資料ㄉ正確性嗎?
舉例來說,就是訊號產生器調整頻率後.基本上你所讀到資料也會跟這變化.
如果資料確定正確的話.在處理paint的問題.
2.你paint是用Canvas,還是Chart?
|
terry000
一般會員
發表:17 回覆:14 積分:6 註冊:2003-10-22
發送簡訊給我
|
抓進來的訊號沒有問題~~~~~可是我用chart顯示的時候出現了信號的落差~~~
不知道問題是出在哪裡~~~~
|
terry000
一般會員
發表:17 回覆:14 積分:6 註冊:2003-10-22
發送簡訊給我
|
抓進來的訊號沒有問題~~~~~可是我用chart顯示的時候出現了信號的落差~~~
不知道問題是出在哪裡~~~~
|
李國維
高階會員
發表:42 回覆:287 積分:235 註冊:2003-02-07
發送簡訊給我
|
terry000:
如果方便.請將Chart的Code上傳.
這樣才好除錯.^^
|
andychang1690
資深會員
發表:20 回覆:694 積分:442 註冊:2003-03-14
發送簡訊給我
|
terry000:
我敘述的是我處理交換機上資料的方式,提供你參考!所有RS232進來的
資料我先存入Memo中畫面也顯示出來,我使用多執行緒將Memo中的資料一筆
一筆的運算處理消化再刪除
Form1->Memo1->Lines->Delete(Form1->Memo1->Lines->Count-1);
Memo也可以存成檔案記錄,在處理大量集中的資料時,這種方式比較能確保
資料的運算及不遺失!
在加上Application->ProcessMessages();應用
如果你抓進來的訊號沒有問題,編碼方面是沒有問題,試試第三類方式!
請參考 Andy Chang
------ Andy Chang
|
terry000
一般會員
發表:17 回覆:14 積分:6 註冊:2003-10-22
發送簡訊給我
|
高手大大~程式如下~請過目~ //------------------------------------------------------------------- #include
#pragma hdrstop #include "ch5.h"
//-------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RS232"
#pragma resource "*.dfm"
TForm1 *Form1; //-------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//-------------------------------------------------------------------
float data[501];
int i;
long NowTime;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
NowTime=GetTickCount();
for(i=0;i<=500;i )
{data[i]=0;}
if(C->PortOpen)
{
ShowMessage("port have been opened!");
return;
}
if(rdcom->ItemIndex==0)
C->CommPort=pnCOM1;
else
C->CommPort=pnCOM2;
C->PortOpen=true; Timer1->Enabled=0;
}
//-------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(!C->PortOpen)
C->PortOpen=false;
exit(0);
}
//-------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
/* //測試 ch5中的 傳送十進位 //傳送及接收要用的陣動態列宣告
DynamicArray ByteSend,ByteReceive;
long Count,i; //指定欲傳送的位元組
ByteSend.Length=1;
ByteSend[0]=0x90;
//將每個位元組數值(Strings)以StrToInt存至陣列中
for (i=0;iLines->Count;i )
ByteSend[i]=StrToInt(Memo1->Lines->Strings[i]);
C->OutputByte(ByteSend);//傳送出去
//Delay(100); //延遲100毫秒
//接收位元組資料,直接存進動態陣列中
ByteReceive=C->ReadInputByte();
Edit1->Text=ByteReceive.Length;
//接收的資料指定給接收陣列
for (i=0;iText=Memo2->Text IntToStr(ByteReceive[i]) '\x0d' '\x0a';
*/ /*
String buf;
DynamicArray ByteSend,ByteReceive;
buf="00000001";
C->OutputString(buf); ByteReceive=C->ReadInputByte();
for (i=0;iText=Memo2->Text (ByteReceive[i]) '\x0d' '\x0a';
*/ /*
DynamicArray ByteSend,ByteReceive;
long Count,i; ByteSend.Length = 4;
ByteSend[0] = 0x01;
ByteSend[1] = 0x03;
ByteSend[2] = 0x80;
ByteSend[3] = 0x81; C->OutputByte(ByteSend);
ByteReceive=C->ReadInputByte();
for (i=0;iText=Memo2->Text IntToStr(ByteReceive[i]) '\x0d' '\x0a';
*/ String Buf,Buf1;
int i,j; //Byte 0..255 unsigned 8-bit
Byte Receviebyte[4095]; DynamicArray tempByte; tempByte=C->ReadInputByte(); Memo1->Text=tempByte.Length; if(tempByte.Length!=0)
{
for(i=0;iProcessMessages(); Receviebyte[i]=StrToInt(tempByte[i]);
Buf1=IntToStr(Receviebyte[i]); Buf=IntToStr(tempByte[i]) ';';
Memo2->Text=Memo2->Text Buf " "; //show the data on the picture
int index2;
for(index2=500;index2>=1;index2--)
{data[index2]=data[index2-1];}
data[0]=StrToFloat(Buf1)*5/255; Series1->Clear(); //加入Data至Series1
int index1;
for(index1=0;index1<=500;index1 )
{Series1->AddXY((GetTickCount()-NowTime)/1000,data[index1],"",clRed);} }//end for }//end if
}
//-------------------------------------------------------------------
void __fastcall TForm1::CReceiveData(TObject *Sender)
{ String Buf,Buf1;
int i,j; //Byte 0..255 unsigned 8-bit
byte Receviebyte[5000]; DynamicArray tempByte; tempByte=C->ReadInputByte(); Edit1->Text=tempByte.Length; for(i=0;iText=Memo2->Text Buf " "; //show the data on the picture
int index2;
for(index2=500;index2>=1;index2--)
{data[index2]=data[index2-1];}
data[0]=StrToFloat(Buf1)*5/255; Series1->Clear(); //加入Data至Series1
int index1;
Memo1->Text=(GetTickCount()-NowTime)/100;
for(index1=0;index1<=500;index1 )
{//Series1->AddXY((GetTickCount()-NowTime),data[index1],"",clRed);
Series1->AddY(data[index1],"",clRed);
} } tempByte.Length=0;
C->DataCount=0;
} //------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender)
{
if(C->RThreshold==1)
{
C->RThreshold=0;
Button4->Caption="開始接收";
//Memo1->Text="0";
}
else
{
C->RThreshold=1;
Button4->Caption="停止接收"; }
}
//------------------------------------------------------------------- void __fastcall TForm1::Memo2Change(TObject *Sender)
{ }
//-------------------------------------------------------------------
< >< >
|
andychang1690
資深會員
發表:20 回覆:694 積分:442 註冊:2003-03-14
發送簡訊給我
|
請在所有
{Series1->AddXY((GetTickCount()-NowTime)/1000,data[index1],"",clRed);Application->ProcessMessages();}
加上紅字的Application->ProcessMessages();試試!
請參考! Andy Chang
------ Andy Chang
|
李國維
高階會員
發表:42 回覆:287 積分:235 註冊:2003-02-07
發送簡訊給我
|
terry000:
int index1,index2;
for(index2=500;index2>=1;index2--)
data[index2]=data[index2-1];
data[0]=StrToFloat(Buf1)*5/255;
//如果我猜測沒錯.你上面的程式碼是功能是將資料推疊
//建議你換各方式用vector,會比較快 Series1->Clear(); //加入Data至Series1
Memo1->Text=(GetTickCount()-NowTime)/100;
for(index1=0;index1<=500;index1 )
Series1->AddY(data[index1],"",clRed);
//Chart的顯示沒有錯
結論 :
1.可能是data的處理的時候發生的錯誤.
2.轉型上面發生ㄌ錯誤.
舉例來說
float data;
data = (100 * 5 ) / 255;//結果是Integer
data = float(100*5) / 255; //結果才會是float 妳在仔細看一下Code吧^^
希望多少能對你有所幫助
|