Contact Info

Crumbtrail

ActiveXperts.com » Serial Port Component » How to Use Serial Port Component » HTML/Javascript

Using ActiveXperts Serial Port Component with HTML forms on a client PC

ActiveXperts Serial Port Component is a software development kit (SDK) that enables the user to communicate to a device over a serial interface.

Such a device can be: a weight indicator, a modem, a scanner, or any other device that is equiped with a serial port. It can even be another PC, connected via a NULL modem cable.

ActiveXperts Serial Port Component features the following:

Step 1: Installation of Serial Port Component

When using HTML, there are two ways to install the ActiveXperts Serial Port Component on a client PC:

Automatic installation using HTML code

You can install the ActiveXperts Serial Port Component automatically using the following HTML code on top of the HTML page:

<head>
  <object id="objComport" 
      codeBase="https://www.activexperts.com/files/serial-port-component/AxSerial32.dll"
      classid="CLSID:9366AAD2-50F4-4CFE-9613-6AC3406ED46B " viewastext></object>
</head>

The Serial Port Component will be installated automatically. The user will be asked to confirm the installation, because the DLL is coming from an untrusted site (www.activexperts.com).

There are two ways to avoid prompting:

Manual installation using the ActiveXperts Serial Port Component installation procedure

On each client PC, download the ActiveXperts Serial Port Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create the ActiveXperts Serial Port Component object in HTML

You must use Javascript to declare and create the objects.

Use the following Javascript code to declare and create the object:

var objComport;
 
objComport  = new ActiveXObject ( "AxSerial.ComPort" );

Step 3: Send an AT command to a connected Hayes compatible modem

You can now send and/or receive data to and/or from a serial device.

The following HTML code shows how to query a modem:

<html>
  <head>
    <object id="objComport" 
        classid="CLSID:9366AAD2-50F4-4CFE-9613-6AC3406ED46B " viewastext>
    </object>
  </head>
  <body onload="ListDevices()">
    <script language="JavaScript">

    function Send ()
    {
      objComport.Device              = comboDevice.options [ comboDevice.selectedIndex].text
      objComport.Speed               = 9600
      objComport.ComTimeout          = 500
      objComport.LogFile             = "C:\ComLog.txt"
      objComport.HardwareFlowControl = objComport.asFLOWCONTROL_DEFAULT

      objComport.Open()

      textResult.value = "Result: " + objComport.LastError + " (" + 
        objComport.GetErrorDescription ( objComport.LastError ) + ")";

      if( objComport.IsOpened == -1 )
      {
         objComport.WriteString( textCommand.value );

         textResponse.value = ""

         while( objComport.LastError == 0 )
         {
            textResponse.value += objComport.ReadString () + "\n";
         }
      }
     
      objComport.Close ()
    }

    function ListDevices ()
    {  
      nCount  = objComport.GetDeviceCount ();

      for ( i = 0 ; i < nCount ; i++ )
      {
        comboDevice.options [ i ] = new Option ( objComport.GetDevice ( i ), "" );
      }

      for ( i = 1 ; i < 9 ; i++ )
      {
        comboDevice.options [ i + nCount - 1 ] = new Option ( "COM" + i , "" );
      }
    }

    </script>
    <font face="sans-serif" size="2">
      <hr size="1" color="#707070">
      <b><font size="4">ActiveXperts Serial Port Component HTML Sample</font></b><br>
      <b>
        <br>
        Query a modem connected to your PC (COM port, USB or Bluetooth).<br>
        <br>
        <br>
        <hr size="1" color="#707070">
        <br>
        <table border="0" bgcolor="#f0f0f0" ID="Table1">
          <tr>
            <td valign="top">Device Name:</td>
            <td>
              <select size="1" name="comboDevice" ID="Select1">
              </select>
            </td>
          </tr>
          <tr>
            <td valign="top">Command:</td>
            <td>
              <input size="50" type="text" name="textCommand" value="ATI" ID="Text1"><br>
              <br>
            </td>
          </tr>
          <tr>
            <td valign="top">Response:<br>
            </td>
            <td>
              <textarea rows="10" name="textResponse" cols="63" ID="Textarea1"></textarea>
            </td>
          </tr>
          <tr>
            <td vAlign="top">Result:</td>
            <td>
              <textarea rows="1" name="textResult" cols="63" id="Textarea2"></textarea>
            </td>
          </tr>
        </table>
        <br>
        <input type="button" onclick="Send()" value="Submit">  <b>IMPORTANT:</b>
        Please press the button <b>only once</b>, and allow some time for the 
      command to be processed </font>
    <br>
  </body>
</html>

You can download the full samples here.