Jump to content

Get port number to variable


Recommended Posts

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 by JLogan3o13
Link to comment
Share on other sites

  • Moderators

@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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

@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 by SAM1386
forgot to quote
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...