Jump to content
Sign in to follow this  
mario52

Martin's UDF - Dale's Dialer

Recommended Posts

mario52

Hello,

I'm experiencing some trouble using Martin's UDF to place a call, same with Dale's dialer script. I got with both an error com port. My modem com port is set on 219, it's high and not common to have such a high port number but I git daily new devices plugged in my system making the port number rising. After some investigations, it seems that the port cannot be set higher than 16 using the mscomm.ocx old vb6 component. I may be wrong and asking your opinion about it.

I wonder if the same apply to Martin's UDF ?

I'm using the codes below :

Martin's UDF test :

#include "commMG.au3"

HotKeySet("^!q", "Finish")      ; CTRL-ALT-Q to exit

Func Finish()
    _Commcloseport()
    Exit
EndFunc

Local $setport = 219      ;; adapt to the actual port number!
Local $sportSetError


 _CommSetPort($setport, $sportSetError, 115200, 8, 0, 1, 2)

if $sportSetError <> '' Then ; if $sportSetError = '' then connection to COMPORT is established
    MsgBox(262144, 'Setport error = ', $sportSetError) ; cannot connect to COMPORT
EndIf

Local $command, $instr

While 1
    $command = InputBox("Toy modem example", "Enter the command you wish to send:")
    If @error = 1 Then Finish()     ; Click Cancel to exit (or hotkey)

    _CommSendString($command & @CR) ; sent command line to the modem (don't wait)
    Sleep(50)       ; don't rush, the modem need some time to proceed

    ; receive multi-line answer until time-out
    $instr = ''
    Do
        ; receive a line or time-out
        ; since many answers are multi-line we need to loop there until we don't receive anymore
        Do
            $instr &= _CommGetline(@cr, 32384, 250)
        Until @error = -2       ; timeout
    Until $instr <> ''      ; here we should really wait for the final status answer (OK or else)

    MsgBox(0, "Modem answer was:", $instr)
WEnd

Martin's code error is :

MsgBox(262144, 'Setport error = ', $sportSetError) ; cannot connect to COMPORT

Dale's dialer script test :

; Set a COM Error handler -- only one can be active at a time (see helpfile)
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$sNumberToDial = "+42...."
Dial($sNumberToDial)

Exit

Func Dial($pNum, $time2wait = 5000)
    
    dim $FromModem = ""
    $DialString = "ATDT" & $pNum & ";" & @CR
    
;   $com = ObjCreate ("MSCommLib.MSComm")
    $com = ObjCreate ("NETCommOCX.NETComm")

    With $com
        .CommPort = 219
        .PortOpen = True
        .Settings = "9600,N,8,1"
        .InBufferCount = 0
        .Output = $DialString
    EndWith

    $begin = TimerInit()
    While 1
        If $com.InBufferCount Then
            $FromModem = $FromModem & $com.Input;* Check for "OK".
            If StringInStr($FromModem, "OK") Then ;* Notify the user to pick up the phone.
                MsgBox(0, "Phone", "Please pick up the phone and either press Enter or click OK")
                ExitLoop
            EndIf
        EndIf
        If (TimerDiff($begin) > $time2wait) Then
            MsgBox(0, "Error", "No response from modem on COM" & $com.CommPort & " in " & $time2wait & " milliseconds")
            Exit
        EndIf
    WEnd

    $com.Output = "ATH" & @CR
    $com.PortOpen = False
    $com = 0
    
EndFunc  ;==>Dial

Func MyErrFunc()
; Set @ERROR to 1 and return control to the program following the trapped error
    SetError(1)
    MsgBox(0, "Error", "Error communicating with modem on COM" );& $com.CommPort)
    Exit
EndFunc  ;==>MyErrFunc

Netcommocx installed.

Dale's script error is :

MsgBox(0, "Error", "Error communicating with modem on COM" );& $com.CommPort)

Thanks for your help.

Share this post


Link to post
Share on other sites
mario52

I finally managed to make it work by decreasing the com port. Thgouh I cannot place a call with Martin's UDF, because the call hang up just after I send the _commstring ("ATDT+42.....

Any help please ?

Share this post


Link to post
Share on other sites
martin

I finally managed to make it work by decreasing the com port. Thgouh I cannot place a call with Martin's UDF, because the call hang up just after I send the _commstring ("ATDT+42.....

Any help please ?

I didn't expect anyone to want anything higher than port 99 and so nothing above that number will work. If you need higher I can send you a fix to try. PM me if you want to do that because I might miss a reply in this thread, or post in the thread for my udf because I check that fairly regularly.

If you are using a port number below 99 then I don't know why it doesn't work.

martin


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
mario52

Hi Martin,

