image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

Build a Caller ID Application Part 2 by Erick Tejkowsi
07-05-01

Printer Version




Last week we talked about the hardware requirements for completing a REALbasic Caller ID project. This week, we'll discuss the Caller ID specification, learn about the REALbasic Serial control, and begin building the project. By the end of this lesson, you should have the basic knowledge to begin working on a Caller ID application.

The Caller ID Specification

Before jumping into the code for this tutorial, it would be a good idea if we took a brief look at how Caller ID works. From here on out, I will refer to Caller ID as CID. On enabled telephone systems, CID information is sent to you sometime between the first and second ring of a phone call. The data comes to you as a string of characters. The idea of this project is to receive this string of data and pull out the desired information (the phone number and the caller's name).

The CID string of data begins with the text: MESG = (Note that there are spaces before and after the equals sign.)

The next character in the string denotes which type of CID data follows. There are two possible formats for CID data:

  • SDMF - Sends the phone number (only)
  • MDMF - Sends the phone number and other data (usually the name)

To simplify this tutorial, we will only discuss the MDMF format. SDMF works in much the same way as MDMF, but it is more simplistic, so adding this functionality later shouldn't be tough. When the data is in MDMF format, a Chr(128) follows the "MESG = " string discussed earlier. For SDMF, a Chr(4) follows instead.

The next character in the CID string represents the length of the remaining data. Following the length, is the date of the call and the name and phone number of the caller. The date, name, and phone number are each preceded by a data type and length of that data. The possible data types are:

  • 1 = date
  • 7 = name
  • 2 = phone number

For a technical description of the CID specification, see this link.

Okay, enough of these boring specs... Time to code this project!

Building the Project

The REALbasic Serial control (pictured below) permits you to send and receive data through the serial port of your Mac. This is how we will capture the CID data. To use the Serial control, simply drag it from the toolbar and set its properties in the Property window. For now, you can leave the default settings as is.

07-05_serial.jpg (18k)

In addition to the Serial control, add the remaining controls to the interface:

RB Control Name
PushButton StartButton
PushButton StopButton
StaticText labeltype
StaticText labellength
StaticText labeldate
StaticText labelname
StaticText labellabelphone
PopupMenu PopupMenu1

By now, your interface might look something like this:

07-05_interface.jpg (15k)

Next, open the Code Editor and place the following code in the Open event of PopupMenu1. me.addrow "Modem"
me.addrow "Printer"
me.listindex=0

Proceed to the Action event of StartButton and add this code:

dim connected as boolean

Serial1.port = PopupMenu1.listindex
connected = Serial1.open

if connected then
  Serial1.write "AT#CID=2" + chr(13)
  StopButton.enabled=true
  me.enabled=false
else
  msgBox "There is a problem connecting to the current serial port."
end

This code starts off by assigning a port to the Serial control. Normally, this is either the modem or the printer port. Next, the code opens the serial port. If a connection is made, the code then sends a command to the Serial control. The command is: AT#CID=2 and it tells the modem to make its Caller ID function active.

Once the Serial control has been started and the modem's CID functions are active, they sit and wait for a call to occur. When a call does come in, the modem will intercept the incoming CID data and send it to the Serial control. This causes the DataAvailable event to fire. To read in the data, use the ReadAll method of the Serial control: dim incomingtext as string

incomingtext = me.readall
incomingtext = replaceall(incomingtext,chr(10),"")
ParseIncoming(incomingtext)

ParseIncoming is a method that looks through the data and tries to find the appropriate CID information. It performs many string manipulations based on the rules discussed earlier in the CID specification. Create the ParseIncoming method like so: ParseIncoming(rawdata as string) and add the following code: dim i,msglength,messageposition as integer
dim msgtype,strippedmsg,temp as string
dim callername,callernum as string

messageposition=Instr(rawdata,"MESG = ")

if messageposition<>0 then

  //we have caller id info!
  msgtype=mid(rawdata,messageposition+7,1)

  //which type of caller id transmission?
  // for my test, it was the newer "MDMF" type
  if msgtype=chr(128) then//"Ÿ" = $80 = 128
    labeltype.text="MDMF"
  else
    labeltype.text="SDMF"
    return
  end if

  //how long is the message?
  msglength=asc(mid(rawdata,messageposition+8,1))
  //display length of the entire CID msg
  labellength.text=str(msglength)

  //now we know the length, so we can
  //retrieve the message from the string
  strippedmsg=mid(rawdata,messageposition+9,msglength)

  //parse the date information
  temp=left(strippedmsg,10)
  //display the date info
  labeldate.text=ParseMyDate(temp)

  //parse the name information
  temp=mid(strippedmsg,11)
  callername=ParseCallerName(temp)
  //display the caller's name
  labelname.text=callername

  //parse the phone number information
  temp=mid(strippedmsg,11+carryoverlength)
  callernum=ParseCallerNumber(temp)
  //display the phone number
  labelphone.text=callernum
  labelphone.refresh

end if

Note the following methods from the above code:

  • ParseMyDate
  • ParseCallerName
  • ParseCallerNumber
These methods each take a string and parse specific information from it. Rather than list the code for each of these methods for you here, you download the project and view them there.

Finally, to turn off the modem (and Caller ID feature), place this code in the Action event of StopButton: serial1.write "AT#CID=0" + chr(13)
serial1.close

StartButton.enabled=true
me.enabled=false

What's Next?

That's it for this week. Again, you may download the completed code for this week's tutorial. Next week, we will look at what happens when a caller hides the CID information from you. We'll also take a look at some fun tricks that you can use to make your Caller ID application even more useful. See you then!




Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]