[問題] BCB在開啟COM10產生問題
因為我是接手別人寫好的程式,才翻了些書就開始改,所以可能很多基礎沒有打好。
問題是這樣的,在開啟COM時,COM1~9都沒有問題。
但在COM10或更大的數字以上時卻會產生錯誤。
上網google了很久,大部分都找到說是CreateFile將裡面的COMx改成////.//COMx
但是我手上的程式完全沒有用到這一段,看到比較相關的似乎是用TComPortNumber
Comm1->CommPort=TComPortNumber(ComPort->ItemIndex);
我在這邊試著做一些改變,但徒勞無功。
雖然有註解,但我還是不太了解網路上找到的這段。
CreateFile(
"//.//COM10", // address of name of the communications device
fdwAccess, // access (read-write) mode
0, // share mode
NULL, // address of security descriptor
OPEN_EXISTING, // how to create
0, // file attributes
NULL // handle of file with attributes to copy
);
關於開啟COM10~不知道有沒有哪位大大願意解釋一下,謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.138.227.152
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1412265619.A.EEA.html
推
10/03 05:57, , 1F
10/03 05:57, 1F
→
10/03 05:57, , 2F
10/03 05:57, 2F
我不太清楚要加在哪邊,我的程式碼是這一段
看起來都像是只用到數字而已?
void __fastcall TForm1::Button3Click(TObject *Sender)
{
// if (Comm1->PortOpen)
// {Comm1->PortOpen=false;}
Comm1->CommPort=TComPortNumber(ComPort->ItemIndex);
Comm1->RThreshold=11;
//-----------default----------------
Comm1->BaudRate=br1200;
Comm1->DataBits=DB8;
Comm1->HwHandShaking=hhNone;
Comm1->SwHandShaking=shNone;
Comm1->Parity=None;
Comm1->StopBits=SB1;
//----------------------------------
if (Comm1->PortOpen)
{
Comm1->PortOpen = false;
Button3->Caption="Open";
}
else
{
Comm1->PortOpen = true;
Button3->Caption="Close";
}
StatusBar1->SimpleText = "Status: Link to
Com"+IntToStr(ComPort->ItemIndex+1)+" 1200,8,N,1"; //COM寫入數值
}
推
10/03 12:29, , 3F
10/03 12:29, 3F
推
10/03 12:31, , 4F
10/03 12:31, 4F
額外再加這一行的意思嗎?因為1-9都沒用到
※ 編輯: sakido (140.138.227.152), 10/03/2014 12:39:59
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):