I know that a phone dialing program is very simple to all of you
programmers that are writing complex communication programs, but
I have been fighting this problem off and on for a couple of months
now. The problem is being able to tell what kind of response there
is from the dialing... whether the phone number that I'm calling
is busy, or is ringing. The executable program below shows the
coding I am currently using, but I know that it could be improved.
It basically depends on a 10 sec delay without getting the "no dialtone"
message to designate the time to pick up the phone and break the
modem connection. If I disconnect the modem from the line, I do get
a "no dialtone" message. It would be nice if there was a positive way of
sensing that the phone was ringing, because that is the time to pick up
the phone and break the modem connection.
Any suggestions would be greatly appreciated.
programmers that are writing complex communication programs, but
I have been fighting this problem off and on for a couple of months
now. The problem is being able to tell what kind of response there
is from the dialing... whether the phone number that I'm calling
is busy, or is ringing. The executable program below shows the
coding I am currently using, but I know that it could be improved.
It basically depends on a 10 sec delay without getting the "no dialtone"
message to designate the time to pick up the phone and break the
modem connection. If I disconnect the modem from the line, I do get
a "no dialtone" message. It would be nice if there was a positive way of
sensing that the phone was ringing, because that is the time to pick up
the phone and break the modem connection.
Any suggestions would be greatly appreciated.
Code:
'Phone dialing example #COMPILE EXE #DIM ALL #INCLUDE "win32api.inc" GLOBAL hWin AS LONG %MyCommPort = 4 $defPhoneNo = "892-4706" SUB endComm(hComm AS LONG) LOCAL s AS STRING COMM PRINT #hComm, "ATZH" IF COMM(#hComm, RXQUE) THEN COMM RECV #hComm, COMM(#hComm, RXQUE), s END IF COMM RESET #hComm, FLOW COMM CLOSE #hComm END SUB CALLBACK FUNCTION winProc LOCAL commPort AS STRING, fromModem AS STRING LOCAL dialNo AS STRING, statusMsg AS STRING LOCAL hComm AS LONG, n AS LONG, connected AS INTEGER LOCAL start AS SINGLE, s AS STRING SELECT CASE CBMSG CASE %WM_COMMAND IF CBCTL = 102 THEN 'quit program DIALOG END hWin ELSEIF CBCTL = 101 THEN 'dial phone CONTROL GET TEXT hWin, 100 TO dialNo IF LEN(dialNo) < 8 THEN CONTROL SET FOCUS hWin, 100 EXIT FUNCTION END IF hComm = FREEFILE commPort = "COM" + TRIM$(STR$(%MyCommPort)) COMM OPEN commPort AS #hComm COMM SET #hComm, BAUD = 9600 COMM SET #hComm, BYTE = 8 COMM SET #hComm, PARITY = %FALSE COMM SET #hComm, STOP = 0 COMM SET #hComm, RXBUFFER = 1024 COMM SET #hComm, TXBUFFER = 1024 'check modem connection -------------------------------------------- s = "" COMM SEND #hComm, "ATZ" + $CRLF start = TIMER DO n = COMM(#hComm, RXQUE) COMM RECV #hComm, n, fromModem s = s + LCASE$(fromModem) IF INSTR(s, "ok") > 0 THEN EXIT DO IF TIMER - start > 5 THEN s = "Modem not responding on commPort" + STR$(%myCommPort) MSGBOX s, %MB_ICONWARNING, "Modem Connection" endComm(hComm): EXIT FUNCTION END IF LOOP 'check for dial tone and dial phone -------------------------------- COMM SEND #hComm, "ATDT" + dialNo + $CRLF s = "Dialing " + dialNo CONTROL SET TEXT hWin, 103, s s = "" start = TIMER DO n = COMM(#hComm, RXQUE) COMM RECV #hComm, n, fromModem s = s + LCASE$(fromModem) IF INSTR(s, "no dialtone") THEN statusMsg = "No dial tone": connected = -1 ELSEIF TIMER - start > 10 THEN statusMsg = "Connected..": connected = 1 END IF IF connected THEN EXIT DO LOOP CONTROL SET TEXT hWin, 103, statusMsg IF connected > 0 THEN BEEP: s = "Connected ... Pick up the phone and click Ok" MSGBOX s, %MB_ICONINFORMATION, "Dialing " + dialNo END IF 'hang up modem ----------------------------------------------------- endComm(hComm) END IF END SELECT END FUNCTION FUNCTION PBMAIN()AS LONG LOCAL title AS STRING, style AS LONG title = "Phone Dialing Example" style=%WS_SYSMENU + %WS_MINIMIZEBOX DIALOG NEW 0,title,,,190,120,style TO hWin CONTROL ADD LABEL, hWin, -1, "Phone number to dial: ", 10, 20, 70, 12 CONTROL ADD TEXTBOX, hWin, 100, $defPhoneNo, 85, 20, 70, 12 CONTROL ADD BUTTON, hWin, 101, "&Dial", 30, 50, 50, 25 CONTROL ADD BUTTON, hWin, 102, "&Quit", 100, 50, 50, 25 CONTROL ADD LABEL, hWin, -1, "Status: ", 10, 90, 30, 10 CONTROL ADD LABEL, hWin, 103, "", 40, 90, 100, 10 DIALOG SHOW MODAL hWin& CALL winProc END FUNCTION
Comment