Sign in to follow this  
Followers 0
mashenden

Help Modifying Script That Uses NETComm OCX

30 posts in this topic

I am trying to write a script that detects ringing on the dial-up modem. I have played with DaleHohm's COM phone dialer script and it works on my PC so I know I have the NETComm OCX installed properly. I have also boned up on my rusty programming skills to refresh the use of While, If, Case, Func etc thanks to a respectible overview on:

http://www.edgeofnowhere.cc/viewtopic.php?p=1166419.

As near as I can tell I need to use EvRing to detect ringing per JoseLB's post on the same phone dialer topic

http://www.autoitscript.com/forum/index.php?showtopic=19769

In a subsequent post DaleHohm says "In AutoIt you'll need to use ObjEvent to set up a COM event handler. Take a look at the helpfile... it is pretty straight forward and similar to the VBS handler." I think my shortocming is that I just do not understand what or how to use ObjCreate, ObjEvent, etc,. The Helpfile is greek. So what is probably straight forward to someone that knows programming, my rusty skill level has resulted in hours invested but no results... not out of lack for trying.

Any help would be appreciated. I am willing to put in the time and post any accomplishments in a well documented manner so others can learn.

Thanks in advance. Here is my latest effort in modifying the original script...

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

$sNumberToDial = "5551212"
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

MsgBox(0, "test1", "1")               ; Program runs to this point
    
    $com2 = ObjEvent ("NETCommOCX.NETComm")  
    With $com2
        $DetRing=$com2.EvRing             ; This section is where I am stabbbing in the dark ??
        MsgBox(0, "EvRing", $DetRing )
    EndWith

MsgBox(0, "test2", "2"); modem times out before this line is ever executed.

    $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

    $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

Matt A

Share this post


Link to post
Share on other sites



I don't know anything about that interface, but I think however it works out will be more like this:

$com = ObjCreate("NETCommOCX.NETComm")

$com2 = ObjEvent($com, "_NETComEvents_", "InterfaceName???")

Func _NETComEvents_EvRing($Any, $Parameters = "?")
    MsgBox(64, "Ring", "Brrrrrrrring!")
EndFunc   ;==>_NETComEvents_EvRing

If you look at the example using IE in the help file under ObjEvent(), you'll see the required parameter "FunctionPrefix" is just the first part of the function name that will be called. The full name is created by appending the method triggering the event "EvRing" in this case.

I have no idea if you need to specify the optional "InterfaceName" parameter, or what parameters the "EvRing" might pass to the called function.

That's not a full answer, but I hope it moves you in the right direction.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thank you PsaltyDS. Definately food for thought.

While my current code does not crash, it also does not detect a ring.

Does anyone have an idea on what I am doing wrong, particularly with the ObjEvent or EvRing aspect of things?

My current version of code is as follows:

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

$com = ObjCreate("NETCommOCX.NETComm")
$com2 = ObjEvent($com, "_NETComEvents_")

With $com
    .CommPort = 3
    .PortOpen = True
    .Settings = "9600,N,8,1"
    .InBufferCount = 0
;   .Output = $DialString
EndWith
    
$x=0
While 1; Reoccuring loop waiting for a ComEvent to occur - not sure if this makes sense
    $x=$x+1
   ;MsgBox(0, "No Ring", $x)
WEnd
Exit

Func _NETComEvents_EvRing($Any, $Parameters = "?")
    MsgBox(64, "Ring", "Brrrrrrrring!")
EndFunc  ;==>_NETComEvents_EvRing

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

Share this post


Link to post
Share on other sites

Thank you PsaltyDS. Definately food for thought.

While my current code does not crash, it also does not detect a ring.

Does anyone have an idea on what I am doing wrong, particularly with the ObjEvent or EvRing aspect of things?

My current version of code is as follows:

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

$com = ObjCreate("NETCommOCX.NETComm")
$com2 = ObjEvent($com, "_NETComEvents_")