Thanks for your reply. In fact I managed to reset my com ports so that my devices start from com port 0. In case someone need the trick I've used a software called USBDEVIEW, selected all devices and uninstalled them.

I finaly set to 0 the registry value :

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter key

99 is a fair enough limit, I will just delete the old devices regularly so the com ports won't exceed 99, maybe someone would be intersted in a fix though. It's kind enough from you to reply :)

Could you please help me to place a call correctly ? The following command, start the call but hang up instantly.

#include "commMG.au3"

_Commcloseport()
$setport = 4     ;; adapt to the actual port number!
Local $sportSetError

_CommSetPort($setport, $sportSetError, 115200, 8, 0, 1, 2)

if $sportSetError <> '' Then ; if $sportSetError = '' then connection to COMPORT is established
    MsgBox(262144, 'Setport error = ', $sportSetError) ; cannot connect to COMPORT
EndIf

; Call
_CommSendString("ATDT0042782xxx" & @CR) ; sent command line to the modem (don't wait)
  Sleep(5000)

I tried to put a sleep afterward but has no effect, I may not use correctly the UDF.

Thank you.

Edited by mario52

Share this post


Link to post
Share on other sites
martin

Hi Martin,

Thanks for your reply. In fact I managed to reset my com ports so that my devices start from com port 0. In case someone need the trick I've used a software called USBDEVIEW, selected all devices and uninstalled them.

I finaly set to 0 the registry value :

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter key

99 is a fair enough limit, I will just delete the old devices regularly so the com ports won't exceed 99, maybe someone would be intersted in a fix though. It's kind enough from you to reply :)

Could you please help me to place a call correctly ? The following command, start the call but hang up instantly.

#include "commMG.au3"

_Commcloseport()
$setport = 4    ;; adapt to the actual port number!
Local $sportSetError

_CommSetPort($setport, $sportSetError, 115200, 8, 0, 1, 2)

if $sportSetError <> '' Then ; if $sportSetError = '' then connection to COMPORT is established
    MsgBox(262144, 'Setport error = ', $sportSetError) ; cannot connect to COMPORT
EndIf

