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

C++Builder 透過rs232開啟com的問題

尚未結案
753951
一般會員


發表:2
回覆:0
積分:0
註冊:2005-01-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-06 10:43:40 IP:219.68.xxx.xxx 未訂閱
char *ComNo; DCB dcb; String Temp; //取得欲開啟的通訊埠 Temp = "COM" IntToStr(rdCOM->ItemIndex 1); //轉換至指標型態Char ComNo = Temp.c_str(); hComm = CreateFile(ComNo,GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); if (hComm == INVALID_HANDLE_VALUE) // 如果COM 未開啟 { MessageBox(0, "開啟通訊埠錯誤!!","Comm Error",MB_OK); return; } //將dcb位址傳入,以取得通訊參數 GetCommState(hComm,&dcb); // 得知目前COM 的狀態 dcb.BaudRate = CBR_9600; // 設定鮑率為9600 dcb.ByteSize = 8; // 位元組為 8 bit dcb.Parity = NOPARITY; // Parity 為 None dcb.StopBits = ONESTOPBIT; // 1 個Stop bit //通訊埠設定 if (!SetCommState(hComm, &dcb)) { // 設定COM 的狀態 MessageBox (0, "通訊埠設定錯誤!!!","Set Error",MB_OK); CloseHandle(hComm); return; } Read232->Resume(); } 上面哪段程式DCB是什麼東西 還有這段 ComNo = Temp.c_str(); hComm = CreateFile(ComNo,GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); if (hComm == INVALID_HANDLE_VALUE) // 如果COM 未開啟 { MessageBox(0, "開啟通訊埠錯誤!!","Comm Error",MB_OK); return; } 可不可以解釋一下..我看不到.請大家幫個忙..謝謝
blk5743
高階會員


發表:34
回覆:371
積分:236
註冊:2003-11-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-06 11:00:55 IP:61.66.xxx.xxx 未訂閱
上面哪段程式DCB是什麼東西 typedef struct _DCB { DWORD DCBlength; // DCB 的大小 (in byte) DWORD BaudRate; // 傳輸率 (baud rate) bit/秒 DWORD fBinary: 1; // 二進制模式,沒有 EOF 檢查. DWORD fParity: 1; // 同位元檢查 (parity checking) DWORD fOutxCtsFlow:1; // CTS output flow control DWORD fOutxDsrFlow:1; // DSR output flow control DWORD fDtrControl:2; // DTR flow control type DWORD fDsrSensitivity:1; // DSR sensitivity DWORD fTXContinueOnXoff:1; // XOFF continues Tx DWORD fOutX: 1; // XON/XOFF out flow control DWORD fInX: 1; // XON/XOFF in flow control DWORD fErrorChar: 1; // enable error replacement DWORD fNull: 1; // enable null stripping DWORD fRtsControl:2; // RTS flow control DWORD fAbortOnError:1; // abort reads/writes on error DWORD fDummy2:17; // reserved WORD wReserved; // not currently used WORD XonLim; // transmit XON threshold WORD XoffLim; // transmit XOFF threshold BYTE ByteSize; // 每一筆資料的 bit 數, 4-8 BYTE Parity; // 同位元 (0-4) = 無,奇同位,偶同位,mark,space BYTE StopBits; // 停止位元 (0,1,2) = 1, 1.5, 2 char XonChar; // Tx and Rx XON character char XoffChar; // Tx and Rx XOFF character char ErrorChar; // error replacement character char EofChar; // end of input character char EvtChar; // received event character WORD wReserved1; // reserved; do not use } DCB; Temp = "COM" IntToStr(rdCOM->ItemIndex 1); ComNo = Temp.c_str(); 取得字串如"COM1","COM2"... hComm = CreateFile(ComNo,GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); [red]取得Com Port相對應的控制碼 HANDLE CreateFile( LPCTSTR lpFileName, // pointer to name of the file DWORD dwDesiredAccess, // access (read-write) mode DWORD dwShareMode, // share mode LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security attributes DWORD dwCreationDistribution, // how to create DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // handle to file with attributes to copy );
系統時間:2024-06-28 18:57:12
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!