ActiveXperts SMS Component

Quicklinks

ColdFusion sample - Send SMS text through a COM/USB GSM modem

The ActiveXperts SMS Component is a software development kit (SDK) to enhance an application or script with SMS or Pager functionality. SMS messages can be sent/received using a GSM modem, an SMPP provider or an HTTP compliant SMSC.


Introduction

In this example we are going to use create a ColdFusion project to send SMS messages. This demo project will ask the user to give a phone number and a message body in the web interface. A GSM modem is required for this demo.

Step 1: Download and install the ActiveXperts SMS Component

Download the ActiveXperts SMS Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new ColdFusion document

Create a new blank webdocument with the ".cfm" extention. First of all we are going to build the form whitch commands and properties of the device can be filled in. Then we are going to make a source code that connects to the device.

Step 3: Implementation

To use a GSM modem in ColdFusion, we need to use the Smsmessage object to create a new SMS message, and the Gsm object for communication through the GSM modem. A constants file might be usefull as well.

<cfobject type="com" Action="Create"class="ax_AxSms.Gsm"        name="objGsm">
<cfobject type="com" Action="Create"class="ax_AxSms.Constants"  name="objSmsConstants">
<cfobject type="com" Action="Create"class="ax_AxSms.Message"    name="objSmsMessage">

Step 4: Create a ColdFusion webform.

