Jump to content

Phone Dialer (using COM to modem on serial port)


DaleHohm
 Share

Recommended Posts

I posted a COM phone dialer a while back as an answer to another post. It used the MSComm component and I have since learned that many people will not have the MSComm ocx file on thier system (unless they once had VB6 installed). It is a royalty component and therefore cannot be redistributed.

Fortunately, there is a freeware version created to be a full emulation of that control that you can download and install from HardAndSoftware. You'll find the download link here: NetComm Update: New Location

Edit: Note, this needs the post 3.1.1 beta for COM support

Here is the Microsoft MSComm example:

; 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 ("MSCommLib.MSComm")

    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.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

Here is the freeware NETComm example:

; 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

    $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

Enjoy,

Dale

Edit: Added note about need for AutoIt beta and link to it

Edit2: Created seperate examples for MSComm and NETComm... NETComm uses the property .InputData instead of .Input -- thanks KenE!

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

  • 4 weeks later...

I get this error when I run the script:

"Error communicating with modem on COM".

It seems that a number of programs have problems communicating with my modem via the com port (COM5). It's an Intel 536EP modem.

Rasphone works fine (so I know the modem is in good working order), but keeps redialling the number after the call has been terminated, and I can't work out how to stop this.

???

Link to comment
Share on other sites

I get this error when I run the script:

"Error communicating with modem on COM".

It seems that a number of programs have problems communicating with my modem via the com port (COM5). It's an Intel 536EP modem.

Rasphone works fine (so I know the modem is in good working order), but keeps redialling the number after the call has been terminated, and I can't work out how to stop this.

???

Welcome to the forums!

Sorry you're having trouble... first I have to ask the obvious... you did change the ".CommPort = 3" line to ".CommPort = 5" right? Sorry I don't point that out as a necessary configuration change as I should.

If that isn't it, do you have another machine with another modem that you can try out? This works for me on COM3 with a SupraMax fax modem.

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

I think there's a better way for phone dialing.

Different for sure... easier, probably - if it does what you need it to do... better? that depends on what you are trying to accomplish...

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

  • 2 weeks later...

FYI, this might be important! I was also having trouble using this example code w/NetComm.

"I could not provide a control property named "Input", as is used in MSComm. Rather, I selected the property name "InputData". This property is used the same way as would be the MSComm Input property."

Link to comment
Share on other sites

FYI, this might be important! I was also having trouble using this example code w/NetComm.

"I could not provide a control property named "Input", as is used in MSComm. Rather, I selected the property name "InputData". This property is used the same way as would be the MSComm Input property."

Oh my, you're right. Here is associated info from the NetComm site:

Please refer to the VB5/6 documentation for the MSComm ActiveX control. I will not repeat that here (you can get a detailed description of MSComm properties and events from articles on www.msdn.microsoft.com; better yet, purchase a copy of my book). NETComm.ocx provides all essential properties, methods, and events provided by MSComm. There is one exception to this, due to an idiosyncrasy of ActiveX controls that are written in Visual Basic. I could not provide a control property named "Input", as is used in MSComm. Rather, I selected the property name "InputData". This property is used the same way as would be the MSComm Input property. For example,

Dim Buffer As String

Buffer = MSComm1.Input

Buffer = axNETComm1.InputData

I'll update the base post to include seperate example code for each library.

Thanks for pointing this out.

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

  • 3 weeks later...

Dale

If I have another type of equipment (not a modem) attached to the serial port, do you believe I can send any type of string to it? I mean, strings that are specific for that equipment?

Second, do you know how I can read a serial port? Also, not a modem, and, there is a way to detect if there is any string/character at the serial port without the program stay waiting ? (thru a loop), or even better, something like "set hot key" that goes to a routine when a char arrives at the serial port?

Regards

Jose

Link to comment
Share on other sites

Dale

If I have another type of equipment (not a modem) attached to the serial port, do you believe I can send any type of string to it? I mean, strings that are specific for that equipment?

Second, do you know how I can read a serial port? Also, not a modem, and, there is a way to detect if there is any string/character at the serial port without the program stay waiting ? (thru a loop), or even better, something like "set hot key" that goes to a routine when a char arrives at the serial port?

Regards

Jose

Sure. The MSComm and NetComm components used here are for communicating with a serial port -- the modem dialer is just an example.

Check out the NETComm site for docs that apply to both... or Google for MSComm for lots of old sample code...

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

