Software: Simple VB Caller ID program and Flash lights

Posted: June 22, 2008 in Non Insteon Programming
Tags: , , , , , , ,

One thing I was always interested was being able to notify me when a certain person calls.  And in this case flash a inteson light or two.

My code is in VB 2005, for a VB6 Sample you can go here and basically requires only some little coding.  In the case of VB6 I think you only need to add the Serial object and adjust the port via the objects property settings.

What I used,

  • Analog phone with Caller ID (Vonage actually)
  • Internal / External Modem – Mine is a 56k External modem and have caller Id capability.
  • Hook them up, from the wall to the modem, to the modem to the handset.  🙂

The best way to see if it does is to open Hyper terminal and type the following command AT #CID=1 if it respond’s ok your set. This of course if for the modem i’m using, depending on your device it may be different.  This page includes how you can check for Caller ID capability on your modem

Here is a example of what the modem will pickup and we will parse.


DATE = 0621

TIME = 1113
NMBR = 1407xxxxxxxxx
NAME = Carlos Cobol

If you modem is external like mine you need to make sure AutoAwnser is disabled this is done by the DIP switches, For the US robotics its Dip switch #5 as down. In the case its internal you will need to add the command to disable auto answer. This is done with the command ATS0=0.

My Dip settings are as follows,









Since the code below allows to send some strings up startup, just add the in there if you need to.

Note: I do make reference to textbox called txtDataReceived in my form which will include the output.

First we make our imports include the serial devices (My program writes to a SQL database so some lines may not be needed)

Imports System.IO
Imports System.IO.Ports
Imports System.Net
Imports System.Data
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.Threading

In our Class definitions we include the reference to the serial port and we’ll call it ‘Modem’

Public Class Form1
    Dim WithEvents Modem As New IO.Ports.SerialPort

In our Load event we will attach to the serial port and give it the basic settings, Here is where you would also add any initialization commands

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Modem.PortName = "COM1"
        Modem.BaudRate = 9600
        Modem.DataBits = 8
        Modem.Parity = Parity.None
        Modem.StopBits = StopBits.One
        If Modem.IsOpen = False Then Modem.Open()

    End Sub

Next using the “Data Received” event we want to capture the Data which was received, Since there is a thread already running it wont allow us to update the textbox so simple we need to call use using the definition below,

 Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles Modem.DataReceived

            txtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
        Catch EX As Exception
        End Try
    End Sub

Second function to update the textbox and check for the number, and check for one of the text information above, Ive stripped my code for simplicity but you can search for specific strings here, match it with fields in a database, even FTP the data somewhere else, but that i’ll show you on another post.
Here we will check for the number ‘123456789’

 Public Sub updateTextBox()
        Dim temp As String
        With txtDataReceived
            .Font = New Font("Garamond", 12.0!, FontStyle.Bold)
            .SelectionColor = Color.Red

            temp = Modem.ReadExisting.ToString
            Buffer = Buffer + temp
        End With

        If Buffer.Contains("NMBR") = True Then
            Dim FILENAME As String = "c:\cALLINFO.TXT"  ' - Set a filename
            File.WriteAllText(FILENAME, Buffer)    '---- Write all the buffer for testing if we want to see it
            If Buffer.contains("123456789") then   '----- check for specific #
                End If
        End if                  
End sub
  1. anxiousguy says:


    thanks for your post. Im also working on reading data from a sensor via a serial port. My data is received on my VB UI as RXXX where XXX are integer values in inches. I want my data to read the RXXX as a value in metres and plot on a graph but Im having trouble converting the RXXX to Integer value. Im pretty new to VB. How can you help? My code is written below:

    Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived
    txtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})

    End Sub

    Public Delegate Sub myDelegate()
    Public Sub updateTextBox()
    With txtDataReceived
    .Font = New Font(“Garamond”, 12.0!, FontStyle.Bold)
    .SelectionColor = Color.Red
    End With
    End Sub

  2. lgarcia4617 says:

    Hi!. If you want to strip the ‘R’ from the variable you can use the replace function like this.

    This will return the code taking the ‘R’ out and replace it for ‘nothing’.


    Then to convert it to a integer you can use the VAL function which

    ‘Top of your code somewhere

    public newdata as integer


    Tell me how it goes!

  3. Mij says:

    Thank you for your Simple Visual Basic Caller ID program, I have been looking for something like this for long time, Its works with visual basic 2010 change made is declare buffer and .SelectionColor = Color.Red. Part from that its work great on visual basic 2010.

    Thank you so much for this program without it I would be lost. No one have sample like this on whole internet. You are the best!!!!

    Thank you.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s