Re: [問題] BCB在開啟COM10產生問題
我自己在用的code template拿去用吧!!有些元件名請自己對應~~
這段是把可用的com port抓到combobox列出來
TStringList *tmp=new TStringList;
TRegistry *reg=new TRegistry;
reg->RootKey=HKEY_LOCAL_MACHINE;
if(reg->OpenKey("\\HARDWARE\\DEVICEMAP\\SERIALCOMM",false))
{
reg->GetValueNames(tmp);
for(int i=0;i<tmp->Count;i++)
{
AnsiString asCOM=reg->ReadString(tmp->Strings[i]);
int iCOM=asCOM.SubString(4,asCOM.Length()-3).ToIntDef(0);
if(iCOM>0 && iCOM<=255)
{
Combo_Com->Items->Add(asCOM);
}
}
reg->CloseKey();
Combo_Com->ItemIndex = 0;
}
delete reg;
delete tmp;
下面這段就是從combobox選出的com port,然後開啟他
YbCommDevice1->PortNo = Combo_Com->Items->Strings[Combo_Com->ItemIndex].SubString(4,Combo_Com->Items->Strings[Combo_Com->ItemIndex].Length()-3).ToIntDef(0);
YbCommDevice1->Baud = TYbCommDevice::br57600;
YbCommDevice1->Active = true;
上面YbCommDevice1是VCL控件http://www.cppfans.com/
不要花時間用win32 api, 這個控件有經過好幾個工業環境的case驗證,完全沒問題。
※ 引述《sakido (佐米/木子)》之銘言:
: 因為我是接手別人寫好的程式,才翻了些書就開始改,所以可能很多基礎沒有打好。
: 問題是這樣的,在開啟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), 來自: 123.193.158.199
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1412394337.A.F1E.html
※ 編輯: MasterChang (123.193.158.199), 10/04/2014 11:58:21
推
10/06 20:23, , 1F
10/06 20:23, 1F
→
10/06 20:23, , 2F
10/06 20:23, 2F
→
10/06 20:24, , 3F
10/06 20:24, 3F
→
10/06 20:25, , 4F
10/06 20:25, 4F
→
10/06 20:26, , 5F
10/06 20:26, 5F
→
10/06 20:26, , 6F
10/06 20:26, 6F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):