全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:4471
推到 Plurk!
推到 Facebook!

利用CreateFile建立RS232,遇到問題了。

尚未結案
hanklin
一般會員


發表:3
回覆:3
積分:1
註冊:2003-03-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-09-03 12:34:52 IP:61.57.xxx.xxx 未訂閱
請教各位大大: 我使用createfile這個API建立RS232,當COMPORT編號小於10時可用,但大於10時如COM13就讀不到了,為什麼呢?有解嗎?謝謝。 hComm = CreateFile("COM13", //com port number GENERIC_READ | GENERIC_WRITE 0, NULL, OPEN_EXISTING, 0, 0);
hanklin
一般會員


發表:3
回覆:3
積分:1
註冊:2003-03-26

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-09-03 13:24:31 IP:61.57.xxx.xxx 未訂閱
我在網路上search到以下片段文章,有人看地懂嗎? I am using 16-port serial card and was not able to access serial ports com10 - com18. I have seen a couple of people complaining about the same problem. The cause of the problem is that CreateFile accepts strings "com1" - "com9" as names of devices and reject to do so for two and more digit numbers. In order to open "com10" and above we actually have to feed "\\\\.\\com10" string to CreateFile. The simple fix to winsup/path.cc given below would solve the problem. Can someone integrate this? Stas. bash-2.02$ diff -u path.cc.00 path.cc --- path.cc.00 Wed Oct 27 20:55:55 1999 path.cc Thu Dec 16 14:49:36 1999 @@ -400,7 400,7 @@ "\\dev\\ttym", "\\dev\\tty%d", "\\dev\\ptym", - "com%d", "\\\\.\\com%d", "\\dev\\pipe", "\\dev\\piper", "\\dev\\pipew", bash-2.02$
hanklin
一般會員


發表:3
回覆:3
積分:1
註冊:2003-03-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-09-03 16:36:29 IP:61.57.xxx.xxx 未訂閱
是否有其他的API可以達成Open Comport???
brook
資深會員


發表:57
回覆:323
積分:371
註冊:2002-07-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-09-03 17:16:14 IP:218.160.xxx.xxx 未訂閱
一部電腦要裝2個以上的rs232好像不容易,我想一定有裝卡片,直接問該公司或許會比較快,應該也會有現成的東東吧!
venson0704
一般會員


發表:3
回覆:3
積分:1
註冊:2002-08-29

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-09-16 13:27:00 IP:61.66.xxx.xxx 未訂閱
hComm = CreateFile("\\\\.\\com10", //com port number GENERIC_READ | GENERIC_WRITE 0, NULL, OPEN_EXISTING, 0, 0); 這樣子就可以了
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-09-16 15:42:26 IP:61.218.xxx.xxx 未訂閱

列舉COM port 清單

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   TStrings *Coms = new TStringList();        HANDLE hCom;     
    char chPort[5];  
    memset( chPort, '\0', sizeof( chPort ) );        for (int i=1; i<20; i   )          {    
        sprintf( chPort , "\\\\.\\COM%d" , i );  
       
        hCom = CreateFile( chPort , GENERIC_READ | GENERIC_WRITE , 0 , NULL ,
                                OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , 0 );            if ( hCom != INVALID_HANDLE_VALUE ){Coms->Add( AnsiString(chPort) );
       }         CloseHandle( hCom );
    }        delete Coms;
}    
/*生活是一種藝術,用心生活才能享受生活*/
發表人 - axsoft 於 2003/09/16 15:46:30
系統時間:2024-04-29 3:28:00
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!