Dale, Thanks a lot, I checked NETComm site and and MSComm. Now I understood all your example, and in fact it reads and writes at the serial port.

About AutoIt to be "interrupted" and directed to a routine when an event occurs at serial port, like an EOF, etc.: at MSCOMM they suggest to create a Private Sub "MSComm_OnComm ()".

If I create it in AutoIt --> Function MSComm_OnComm () .... it will work? It will execute at the envents interruption?

Follows the MSCOMM OnComm Event Example ( http://msdn.microsoft.com/library/default....comm_commx.asp)

The following example shows how to handle communications errors and events. You can insert code after each related Case statement, to handle a particular error or event.

Private Sub MSComm_OnComm ()
   Select Case MSComm1.CommEvent
   ' Handle each event or error by placing 
   ' code below each case statement

   ' Errors
      Case comEventBreak   ' A Break was received.
      Case comEventFrame   ' Framing Error
      Case comEventOverrun   ' Data Lost.
      Case comEventRxOver   ' Receive buffer overflow.
      Case comEventRxParity   ' Parity Error.
      Case comEventTxFull   ' Transmit buffer full.
      Case comEventDCB   ' Unexpected error retrieving DCB]

   ' Events
      Case comEvCD   ' Change in the CD line.
      Case comEvCTS   ' Change in the CTS line.
      Case comEvDSR   ' Change in the DSR line.
      Case comEvRing   ' Change in the Ring Indicator.
      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
   End Select
End Sub
Link to comment
Share on other sites

Dale, Thanks a lot, I checked NETComm site and and MSComm. Now I understood all your example, and in fact it reads and writes at the serial port.

Great!

About AutoIt to be "interrupted" and directed to a routine when an event occurs at serial port, like an EOF, etc.: at MSCOMM they suggest to create a Private Sub "MSComm_OnComm ()".

If I create it in AutoIt --> Function MSComm_OnComm () .... it will work? It will execute at the envents interruption?

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.

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

  • 1 month later...
  • 3 months later...

hi dale were can i find netcomm thanks beau

I posted a COM phone dialer a while back as an answer to another post. It used the MSComm component and I have since learned that many people will not have the MSComm ocx file on thier system (unless they once had VB6 installed). It is a royalty component and therefore cannot be redistributed.

Fortunately, there is a freeware version created to be a full emulation of that control that you can download and install from HardAndSoftware. You'll find the download link here: NetComm

Edit: Note, this needs the post 3.1.1 beta for COM support

Here is the Microsoft MSComm example:

; 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 ("MSCommLib.MSComm")

    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.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

Here is the freeware NETComm example:

; 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

    $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

Enjoy,

Dale

Edit: Added note about need for AutoIt beta and link to it

Edit2: Created seperate examples for MSComm and NETComm... NETComm uses the property .InputData instead of .Input -- thanks KenE!

Link to comment
Share on other sites

hi dale were can i find netcomm thanks beau

A quick Google search shows it is now at hardandsoftware -- check out the download section.

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

Hi dale quick ?

is there s way to send a command to a com port an get the replythen sen somthing back so how wold you send at then check to see if u you got ok back

The example checks for "OK". Perhaps I don't understand your question... can you ask it more carefully without all the typos please?

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

hello Dale sorry about all the typos in the first message. I have a device on com 4 that I need to send the command, Fr; and get the output back from the device I no if I use this code

$com = ObjCreate ("NETCommOCX.NETComm")

$input ="fr;"

With $com

.CommPort = 4

.PortOpen = True

.Settings = "9600,N,8,1"

.InBufferCount = 0

.output = $input

endwith

it sends a fr; to the device how can I read the output that the device sends back to the computer. So I can do, an if then statement thanks Beau

Link to comment
Share on other sites

hello Dale sorry about all the typos in the first message. I have a device on com 4 that I need to send the command, Fr; and get the output back from the device I no if I use this code

$com = ObjCreate ("NETCommOCX.NETComm")

$input ="fr;"

With $com

.CommPort = 4

.PortOpen = True

.Settings = "9600,N,8,1"

.InBufferCount = 0

.output = $input

endwith

it sends a fr; to the device how can I read the output that the device sends back to the computer. So I can do, an if then statement thanks Beau

OK, so as I said in the initial reply... the example does wait for OK at one point... that's what this section of code is doing:

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

You may want to check out some of the documentation at hardandsoftware as well...

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

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...