COM PORT 連結的疑問 |
尚未結案
|
yjh0225
一般會員 發表:7 回覆:7 積分:2 註冊:2003-10-13 發送簡訊給我 |
hCom1=CreateFile("COM1", //串口號 我是以此方式連接上 COM1 的設備。 (hCom1 == INVALID_HANDLE_VALUE) 就會成立,連接不上COM10了 經過測試COM1 ~ COM9均可以正常連線,不知為什麼變成2位數以上的com port時就會結接失敗了。 煩請各位大大給予解答指教。 |
yjh0225
一般會員 發表:7 回覆:7 積分:2 註冊:2003-10-13 發送簡訊給我 |
我找到解答了!! CreateFile() can be used to get a handle to a serial port. The "Win32 Programmer's Reference" entry for "CreateFile()" mentions that the share mode must be 0, the create parameter must be OPEN_EXISTING, and the template must be NULL. CreateFile() is successful when you use "COM1" through "COM9" for the name of the file; however, the message "INVALID_HANDLE_VALUE" is returned if you use "COM10" or greater. If the name of the port is \\.\COM10, the correct way to specify the serial port in a call to CreateFile() is as follows: 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 ); NOTES: This syntax also works for ports COM1 through COM9. Certain boards will let you choose the port names yourself. This syntax works for those names as well. |
Ktop_Robot
站務副站長 發表:0 回覆:3511 積分:0 註冊:2007-04-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |