Jump to content

Help Modifying Script That Uses NETComm OCX


Recommended Posts

I'm still lost :)

Any advice?

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

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

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

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

While 1
    Sleep(1000)
WEnd
Exit

Func _NETComEvents_OnComm()
    ConsoleWrite("1" & $com2 & @CR)
    Select 
        Case $com2.CommEvent()=$comEvRing  ; Change in the Ring Indicator.
            ConsoleWrite("2" & @CR)
        #comments-start
        Case $com2.CommEvent()=$comEvCD  ; Change in the CD line.
        Case $com2.CommEvent()=$comEvCTS  ; Change in the CTS line.
        Case $com2.CommEvent()=$comEvDSR  ; Change in the DSR line.
        Case $com2.CommEvent()=$comEvReceive  ; Received RThreshold # of chars.
        Case $com2.CommEvent()=$comEvSend  ; There are SThreshold number of characters in the transmit buffer.
        Case $com2.CommEvent()=$comEvEof  ; An EOF charater was found in the input stream
        #comments-end
    EndSelect
EndFunc

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

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

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

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

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

While 1
    Sleep(1000)
WEnd
Exit

Func _NETComEvents_OnComm()
    $evt = $com.CommEvent()
    Switch $evt
        Case $comEvRing  ; Change in the Ring Indicator.
            ConsoleWrite("2 - Ring" & @CR)
        Case $comEvCD  ; Change in the CD line.
            ;;;
        Case $comEvCTS  ; Change in the CTS line.
            ;;;
        Case $comEvDSR  ; Change in the DSR line.
            ;;;
        Case $comEvReceive  ; Received RThreshold # of chars.
            ;;;
        Case $comEvSend  ; There are SThreshold number of characters in the transmit buffer.
            ;;;
        Case $comEvEof  ; An EOF charater was found in the input stream
            ;;;
    EndSwitch
EndFunc

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

Edited by DaleHohm

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

Link to comment
Share on other sites

Yahoo - Thanks again, DaleHohm.

The good news is that this is the best way to detect ringing and the other events. The bad news is that in pursuing this approach I assumed that these other events would include off hook, on hook, etc, but they seemingly do not. I know, I know; "Assume..." Shame on me.

Does anyone know how to, after a ring is detected, monitor/test the line to detect when the line goes back on hook? As mentioned in an earlier post I can do it by periodically issuing a ATDT command and monitoring the response, but that puts clicking noise on the line that the person on the phone will hear - less than ideal.

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

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

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

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

While 1
    Sleep(1000)
WEnd
Exit

Func _NETComEvents_OnComm()
   $evt = $com.CommEvent()
    Switch $evt
    ;Events
        Case $comEvSend  ; There are SThreshold number of characters in the transmit buffer.
            ConsoleWrite("1 - EvSend" & $evt & @CR)
        Case $comEvReceive  ; Received RThreshold # of chars.
            ConsoleWrite("2 - EvReceive" & $evt & @CR)
        Case $comEvCTS  ; Change in the CTS line.
            ConsoleWrite("3 - EvCTS" & $evt & @CR)
        Case $comEvDSR  ; Change in the DSR line.
            ConsoleWrite("4 - EvDSR" & $evt & @CR)
        Case $comEvCD  ; Change in the CD line.
            ConsoleWrite("5 - EvCD" & $evt & @CR)
        Case $comEvRing ; Change in the Ring Indicator.
            ConsoleWrite("6 - EvRing" & $evt & @CR)
        Case $comEvEof  ; An EOF charater was found in the input stream
            ConsoleWrite("7 - EvEof" & $evt & @CR)
        Case $comInputModeText
    EndSwitch
EndFunc

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

Never had to live in the modem-only world have you :)

DTR (data terminal ready) should indicate On/OffHook for you.

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

Link to comment
Share on other sites

Shamefully I must admit that at one time I did live in that world. Similarly as my programming skills my modem skills have ebbed as well, but things like this do come back reasonably quick with Google and help from others.

Are you thinking that the way to get the status of DTR would be using an AT command, some other Ev event or some other method?

Edited by mashenden
Link to comment
Share on other sites

Sorry, I was assuming that DTR was one of the events available without looking.

You may be able to get this from the DSR (data set ready) or CD (carrier detect) events. Patly depends on the configuration settings of your modem I believe.

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

Link to comment
Share on other sites

That was kinda what I initially thought but through our efforts, we got the code to the point where it should show if any of the Ev_xxx events change (assuming I understand it right), but none seem to except the Ev_Ring when the line is called, but if I pick up the phone, nothing else changes on the modem.

Presumably this is all of the NetComm events, right?

I'll look to see if there may be an AT command that will make the modem act differently, so that possilby DSR or CD do change.

