YOUR FEEDBACK
Evripidis wrote: I downloaded and tried to run the SampleSolution through Visual Studio. Every ti...
Cloud Computing Conference
November 19-21 San Jose, CA
Register Today and SAVE !..


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
POWERBUILDER LINKS YOU MUST CLICK ON


Adding Caller ID to Your PowerBuilder Applications
A how-to

How did I know the values of the hexadecimal constants to begin with? There are many sources but one I find useful is a tool called ApiViewer. It's invaluable when it comes to prototyping Win32 API calls. A link to it can be found at the bottom in the references section.

A further look at the prototype for CreateFile sheds some light onto the other constants, in particular 3, 0, 3. Again, if we look at the prototype for CreateFile, we see that these represent the ShareMode, SecurityAttributes, and CreateDisposition, respectively. For the ShareMode we are interested in FILE_SHARE_READ | FILE_SHARE_WRITE. Again, look at APIViewer to find out their hex values, or them together and convert to yield decimal 3. For the SecurityAttributes, this represents a pointer to a SECURITY_ATTRIBUTES structure that determines whether or not the returned handle can be inherited by child processes. If lpSecurityAttributes is NULL, the handle cannot be inherited. This is what is desired in our case, thus the zero. Finally, a word about the CreateDisposition, which is an action to take on files that do and do not exist. With respect to a comport, we expect it to exist. Therefore, the value OPEN_EXISTING is in order. Again, use the ApiViewer tool to see the numeric values of this constant.

Back to our project, the next order of business is to set the modem up to capture caller-ID information. The command for doing this may vary depending on your manufacture; consult your modem documentation. I was using a Toshiba software modem. With respect to the call to WriteFile, ls_write is the text to send to the modem, ll_write is the length of the text sent to the modem, and ll_written is the length actually written to the modem.

//turn on caller-ID

String ls_write
Long ll_write
Long ll_written
Long ll_rc

    ls_write = "AT#CID=1" + Char(13)
    ll_write = Len(ls_write)

    ll_rc = WriteFile( il_hcon, ls_write, ll_write, ll_written, Long(0) )

    Return True

Now all we have to do is wait for an incoming phone call and pick off the data. A couple of points are important here. One, the string that indicates the information is the phone number can vary depending on your particular modem. Again, experiment or consult your modem documentation. The second thing is that the data is returned with carriage returns and line feeds. While nice to look at, it can make parsing more difficult. Therefore, I've replaced them with spaces. With respect to the call to ReadFile, it follows the same logic as WriteFile(see above). Here is what the function to pick off the caller id looks like:

String ls_read
Long ll_Read
Integer ll_rc
Integer ll_i
String ls_Char
String ls_Result
String ls_Number

do while not Match(ls_result, 'NMBR')
    ls_read = SPACE(100)

    ll_rc = ReadFile( il_hcon, ls_read, len(ls_read), ll_read, Long(0) )

    //do some parsing
    For ll_i = 1 to Len(Trim(ls_read))
      ls_Char = Mid(ls_read, ll_i, 1)
      If ls_Char = Char(10) Or ls_Char = Char(13) Then
        ls_Result += ' '
      Else
        ls_Result += ls_Char
      End If
    Next

Loop
//here we got our string so pick off number
ls_Number = Mid(ls_Result, Pos(ls_Result, 'NMBR') + 5, 10)

sle_number.Text = ls_Number

Finally, in the close event we will need to make sure we close the open comm port.

CloseHandle(il_hCon)

Return True

That's it! Incredibly simple but powerful coupled with a database of phone numbers you can query to personalize your applications for your end users.
Happy Coding!

Resources

  • How does Caller ID work? How is the caller's phone number sent to my phone?
    http://electronics.howstuffworks.com/question409.htm
  • Toshiba V.92 56k Internal Modem User's Guide
    http://cdgenp01.csd.toshiba.com/content/support/downloads/v_92_manual_20020815.pdf
  • Sybase Developer Network/CodeExchange www.sybase.com/sdn
  • Chance's Blog http://chance.pbdjmagazine.com/
  • About Deanne M. Chance
    Ms. Chance graduated in 1996 with a degree in computer science from the University of Illinois. She has been a frequent contributor to the PowerBuilder Developer's Journal and gave a key presentation at Sybase TechWave 2005 entitled "A Real-Time Physical Inventory Solution Using PocketBuilder ASA and a WiFi Connection." She has held several engineering positions, starting a career at Motorola where she focused on mobile I.P. by doing real-time embedded programming for the base radio controller group as part of the iDEN/Nextel project.

    PBDJ LATEST STORIES . . .
    Sybase, Inc. (NYSE:SY), a leading provider of enterprise infrastructure, mobile software, and mobile services, today announced that Terry Stepien, President of Sybase iAnywhere, will present on behalf of the company at the UBS Global Technology and Services Conference. The presentation...
    Sybase 365 manages inter-carrier messaging services for more than 3 billion of the estimated 3.7 billion mobile subscribers worldwide, and for more than 700 mobile operators worldwide. Sybase 365's systems process more than 100 billion messages annually. With responsibility for over 80...
    Particularly in a means of moving PowerBuilder applications to the web. What I’m looking for doesn’t require a server license or the installation of unmanaged code to the web server, and works well across different browsers (not just Internet Explorer). The WPF DataWindow will help...
    As in prior years, the first thing I'll cover is what has changed (assuming that you attended in the past few years). We're back at the Mandalay Bay in Las Vegas. Near as I can tell, if you have to be in Las Vegas, this is the place to be. About the only complaint I had last year was t...
    Recognizing that information technology is pervasive in today’s business organizations and is changing the way businesses function across virtually every industry sector, Boston University's School of Management created a unique dual degree program – the MS·MBA. This program fuses...
    Up until recently, Web applications were "connected-only" applications. Users could only use the application by connecting to the central server and all data access was done in a single place. For many years, people accepted that was the limitation of Web applications. But it isn't a l...
    SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
    SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


    SYS-CON FEATURED WHITEPAPERS

    ADS BY GOOGLE
    BREAKING POWERBUILDER / SYBASE NEWS

    Sybase 365, a subsidiary of Sybase, Inc. (NYSE: SY), the global leader in mobile me...