The following information is required to send a SMS message:

  • The port to which the GSM-Modem is connected.
  • The baudrate of the device. (You might get a tapi error if this isn't filled in correctly.)
  • The SIMcard's pincode. (If this is configured)
  • The recipient's telephone number.
  • The message.

Create a simple form to collect this information from the user. You can configure the required fields as required fields in ColdFusion. If the user does not fill in these fields properly, a messagebox is shown and the form will not be submitted. Make sure you create a ColdFusion form, not a plain HTML form.

Step 5: Gather information

The following code will ask the user for the recipient telephone number and the content of the text message. If a PIN code is required, then it will be prompted you to enter one. This data will be stored in the 'objSmsMessage' object.

//Message Settings
objSmsMessage.Clear();
objSmsMessage.ToAddress = Form.txtToAddress;
objSmsMessage.Body = Form.txtBody;
objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;

Step 6: Send the SMS message

The following code shows how to send an SMS message using the data that was stored in the 'objSmsMessage' and 'objSmsConstants' objects. The timeout value is set to 10 seconds, which means that the modem will try to send the message for 10 seconds, after this value it will stop trying.

//Send the message ! 
obj = objSmsMessage;
objGsm.SendSms(obj, iMultipart, 10000);
objSmsMessage = obj;

Appendix: Full source code.

Following you can find the full source code which is also included in the ActiveXperts SMS Component package.

<cfobject type="com" Action="Create"class="ax_AxSms.Gsm"        name="objGsm">
<cfobject type="com" Action="Create"class="ax_AxSms.Constants"  name="objSmsConstants">
<cfobject type="com" Action="Create"class="ax_AxSms.Message"    name="objSmsMessage">

<cfscript>
  strResult = "n/a";
  objGsm.LogFile = "C:\Windows\Windows\Temp\AxSms.Gsm.log";
  
  if (IsDefined("Form.btnSendMessage"))
  {
    strName = Form.ddlDevices;
    strPincode = Form.txtPincode;
    iDeviceSpeed = Form.ddlDeviceSpeed;	
    
    objGsm.clear();
    objGsm.Open(strName, strPincode, iDeviceSpeed);
    
    if (objGsm.LastError != 0)
    {
      strResult = objGsm.LastError & ': ' & objGsm.GetErrorDescription(objGsm.LastError);
    }
    else
    {
      //Message Settings
      objSmsMessage.Clear();
      objSmsMessage.ToAddress = Form.txtToAddress;
      objSmsMessage.Body = Form.txtBody;
      objSmsMessage.BodyFormat = objSmsConstants.BODYFORMAT_TEXT;
      
      iMultipart = "";
      if (IsDefined("Form.cbxMultipart"))
      {
        iMultipart = objSmsConstants.MULTIPART_OK;
      }
      else
      {
        iMultipart = objSmsConstants.MULTIPART_TRUNCATE;
      }
      
      if (IsDefined("Form.cbxFlash"))
      {
        objSmsMessage.DataCoding = objSmsMessage.DataCoding Or objSmsConstants.DATACODING_FLASH;
      }
      
      //Send the message ! 
      obj = objSmsMessage;
      objGsm.SendSms(obj, iMultipart, 10000);
      objSmsMessage = obj;
      
      strMessageReference = objSmsMessage.Reference;
      strResult = objGsm.LastError & ': ' & objGsm.GetErrorDescription(objGsm.LastError);
      
      objGsm.Close();
    }
  }
</cfscript>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>ActiveXperts SMS Component Demo</title>
  <link rel="Stylesheet" type="text/css" href="css/Layout.css" />
</head>
<body>
  <div class="ax_maincontainer">
    <div class="ax_header">
      <div class="ax_stroke"></div>
      <div class="ax_logo"></div>
    </div><!-- /header -->

    <div class="ax_container">
      <h1>SMS Component Coldfusion GSM Sample</h1>
      <hr />
      <p>
        This demo requires a GSM modem or GSM phone connected to your computer. A SIM card
        is required in this GSM modem. The product works with almost all available GSM modems.
      </p>
      <form action="gsm.cfm" method="post">
      <cfoutput>
        <h2>SMS Component:</h2>
        <h3>Build: #objGsm.Build#; Module: #objGsm.Module#</h3>
        
        <!-- Device -->
        <label for="Devices">Device:</label>
        <p>
          <select id="Devices" name="ddlDevices">
          <cfscript> 
            strDevice = objGsm.FindFirstDevice();
            
            while (objGsm.LastError LTE 0)
            {
              WriteOutput('<option value="' & strDevice & '">' & strDevice & '</option>');
              strDevice = objGsm.FindNextDevice();
            }
            
            for (i=1; i LTE 20; i++)
            {
              WriteOutput('<option value="COM' & i & '">COM' & i & '</option>');
            }
          </cfscript> 
          </select>
        </p>
        
        <!-- Device Speed -->
        <label for="DeviceSpeed">Device Speed:</label>
        <p>
          <select id="DeviceSpeed" name="ddlDeviceSpeed">
            <option value="0">Default</option>
            <option value="110">110</option>
            <option value="300">300</option>
            <option value="600">600</option>
            <option value="1200">1200</option>
            <option value="2400">2400</option>
            <option value="4800">4800</option>
            <option value="9600">9600</option>
            <option value="14400">14400</option>
            <option value="19200">19200</option>
            <option value="38400">38400</option>
            <option value="56000">56000</option>
            <option value="57600">57600</option>
            <option value="64000">64000</option>
            <option value="115200">115200</option>
            <option value="128000">128000</option>
            <option value="230400">230400</option>
            <option value="256000">256000</option>
            <option value="460800">460800</option>
            <option value="921600">921600</option>
          </select>
          Only applies to direct ports, i.e. COM1, COM2, etc.
        </p>
        
        <!-- Pincode -->
        <label for="Pincode">Pincode:</label>
        <p>
          <input type="password" id="Pincode" name="txtPincode" />
          Only required if SIM card has PIN code
        </p>
        
        <!-- Empty row -->
        <div class="ax_clearRow"></div>
        
        <!-- ToAddress -->
        <label for="ToAddress">ToAddress:</label>
        <p>
          <input type="text" id="ToAddress" name="txtToAddress" value="[ToAddress]" />
          <a href="http://www.activexperts.com/support/sms-component/?kb=Q4200015" 
            target="_blank">Recipient number format</a>
        </p>
        
        <!-- Body, Multipart, Flash -->
        <label for="Body">Body:</label>
        <p>
          <textarea id="Body" name="txtBody" style="height:55px;">
            Hello world send from ActiveXperts SMS Component!
          </textarea><br />
          
          <input type="checkbox"class="ax_cbFix" id="Multipart" name="cbxMultipart" value="1" />
          <label for="Multipart">Allow Multipart</label><br />
          
          <input type="checkbox"class="ax_cbFix" id="Flash" name="cbxFlash" value="1" />
          <label for="Flash">Flash</label>
        </p>
        
        <!-- Empty row -->
        <div class="ax_clearRow"></div>
        
        <!-- Send button -->
        <div class="ax_clearLabel"></div>
        <p>
          <input type="submit" name="btnSendMessage" value="Send SMS Message!" />
        </p>
        
        <!-- Result -->
        <label for="Result"><b>Result:</b></label>
        <p>
          <input type="text" id="Result" name="txtResult" 
           class="ax_FullWidth Bold" value="#strResult#" />
        </p>
      </cfoutput>
      </form>
      <p>
        This demo uses the ActiveXperts SMS Component, an 
        <a href="http://www.activexperts.com" target="_blank">
          ActiveXperts Software
        </a> product.
        <br />
        <a href="index.cfm">Back to main page</a>
      </p>
    </div><!-- /container -->
    <div class="ax_footer">
      <div class="ax_icon"></div>
      <p>
        © 2011 <a href="http://activexperts.com" target="_blank">
          Active<font color="#CCC000000">X</font>perts Software B.V.
        </a> All rights reserved.
        <small>
          <a href="http://activexperts.com/activexperts/contact" target="_blank">
            Contact Us
          </a> |
          <a href="http://activexperts.com/activexperts/termsofuse" target="_blank">
            Terms of Use
          </a> |
          <a href="http://activexperts.com/activexperts/privacypolicy" target="_blank">
            Privacy Policy
          </a>
        </small>
      </p>
    </div><!-- /footer -->
  </div><!-- /maincontainer -->
</body>
</html>    

You can download the full source code of this project from the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/sms-component. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The ActiveXperts SMS Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.