With $com
    .CommPort = 3
    .PortOpen = True
    .Settings = "9600,N,8,1"
    .InBufferCount = 0
;   .Output = $DialString
EndWith
    
$x=0
While 1; Reoccuring loop waiting for a ComEvent to occur - not sure if this makes sense
    $x=$x+1
  ;MsgBox(0, "No Ring", $x)
WEnd
Exit

Func _NETComEvents_EvRing($Any, $Parameters = "?")
    MsgBox(64, "Ring", "Brrrrrrrring!")
EndFunc ;==>_NETComEvents_EvRing

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
I have never used the COM method, but I believe that when the modem receives a cal and it is not in AUTOANSWER mode then it sends 'RING' over the serial port so you could just detect that.

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

I've tested nothing, but syntax-wise, this may work.

Check the event names that will hopefully be printed by the generic event handler and tose are the ones you would use in place of EvRing for specific ones.

Dale

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

$com = ObjCreate("NETCommOCX.NETComm")
$com2 = ObjEvent($com, "_NETComEvents_")

With $com
    .CommPort = 3
    .PortOpen = True
    .Settings = "9600,N,8,1"
    .InBufferCount = 0
;   .Output = $DialString
EndWith
    
While 1
    Sleep(100)
WEnd

Exit

Func _NETComEvents_($evtName)
    ConsoleWrite($evtName & @CR)
EndFunc  ;==>_NETComEvents_

Func _NETComEvents_EvRing()
    ConsoleWrite("Ring!!!!" & @CR)
EndFunc  ;==>_NETComEvents_

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

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

A notable step in the right direction. It definately goes to Func _NETComEvents_($evtName) when the phone rings.

Many thanks DaleHohm, because I would not have gotten to this point anytime soon.

Would you mind explaining what is happening? I was thinking that $evName would be set to whatever event triggered the function like it would be EvRing or an a corresponding integer if the phone ringing had triggered it, but instead it was set to "OnComm".

Ultimately, I am trying to figure out when EvRing, or EvCTS changes state, then also when Off Hook or On Hook occurs.

Matt A

Share this post


Link to post
Share on other sites

Ah... in that case you need to do just as in the example...

Func _NETComEvents_()
    Local $evt = @COM_EventObj.CommEvent
    ConsoleWrite($evt & @CR)
EndFunc  ;==>_NETComEvents_oÝ÷ Ù8^)駡ûax*'²^Z¸­yÚjëh×6Switch $evt
    Case "comEvRing"
    ;;;
EndSwitch

My only concern with this is that comEvRing may be an Enum (a constant) instead of a string. If this is the case, see the link to harvesting Enums in my sig.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Also, thank you to martin. You were right that RING gets put on the comm port.

Now I have two ways to detect ringing, which is the most important thing I wanted to accomplish. If I can now figure out how to detect someone answering the line (line goes Off Hook) and hanging up (line goes On Hook), then we will have this thing exactly where I would like it.

DaleHohm - The programming line Local $evt = @COM_EventObj.CommEvent is getting a "Object referenced without a With statement" error. Do you think that this would be related to ComEvRing being a constant or something else?

Matt A

Share this post


Link to post
Share on other sites

I am able to detect an Off Hook by outputting "ATDT" & @CR then checking the comm port... "NO CARRIER" means phone was on hook and "NO DIALTONE" means dial tone was not detected (Off hook). The problem was that the ATDT command makes clicking noise on the line even though DTMF tones are not sent.

Hopefully with some more help we can get this to work using comEvRing.

Matt A

Share this post


Link to post
Share on other sites

Please show your code and please check to see what @COM_EventObj is with ConsoleWrite(ObjName(@COM_EventObj) & @CR)

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

I removed the ATDT aspect of the programming. Although it worked, it put noise on the line.

My current code:

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$com = ObjCreate("NETCommOCX.NETComm")
$com2 = ObjEvent($com, "_NETComEvents_")

dim $FromModem = ""

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

