SAM1386 Posted April 11, 2017 Posted April 11, 2017 (edited) Hello, I can easily find my modem comport number using the code below:- #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> Global $key = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM","\Device\ssudmdm0000") Local $iError = 0 If @error Then ; The server is probably offline/port is not opened on the server. $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError) Else MsgBox($MB_ SYSTEMMODAL, "MODEM:", $key) EndIf but the thing is I am planning to design a small tool by which it can read the modem COM port and set the COM number and send AT command to modem port using UDF CommMG.au3 created by Martin. I added some below code to martins file :- ;====================================================================================================================== ;CommSendStandard,a new function for sending information to a serial port. ;====================================================================================================================== Func _CommSendStandard($port,$error,$command) _CommSetPort($port,$error,9600,8,0,1,2) if $error <> '' Then MsgBox(262144,'Port Error = ',$error) EndIf _CommSendString($command & @CR) EndFunc ;==>_CommGetLineStates ;=============================================================================================== After adding I wrote the below code for sending AT command to modem port but its not working. Please check the below code and let me know for the issue. ;===================================================================================== #include "C:\Program Files (x86)\AutoIt3\SciTE\CommMG.au3" #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> Global $key = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM","\Device\ssudmdm0000") Local $iError = 0 If @error Then ; The server is probably offline/port is not opened on the server. $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError) Else MsgBox($MB_SYSTEMMODAL, "MODEM:", $key) EndIf Local $port=$key Local $porterror _CommSendStandard($port,$portError,"AT+CFUN=1,1") ;================================================================================================ but If I set the port number by my own in the code (for eg :- port number 8 or any value instead of $key) it works fine and the modem gets reset.I want to know if there is any way to get the port number to a variable $port and discarding so that my above code works fine...In that case user donot have to take care of entering the port manually everytime and the script will automatically read the port number and set itself. Please help Regards, SAM Edited April 11, 2017 by JLogan3o13
Moderators JLogan3o13 Posted April 11, 2017 Moderators Posted April 11, 2017 @SAM1386 Welcome to the forum. Please take notice where you post in the future, I have moved your post to the appropriate forum. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
SAM1386 Posted April 12, 2017 Author Posted April 12, 2017 Someone please reply and help me out of it. Regards, SAM
SAM1386 Posted April 13, 2017 Author Posted April 13, 2017 why there is no response from anyone...Someone please reply and help Regards, SAM
Quesney Posted April 13, 2017 Posted April 13, 2017 Are you getting one of your msgbox answers or is it just going through as if it worked but not changing anything? “Courage is being scared to death, but saddling up anyway” – John Wayne
Quesney Posted April 13, 2017 Posted April 13, 2017 On 4/11/2017 at 8:56 AM, SAM1386 said: Local $port=$key Local $porterror _CommSendStandard($port,$portError,"AT+CFUN=1,1") I am not 100% sure how Autoit handles Capitalization and such but if it sees e and E as different then you could have an issue there “Courage is being scared to death, but saddling up anyway” – John Wayne
SAM1386 Posted April 15, 2017 Author Posted April 15, 2017 (edited) @Quesney :- Thanks for the reply. #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> Global $key = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM","\Device\ssudmdm0000") Local $iError = 0 If @error Then ; The server is probably offline/port is not opened on the server. $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError) Else MsgBox($MB_ SYSTEMMODAL, "MODEM:", $key) EndIf The above mentioned code is giving me the output as "COM5" like $key = COM5 and I want to get that port number 5 like in my case '5' to a variable named $port. So that I can pass that $port number to below function which will reset my UE by AT command "AT+CFUN=1,1" _CommSendStandard($port,$portError,"AT+CFUN=1,1") The thing here is when I write it as :- _CommSendStandard(5,$portError,"AT+CFUN=1,1") ; it works fine. but when I write it like below it donot work fine in run time. _CommSendStandard($port,$portError,"AT+CFUN=1,1") I want $port variable to take the $key value 5 in run time and set the $port value as 5 instead of setting it manually. I think I am unable to make understand my problem :-( Please help. Regards, SAM Edited April 15, 2017 by SAM1386 forgot to quote
SAM1386 Posted April 15, 2017 Author Posted April 15, 2017 On 4/13/2017 at 4:00 PM, Quesney said: I am not 100% sure how Autoit handles Capitalization and such but if it sees e and E as different then you could have an issue there @Quesney :- Thanks for the reply. #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> Global $key = RegRead("HKLM\HARDWARE\DEVICEMAP\SERIALCOMM","\Device\ssudmdm0000") Local $iError = 0 If @error Then ; The server is probably offline/port is not opened on the server. $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Could not connect, Error code: " & $iError) Else MsgBox($MB_ SYSTEMMODAL, "MODEM:", $key) EndIf The above mentioned code is giving me the output as "COM5" like $key = COM5 and I want to get that port number 5 like in my case '5' to a variable named $port. So that I can pass that $port number to below function which will reset my UE by AT command "AT+CFUN=1,1" _CommSendStandard($port,$portError,"AT+CFUN=1,1") The thing here is when I write it as :- _CommSendStandard(5,$portError,"AT+CFUN=1,1") ; it works fine. but when I write it like below it donot work fine in run time. _CommSendStandard($port,$portError,"AT+CFUN=1,1") I want $port variable to take the $key value 5 in run time and set the $port value as 5 instead of setting it manually. I think I am unable to make understand my problem :-( Please help. Regards, SAM
SAM1386 Posted April 15, 2017 Author Posted April 15, 2017 I think the output is "COM5" but $port is taking only integer value 5. Is there any way to separate that "COM" and "5" part from COM5 so That I can give that 5 to $ port. Regards, SAM
232showtime Posted April 15, 2017 Posted April 15, 2017 (edited) $key = "COM5" $sr = StringRight($key, 1) ConsoleWrite($sr & @CRLF) Edited April 15, 2017 by 232showtime ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
SAM1386 Posted April 17, 2017 Author Posted April 17, 2017 On 4/15/2017 at 4:10 PM, 232showtime said: $key = "COM5" $sr = StringRight($key, 1) ConsoleWrite($sr & @CRLF) Thanks for the reply ...It worked for me as exactly I wanted..... Thanks a lot Regards, SAM
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