Champak Posted February 27, 2012 Share Posted February 27, 2012 Is there a way to close a specific COM port that is in use...not in use by my script? I've looked at the commg udf, but see nothing of use for me. Link to comment Share on other sites More sharing options...
Blue_Drache Posted February 27, 2012 Share Posted February 27, 2012 As martin is actively developing this, I think I'd have to defer to him and possibly ask in his if this is a feature he could add. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
atzoref Posted September 19, 2012 Share Posted September 19, 2012 I have the same question, How can I Open/Close a specific ComPort? Link to comment Share on other sites More sharing options...
FireFox Posted September 19, 2012 Share Posted September 19, 2012 Hi, Code from MKISH : #include <WinAPI.au3> $RESULT = _WinAPI_CreateFile(".COM3", 2, 2) If $RESULT = 0 then msgbox(16, "", "Port not available, please plug in your device") EndIf This is for opening the COM port 3, maybe to close a port you have to open and close it. Hope that helps. Br, FireFox. Link to comment Share on other sites More sharing options...
stormbreaker Posted September 19, 2012 Share Posted September 19, 2012 Some extension to above: #include <WinAPI.au3> $RESULT = _WinAPI_CreateFile(".COM3", 2, 2) msgbox(64, "", "Port opened.") _WinAPI_CloseHandle($RESULT) msgbox(64, "", "Handle closed.") ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
AlainB Posted September 22, 2012 Share Posted September 22, 2012 (edited) Hi, It is not working for me, I mean for the closing of the port. For the opening, It is working well. What could be the problem? Alain #include <WinAPI.au3> Global $Port = "COM1" _OpenAndClosePort() Func _OpenAndClosePort() $Open = _WinAPI_CreateFile($Port, 2, 2) If $Open = False then msgbox(0, "", "The port is not open" ,3) Exit EndIf msgbox(0, "", "The port is open",2) $Closed =_WinAPI_CloseHandle($Port) If $Closed = False then msgbox(0, "", "The port is not closed",3) Exit EndIf msgbox(0, "", "The port is closed",3) EndFunc Edited September 22, 2012 by AlainB Link to comment Share on other sites More sharing options...
stormbreaker Posted September 23, 2012 Share Posted September 23, 2012 _WinAPI_CloseFile() closes a handle created with _WinAPI_CreateFile() (or so). So, you need to do something like:_WinAPI_CloseFile($Open)AND NOT: _WinAPI_CloseFile($Port) Hope, all's clear now... ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
AlainB Posted September 23, 2012 Share Posted September 23, 2012 (edited) Thank you MKISH, very informative post, as usual. It is working now. Here is the edited code:#include <WinAPI.au3> Global $Port = "COM1" _OpenAndClosePort() Func _OpenAndClosePort() Local $Port1 = _WinAPI_CreateFile($Port, 2, 2) If $Port1 = False then msgbox(0, "", "The port is not open" ,3) exit EndIf msgbox(0, "", "The port is open",2) Local $Closed =_WinAPI_CloseHandle($Port1) if $Closed = False then msgbox(0, "", "The port is not closed",3) exit EndIf msgbox(0, "", "The port is closed",3) EndFunc(On edit: It is working for me with _WinAPI_CloseHandle but not with _WinAPI_CloseFile. Is this a typo? It gives the error Unknown function name.) Edited September 23, 2012 by AlainB Link to comment Share on other sites More sharing options...
stormbreaker Posted September 24, 2012 Share Posted September 24, 2012 The error speaks for itself: There is no such function defined in WinAPI UDF (or in Windows probably) ---------------------------------------- :bye: Hey there, was I helpful? ---------------------------------------- My Current OS: Win8 PRO (64-bit); Current AutoIt Version: v3.3.8.1 Link to comment Share on other sites More sharing options...
AlainB Posted September 24, 2012 Share Posted September 24, 2012 (edited) Yes, it is true... when you have acquired a sufficient knowledge on how Autoit is working. The concept of including UDF in a script and what it is doing is not necessary very obvious for a newbee. If one know, he could go under the "Include" sub directory of autoit and see that there is a file called WINAPI.AU3 among many other ones. Opening this file, he will see that the content is a set of functions that may be used when the file is included in a script. When you know all that then yes...the error speaks for itself. Just taking this occasion to try to explain a bit what are included files for others newbees like me. All this is probably in a help file somewhere anyway. Edited September 24, 2012 by AlainB Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now