While 1
    If $com.InBufferCount Then
        $FromModem = $FromModem & $com.InputData ;* Check comm port
        If StringInStr($FromModem, "RING") Then ;* Reset $FromModem to null
            $FromModem = ""
        EndIf
    EndIf
WEnd
Exit

Func _NETComEvents_()
    Local $evt = @COM_EventObj.CommEvent            ; This line results in the error
    Switch $evt
        Case "comEvRing"
        SplashTextOn("TEST 2", $evtName, -1, -1, -1, -1, 4, "", 24)
        Sleep(1000)
        SplashOff()
        $FromModem = ""
    EndSwitch
EndFunc ;==>_NETComEvents_

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

Share this post


Link to post
Share on other sites

Please show your code and please check to see what @COM_EventObj is with ConsoleWrite(ObjName(@COM_EventObj) & @CR)

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Ooops. I missed the latter part. I think I understand your intent, although a bit of an explanation would help in the learning process if you have the time.

I'll need to experiment a bit with ConsoleWrite. I am not familiar with this command. Presumably it is something to do with a Troubleshooting approach I remember reading, but have not taken the time to learn.

Share this post


Link to post
Share on other sites

Assuming you use SciTe (if you aren't, you're making your life a lot harder), ConsoleWrite will write text to the console window at the bottom of the editor. You can also use MsgBox.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

To edit I right click on the file, which appaers to be doing editing in SciTE4, but to run (test) the script I have been doubleclicking on the file name in IE. I do not see a console window.

Presumably there is a way to run it from within SciTE that I am missing. I'll check. Maybe F5...

Edited by mashenden

Share this post


Link to post
Share on other sites

I got it. Sorry for the newbie status.

Share this post


Link to post
Share on other sites

... please check to see what @COM_EventObj is with ConsoleWrite(ObjName(@COM_EventObj) & @CR)

Dale

Using a ConsoleWrite before "Local $evt = @COM_EventObj.CommEvent" results in "NETComm" in the window.

Using the ConsoleWrite after the EventObj code does not work since that line causes the following error:

Ring Detect 9b.au3 (27) : ==> Object referenced outside a "With" statement.:

Local $evt = @COM_EventObj.CommEvent

Local $evt = @COM_EventObj^ ERROR

Sidebar - SciTE for troubleshooting is definately better. Great tip. Thank you.

In case needed, here is the code in the Func:

Func _NETComEvents_()
    ConsoleWrite(ObjName(@COM_EventObj) & @CR)
    Local $evt = @COM_EventObj.CommEvent; this line resuls in the error
    Switch $evt
        Case "comEvRing"
        SplashTextOn("TEST 2", $evtName, -1, -1, -1, -1, 4, "", 24)
        Sleep(1000)
        SplashOff()
        $FromModem = ""
    EndSwitch
EndFunc ;==>_NETComEvents_

Share this post


Link to post
Share on other sites

To edit I right click on the file, which appaers to be doing editing in SciTE4, but to run (test) the script I have been doubleclicking on the file name in IE. I do not see a console window.

Presumably there is a way to run it from within SciTE that I am missing. I'll check. Maybe F5...

From SciTE:

Tools | Go, or F5 for run with production

Tools | Beta Run, or Alt-F5 for run with Beta (if installed)

For this to work the file must be an .au3 file. This trips people up because if you create a new file and haven't saved it at least once yet, it doesn't have the .au3 extension yet, and doesn't run.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Ah, I think I understand... the ComEvent property is only valid if you fire an OnComm event... the routine now fires for ALL events.

So use

Func _NETComEvents_OnComm()

Then you also want the Enums:

Global Const $comEvSend = 1

Global const $comEvReceive = 2

Global const $comEvCTS = 3

Global const $comEvDSR = 4

Global const $comEvCD = 5

Global const $comEvRing = 6

Global const $comEvEOF = 7

Global const $comInputModeText = 0

Global const $comInputModeBinary = 1

Can you take it from here?

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Let me think about it. It is not overly clear but I may be able to figure it out.

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