CreateFile開啟串列埠時串列埠名字的寫法

2021-06-07 13:12:23 字數 835 閱讀 1454

開啟com1到com9用:

m_hcom = createfile(_t("com1:"), generic_read | generic_write, 0, null, open_existing, null, null);

或者m_hcom = createfile(_t("com1"), generic_read | generic_write, 0, null, open_existing, null, null);

(第乙個引數有沒有分號都可以)

或者m_hcom = createfile(_t(".//com1"), generic_read | generic_write, 0, null, open_existing, null, null);

(com1後面不能有分號)

開啟com10之後的串列埠

m_hcom = createfile(_t(".//com15"), generic_read | generic_write, 0, null, open_existing, null, null);

在網上查到:

"comx:",

"/$device/comx",

"/$bus/pcmcia_0_0_0"。

其中第一種方式只適合從0~9的裝置名,亦即com10:中10超出了裝置命名規範,所以用createfile開啟裝置失敗。

使用第二種方式/$device/com10,作為引數傳遞給createfile,成功開啟com口,通訊正常,搞定。

第三種是用在匯流排驅動上的,暫時沒涉及到

第二種方法試了好多編,還是沒開啟。

以上結果只在xp平台下測試,串列埠15為usb轉串列埠 vs使用unicode編碼

CreateFile開啟檔案或者開啟目錄

一 開啟目錄 引數列表 lpfilename string 要開啟的檔案的名字 dwdesiredaccess long 如果為 generic read 表示允許對裝置進行讀訪問 如果為 generic write 表示允許對裝置進行寫訪問 可組合使用 如果為零,表示只允許獲取與乙個裝置有關的資訊...

CreateFile在串列埠中的運用

在32位的windows系統中,串列埠和其他通訊裝置是作為檔案處理的。對串列埠的操作和對檔案的操作是完全一樣的。通訊以呼叫createfile 開始。函式原型如下 handle createfile lpctstr lpfilename,指向檔名的指標 dword dwdesiredaccess,訪...

CreateFile開啟磁碟格式要求

handle createfile lpctstrlpfilename dworddwdesiredaccess dworddwsharemode lpsecurity attributeslpsecurityattributes dworddwcreationdisposition dworddw...