; Call
_CommSendString("ATDT0042782xxx" & @CR) ; sent command line to the modem (don't wait)
  Sleep(5000)

I tried to put a sleep afterward but has no effect, I may not use correctly the UDF.

Thank you.

I don't think there is anything wrong with th eway you use the udf. If your script makes the modem dial then you must be very close to making it work.

I hav eno experience of using a modem so I can't give much advice. I would try using a terminal emulator, something like hyperterminal or the example with my udf, and send the AT commands to see if that works. Assuming you can get things working that way then reproduce what you did in the script.

If you are sure that the commands are sent correctly and the modem still hangs up as soon as it has dialled then I would expect that there is some setting which needs to be adjusted in the modem before you dial.

Maybe you need to send

S30=0

to disable the Inactivity Disconnect Timer, or something like that. No doublt when you get it to work it will be because of some very simple thing but these simple things are usually difficult to find.

Maybe instead of

ATDT0042..

you need

ATDTW;0042....

or some variation. I imagine the documentation for the modem gives examples though. It would also be worth trying a different modem if that is possible, and perhaps read any respons from the modem with _CommGetString or _CommGetLine in case there is any usefule reply.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
mario52

Hi Martin,

I looked to the modem documentation and I missed a semi-column

;
at the end of the command, that's what maked it hang up instantly. My call finally goes on.

Now what i'm trying to do before calling is that I sent an ATH command to initiate a hang-up sequence. The modem reply by "OK" which I want to get before placing my call, so here is the script I'm using :

#include "commMG.au3"

_Commcloseport()
$setport = 4     ;; adapt to the actual port number!
Local $sportSetError

; Configurer le port
_CommSetPort($setport, $sportSetError, 115200, 8, 0, 1, 1)

if $sportSetError <> '' Then ; if $sportSetError = '' then connection to COMPORT is established
    MsgBox(262144, 'Setport error = ', $sportSetError) ; cannot connect to COMPORT
EndIf

; Disables command echo of characters to computer
_CommSendString("ATE0" & @CR)
sleep (100)

; Hang Up
_CommSendString("ATH" & @CR)
sleep (100)

 _CommClearOutputBuffer()

Do
$return = _Commgetstring()
Until $return <> ""

If $return = "OK" Then
    MsgBox(0, "Ok detected:", $return)
    Else
    MsgBox(0, "Modem answer was:", $return)
EndIf

For debugging purpose I've set a msgbox to read the $return value. I always got returned this one :

MsgBox(0, "Modem answer was:", $return)

which give me the following :

ATE0
OK
OK

Posted Image

Is there any mean to catch only the OK issuing by the ATH command ?

i'm not very advanced in autoit, sorry if my question is quite novice.

Thank you.

Share this post


Link to post
Share on other sites
martin

Hi Martin,

I looked to the modem documentation and I missed a semi-column

;
at the end of the command, that's what maked it hang up instantly. My call finally goes on.

Now what i'm trying to do before calling is that I sent an ATH command to initiate a hang-up sequence. The modem reply by "OK" which I want to get before placing my call, so here is the script I'm using :

#include "commMG.au3"

_Commcloseport()
$setport = 4    ;; adapt to the actual port number!
Local $sportSetError

; Configurer le port
_CommSetPort($setport, $sportSetError, 115200, 8, 0, 1, 1)

if $sportSetError <> '' Then ; if $sportSetError = '' then connection to COMPORT is established
    MsgBox(262144, 'Setport error = ', $sportSetError) ; cannot connect to COMPORT
EndIf

; Disables command echo of characters to computer
_CommSendString("ATE0" & @CR)
sleep (100)

; Hang Up
_CommSendString("ATH" & @CR)
sleep (100)

 _CommClearOutputBuffer()

Do
$return = _Commgetstring()
Until $return <> ""

If $return = "OK" Then
    MsgBox(0, "Ok detected:", $return)
    Else
    MsgBox(0, "Modem answer was:", $return)
EndIf

For debugging purpose I've set a msgbox to read the $return value. I always got returned this one :

MsgBox(0, "Modem answer was:", $return)

which give me the following :

ATE0
OK
OK

Posted Image

Is there any mean to catch only the OK issuing by the ATH command ?

i'm not very advanced in autoit, sorry if my question is quite novice.

Thank you.

You can wait fo rth ereply to each command bfore issuing the next, or you split the string containing al the replies. The way you showed above you got the string for all the replies after sending all the commands. This can work but it means you don't relize when someting has gone wrong as soon as you should.

Here is what I would do but simplified because I haven't checked @error after a _CommGetLine say but it shows the basic method.

#include "commMG.au3"


$setport = 4    ;; adapt to the actual port number!
Local $sportSetError

; Configurer le port
_CommSetPort($setport, $sportSetError, 115200, 8, 0, 1, 1)

if $sportSetError <> '' Then ; if $sportSetError = '' then connection to COMPORT is established
    MsgBox(262144, 'Setport error = ', $sportSetError) ; cannot connect to COMPORT
EndIf
_CommClearInputBuffer();probably not needed but it ensures that we start without confusing unexpected characters.
; Disables command echo of characters to computer
_CommSendString("ATE0" & @CR)
$ReplyA = _CommGetLine(@CR, 0 , 2000);get the echo to last command
;get the result
$ReplyA = _CommGetLine(@CR, 0 , 2000); better to have a max timeout set so that the script doesn't hang

; Hang Up
_CommSendString("ATH" & @CR)
;get the result
$return = _CommGetLine(@CR, 0 , 2000)
 _CommClearOutputBuffer()


If $return = "OK" Then
    MsgBox(0, "Ok detected:", $return)
    Else
    MsgBox(0, "Modem answer was:", $return)
EndIf

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
mario52

You can wait fo rth ereply to each command bfore issuing the next, or you split the string containing al the replies. The way you showed above you got the string for all the replies after sending all the commands. This can work but it means you don't relize when someting has gone wrong as soon as you should.

Here is what I would do but simplified because I haven't checked @error after a _CommGetLine say but it shows the basic method.

#include "commMG.au3"


$setport = 4    ;; adapt to the actual port number!
Local $sportSetError

; Configurer le port
_CommSetPort($setport, $sportSetError, 115200, 8, 0, 1, 1)

if $sportSetError <> '' Then ; if $sportSetError = '' then connection to COMPORT is established
    MsgBox(262144, 'Setport error = ', $sportSetError) ; cannot connect to COMPORT
EndIf
_CommClearInputBuffer();probably not needed but it ensures that we start without confusing unexpected characters.
; Disables command echo of characters to computer
_CommSendString("ATE0" & @CR)
$ReplyA = _CommGetLine(@CR, 0 , 2000);get the echo to last command
;get the result
$ReplyA = _CommGetLine(@CR, 0 , 2000); better to have a max timeout set so that the script doesn't hang

; Hang Up
_CommSendString("ATH" & @CR)
;get the result
$return = _CommGetLine(@CR, 0 , 2000)
 _CommClearOutputBuffer()


If $return = "OK" Then
    MsgBox(0, "Ok detected:", $return)
    Else
    MsgBox(0, "Modem answer was:", $return)
EndIf

Thank you Martin for you great help !

Share this post


Link to post
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
Sign in to follow this  

×