It may be that what I am trying to do is not possible since these pins are really for controling the modem but I want to monitor the line instead. Possilby off hook and on hook are monitored inside the modem but not reported such that it can be determined.

Matt A

Link to comment
Share on other sites

With the exception of the .Input property being renamed .InputData in NetComm, you should be able to apply all of the documentation, properties, methods and events for MSComm to NetComm. Suggest you search MSDN.

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

Link to comment
Share on other sites

In case anyone wants it here is the half baked code that detects ringing as well as off hook and on hook using AT commands. Because ATDT puts noise on the line I decided it was not for me. I see no way to detect off hook and on hook in another manner (unintrusive), plus this project exceeded my abilites (or willingness to invest any more time) so regretfully I am bailing.

DaleHohm - Your guidance was truly appreciated. It was worth the effort in that others should be able to use this to figure out the various options for reliably detecting ringing. Thank you.

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

$com = ObjCreate("NETCommOCX.NETComm")
$com2 = ObjEvent($com, "_NETComEvents_")
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
dim $FromModem = ""
dim $x

Global $Status = ""

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

While 1
    If $Status = "Ring Detected" Then
        While $Status <> "On Hook"
            Sleep (3000)
            $DialString = "ATDT" & @CR
            OutputToComm($com,$DialString)
            CheckCommBuffer($com, $FromModem, $DialString)
            ConsoleWrite("0 Status = " & $Status & @CR)
        WEnd
    EndIf
WEnd
            
Exit

Func _NETComEvents_OnComm()
   $evt = $com.CommEvent()
    Switch $evt
;Events
        Case $comEvSend; There are SThreshold number of characters in the transmit buffer.
            ConsoleWrite("1 - EvSend" & $evt & @CR)
        Case $comEvReceive; Received RThreshold # of chars.
            ConsoleWrite("2 - EvReceive" & $evt & @CR)
        Case $comEvCTS; Change in the CTS line.
            ConsoleWrite("3 - EvCTS" & $evt & @CR)
        Case $comEvDSR; Change in the DSR line.
            ConsoleWrite("4 - EvDSR" & $evt & @CR)
        Case $comEvCD; Change in the CD line.
            ConsoleWrite("5 - EvCD" & $evt & @CR)
        Case $comEvRing; Change in the Ring Indicator.
            $Status = "Ring Detected"
            ConsoleWrite("6 Status = " & $Status & @CR)
        Case $comEvEof; An EOF charater was found in the input stream
            ConsoleWrite("7 - EvEof" & $evt & @CR)
        Case $comInputModeText
            ConsoleWrite("8 - InputModeText" & $evt & @CR)
        Case $comInputModeBinary
            ConsoleWrite("9 - InputModeBinary" & $evt & @CR)
    EndSwitch
EndFunc

Func OutputToComm($com, $DialString)
With $com
    .Output = $DialString
EndWith
EndFunc

Func CheckCommBuffer($com, $FromModem, $DialString)
    While 1
        If $com.InBufferCount Then
            $FromModem = $FromModem & $com.InputData;* Check comm port
            If StringInStr($FromModem, "NO DIALTONE") Then;* Reset $FromModem to null
                $Status = "Off Hook"
;               ConsoleWrite("1 " & "Comm = " & $FromModem & "Status = " & $Status & @CR)
                $FromModem = ""
                ExitLoop
            ElseIf StringInStr($FromModem, "NO CARRIER") Then;* Reset $FromModem to null
                $Status = "On Hook"
;               ConsoleWrite("2 " & "Comm = " & $FromModem & "Status = " & $Status & @CR)
                $FromModem = ""
                ExitLoop
            ElseIf StringInStr($FromModem, "OK") Then;* Reset $FromModem to null
;               ConsoleWrite("3 " & "Comm = " & $FromModem)
                $FromModem = ""
                ExitLoop
            Else
;               ConsoleWrite("0 " & "Comm = " & $FromModem)
                $FromModem = ""
            EndIf
        EndIf
        $FromModem = ""
    WEnd
EndFunc

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

OK, not being one to give up without a fight, I tried one more ditch effort. I contacted Richard Grier, author of the NETComm OCX (and author of Visual Basic Programmer's Guide to Serial Communications, 4th Edition ISBN 1-890422-28-2 (391 pages) published July 2004, Revised July 2006).

Generally I asked whether I was missing the obvious with respect to being able to detect Off Hook or On Hook using NETComm. His response was:

What you have found i(s) true.

This has nothing to do with serial communications, but is a limitation of the modem. Modems DO NOT provide any method to determine the hook switch status. Thus, there is nothing that you as a programmer can do to override this limitation. The only solution is to use a non-modem (TAPI enabled) voice device.

Richard Grier (Microsoft MVP - Visual Basic)

Hard & Software

Homepage: www.hardandsoftware.net

Sad but true.

If anyone figures out a way PLEASE post your solution here.

Matt A

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...