Sign in to follow this  
Followers 0
mario52

Dialing through Netcomm.ocx

7 posts in this topic

Hello Master Coders,

I'm using Dale's code to dial through netcomm.ocx and my modem.

$sNumberToDial = "5551235"
Dial($sNumberToDial)

Exit

Func Dial($pNum, $time2wait = 5000)

    dim $FromModem = ""
    $DialString = "ATDT" & $pNum & ";" & @CR

    $com = ObjCreate ("NETCommOCX.NETComm")

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

    $com.Output = "ATH" & @CR
    $com.PortOpen = False
    $com = 0

EndFunc;==>Dial

The problem is that it doesn't want to hang up until I close autoit3.exe process.

Can somebody please enlight me on how to hang up the call. I point out that :

$com.Output = "ATH" & @CR
    $com.PortOpen = False
    $com = 0

would normally hang up the call but for some reason it's not loaded at all, the script seems to create the netcomm.ocx object and the rest is ignored.

To check out I've used this :

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

$sNumberToDial = "5551235"
Dial($sNumberToDial)

ConsoleWrite ("exit" & @CRLF)
MsgBox (0,"exit","exit")

Exit

Func Dial($pNum, $time2wait = 5000)

    $DialString = "ATDT" & $pNum & ";" & @CR

    $com = ObjCreate ("NETCommOCX.NETComm")

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

MsgBox (0,"read timerinit", "init")

    $begin = TimerInit()
    If (TimerDiff($begin) > $time2wait) Then
        ConsoleWrite ("No response from modem on COM" & $com.CommPort & " in " & $time2wait & " milliseconds")
        Exit
    EndIf

MsgBox (0,"ATH", "ATH")

    sleep (15000)

    $com.Output = "ATH" & @CR
    $com.PortOpen = False
    $com = 0

MsgBox (0,"end of mission", "end of mission")
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

and none of my consolewrite nor msgboxes appaeared.

I'm just missing the hang up function, if somebody could help me that would be greatly appreciated.

Thank you guys.

Share this post


Link to post
Share on other sites



Remembering back to my BBS days, don't you need the escape sequence to be sent before you can get back into command mode? Plus you need to make sure that the "guard time" has elapsed before and after sending the escape sequence (+++) if modems still use that to differentiate the commands from the data being sent. Default guard time was 1 second.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Remembering back to my BBS days, don't you need the escape sequence to be sent before you can get back into command mode? Plus you need to make sure that the "guard time" has elapsed before and after sending the escape sequence (+++) if modems still use that to differentiate the commands from the data being sent. Default guard time was 1 second.

Hi BrewManNH,

Thank you for your answer, though I'm not sure where to put the escape sequence, I tried :

$sNumberToDial = "5551235,+++"

and

With $com
        .CommPort = 4
        .PortOpen = True
        .Settings = "9600,N,8,1"
        .InBufferCount = 0
        .Output = $DialString
        .input = "+++"

with no luck but I'm pretty sure I'm not using it correctly. Any clue where to put that escape sequence ?

Thank you.

Share this post


Link to post
Share on other sites

You need to put the escape sequence before the ATH command, use something like this (untested).

Sleep(1000)
    $com.Output = "+++" 
    Sleep(1000)
    $com.Output = "ATH" & @CR
    $com.PortOpen = False
    $com = 0
    MsgBox(0, "end of mission", "end of mission")

That sleeps for 1 second, sends the escape sequence and sleeps for another second before sending the hangup command. I am guessing on how to send the string to the modem and I just used the code shown that sends commands to it, so modify that part as needed. Just make sure that you have the Sleep(1000) before and after the escape sequence before sending the hangup command. You may need to adjust the second Sleep command if it isn't seeing the hangup command because it may take a few milliseconds before it switches to command mode, just keep it to at least 1000 milliseconds.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

$sNumberToDial = "123456789"
Dial($sNumberToDial)

Exit

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

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

    $begin = TimerInit()
    While 1
        If $com.InBufferCount Then
            $FromModem = $FromModem & $com.InputData;* 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

    sleep (10000)
    $com.Output = "+++"
    sleep (10000)
    $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

The escape sequence do not make a change :)

The script keep running even if the call has hanged up by the other person. The only way to hang up the modem is still to processclose autoit3.exe...

Closing the script by the tray icon do not work as the modem is still running, maybe an issue with the netcomm.ocx ?

Thank you for your help.

Edited by mario52

Share this post


Link to post
Share on other sites

You might want to try sending the commands through the serial port using Martin's Serial Port UDF instead. I am not familiar with the code you're using currently, so this might be another thing to try.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thank you I have seen this UDF earlier but way too complicated for me. I don't understand anything :)

Nevermind thank you. Maybe someone who has used the Netcomm.ocx before will read this post by chance and sort the problem out. Thank you for your much appreciated help mate.

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  
Followers 0