Roach
中階會員
![](./myimg/board/mystar.gif) ![](./myimg/board/mystar.gif)
![](images/icon_photo_none.gif) 發表:61 回覆:104 積分:98 註冊:2002-11-05
發送簡訊給我
|
那個元件該不會是你學長自己寫的吧 ![]()
與其去 >
貼一個給你參考 //--------------------------------------------------------------------------- #>
#>Caption = "Updated in a thread" > sizeof(inbuff) )
{
PurgeComm( hComm,PURGE_RXCLEAR );
return;
} ReadFile( hComm,inbuff,cs.cbInQue,&nBytesRead,NULL );
inbuff[cs.cbInQue]='\0' ; if( cs.cbInQue > 0 )
{
Form1->Label1->Caption = inbuff ;
// Form1->Memo1->Text = Form1->Memo1->Text inbuff ;
} } //--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm" TForm1 *Form1; HANDLE hComm; //---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender)
{
Read232 = new TReadThread(true);
Read232->FreeOnTerminate = true ; char *ComNo ;
DCB dcb;
String Temp="COM2" ;
ComNo = Temp.c_str();
hComm = CreateFile( ComNo,GENERIC_READ | GENERIC_WRITE , 0 , NULL , OPEN_EXISTING , 0 , 0 );
if( hComm == INVALID_HANDLE_VALUE )
{
ShowMessage("開啟通信埠有問題 2 ");
return;
} GetCommState( hComm,&dcb );
dcb.BaudRate = CBR_56000 ;
dcb.ByteSize = 8 ;
dcb.Parity = NOPARITY ;
dcb.StopBits = ONESTOPBIT ; if( !SetCommState(hComm,&dcb) )
{
ShowMessage(" 設定通信埠錯誤 ");
CloseHandle(hComm);
} Read232->Resume(); }
//--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
Read232->Terminate();
if( hComm!=INVALID_HANDLE_VALUE )
CloseHandle(hComm);
exit(EXIT_SUCCESS);
}
//---------------------------------------------------------------------------< >< >< >< > 試車總是問題多
|