YOUR FEEDBACK
AJAX: XMLHttpRequest Vs. iFrames
Kenneth wrote: You forgot to mention a disadvantage of xmlHttpRequest that i...
AJAXWorld RIA Conference
$300 Savings Expire July 25
Register Today and SAVE!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
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

Digg This!

Page 1 of 2   next page »

We begin this article by asking the question, why would you want to add caller ID to your PowerBuilder applications anyway? I can think of about a handful of applications for it, mostly revolving around picking a phone number and querying a database. For example, "Good morning, Chance, will you be ordering the cheese and sausage pizza again?" Or perhaps a database of people, some whom you might not like, just to have your modem hang up on them. The possibilities are endless.

First some introductions. How does caller ID information get relayed from Ma Bell to your phone or modem anyway? Modems use a technique called Frequency Shift Keying to transmit information over a phone line. One tone represents a binary 1, while a nother represents a binary zero. A modem changes frequencies depending on whether it wants to send a 1 or a 0. To send caller ID information to your home it simply sends ASCII data to the caller ID box between the first and second rings. The modem then decodes the bits and makes the data available for your viewing pleasure. Incidentally, there's a more advanced system that contains the caller's name and the date and time of call but its technique is identical.

In this demonstration we'll simply pick off the incoming phone number (but you could use a similar technique to get the caller's name if you want). However, before we begin you'll need a few things:

  • A telephone account with the caller ID feature enabled
  • A modem capable of reading caller ID information
  • PowerBuilder
  • Some time to learn
For starters, we'll need a way to communicate with the modem. In general, modems are serial devices so we'll need a way to "talk to" the comm port. We'll need to use the Win32 API rather than the native PowerBuilder file I/O functions. Why? Because PowerBuilder buffers data on top of that already being done by the operating system. That can be problematic for serial devices. With that, here are the external function prototypes that you'll need for your project.

Function Long CreateFile(ref string lpszName, long fdwAccess, long &
fdwShareMode, long lpsa, long fdwCreate, long fdwAttrsAndFlags, long &
hTemplateFile) Library "Kernel32.dll" ALIAS FOR "CreateFileA;Ansi"

Function Long ReadFile(Long hFile, ref string lpBuffer, long nBytesToRead, &
ref Long nBytesRead, Long lNull) Library "Kernel32.dll" alias for "ReadFile;Ansi"

Function Long WriteFile(Long hFile, ref string lpBuffer, long nBytesToWrite, &
ref Long nBytesWritten, LONG lNull) Library &
"Kernel32.dll" alias for "WriteFile;Ansi"

Function Long CloseHandle(Long hObject) Library "Kernel32.dll"

For demonstrations purposes, we'll have to create a GUI capable of displaying the incoming information. You might use something like this: (Figure 1)

With that in place, we can go about coding our main algorithm in a "pre-open" event. It looks like this:

If wf_open_modem() Then
wf_write_data()
    wf_read_data()
End If

The first function tries to open the comm port the modem is located on. It looks like this. (Note: I've hard-coded the port number in. In an actual implementation you'd probably want this to be a user-defined setting.)

//poll device until we get a hit
Integer li_sub = 1
Boolean lb_connected = FALSE
UnsignedLong ll_tmp = 3221225472

    is_CommPort = "COM3:"

    //modem already detected
    If il_hCon > 0 Then
      Return True
    End If

    //try to connect
    Do While li_sub <= 10 And Not lb_connected
      il_hCon = CreateFile(is_CommPort, ll_tmp, 3, 0, 3, 0, 0);
      If il_hCon < 0 Then
        MessageBox(This.Title, "Modem NOT detected " + String(il_hCon))
      Else
        MessageBox(This.Title, "Modem detected " + String(il_hCon))
        lb_connected = TRUE
      End If
      li_sub ++
    Loop

    If Not lb_connected Then
        MessageBox(This.Title, "Modem not detected ")
    End If

    Return lb_Connected

A little explanation may be in order with the call to CreateFile. You may be wondering where the value 3221225472 comes from and what it represents. If we look at the prototype for the function, we'll see that this is the access mode to the commport that can be read, write, or both. In our case, we are interested in the hexadecimal constants GENERIC_READ and GENERIC_WRITE or more precisely these two values or'd together. For example, in hex, 0x80000000 | 0x40000000 = 0xC0000000. Convert that to a decimal and we have our constant 3221225472.



Page 1 of 2   next page »

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 . . .
Adobe's Kevin Lynch and Microsoft's Scott Guthrie to Keynote AJAX World RIA Conference & Expo
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be
PowerBuilder and EAServer: Uniting the .NET and J2EE Communities
In PowerBuilder 11.2, .NET meets J2EE head-on with the capability to deploy .NET Windows Forms and Web Forms applications (as well as assemblies and Web Services) that access Enterprise JavaBeans (EJBs) in Sybase's own EAServer. As you'll see over the course of this article, integratin
HarPB Tool Review
HarPB is a specialized utility for checking PowerBuilder source objects in and out of AllFusion Harvest. It handles the special requirements of checking objects out to PowerBuilder Libraries (PBLs) and checking objects in from PBLs. These operations are non-standard to most source cont
PowerBuilder Editorial: The State of the State
Back in 2002, Sybase announced their four-phase approach toward adding .NET support to PowerBuilder. Phase 1 was the implementation of web services in PB9 and Phase 2 was the release of DataWindow.NET, which was packaged with PB 10. Phases 3 and 4 were the more significant phases. In P
PowerBuilder History - When Did Sybase Develop PB and How Did It Evolve?
I have been asked many times by various clients, students, and the IT curious about PowerBuilder: When did Sybase develop the product and how did it evolve? I keep telling this story and answering e-mails on the subject. I am now to the point where I have decided that I should have PBD
PowerBuilder 11's .NET Interoperability
PowerBuilder 11 deploys entire applications as .NET Windows Form or Web Form applications and deploys individual components as .NET Assemblies and as .NET Web Services. Version 11 consumes resources of the default .NET framework as well as resources of custom developer-defined .NET res
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 Reports Record Second Quarter Results, Driven by 15% Revenue Growth
Sybase, Inc. (NYSE:SY), the largest enterprise software and services company exclusively