SECS Equipment Example

[Home] [SECS Library] [Host Example] [Equipment Example] [Message Handler Example]

Equipment Example

This code example is distributed with the SECS Library. It demonstrates how a simple equipment (passive) application can be constructed. It relies on the Message Handler to respond to Host messages.

/*Title:       SECS Example Equipment
 *Copyright:   Copyright (c) 2002
 *Author:      Drake Woodring
 *Author:      Jim Redman
 *Company:     ErgoTech Systems, Inc.
 *Description: This is the example application for SECS/GEM

# SECS-GEM: True
# Test: True
# Not-To-JavaDoc: True
*/

/* The contents of this file are confidental property of ErgoTech Systems, Inc.
 * as described in the file "Ownership.txt". If you did not receive a copy
 * of that file please contact ErgoTech at +1 505 662 5156 or info@ergotech.com.
 */


import java.util.Vector;
import com.ergotech.secs.*;


/** This is an example piece of equipment. This will reply to messages based
 * on the MessageHandlerObject (ie, generic responses).  If the port number is
 * less then 128, then it will try to create a SecsI connection. Otherwise it
 * will assume that it is a HSMS connection.
 */
public class ExampleEquipment {
  public static final String cvsRev =  "CVS Info:$Revision: 1.4 $ $Date: 2003/07/23 18:08:55 $";
  static public void main (String args[]) {
   int portNumber = 0;
   int deviceId = 0x1;

   try {
     portNumber = Integer.valueOf(args[0]).intValue();

     if (args.length > 1) {
       deviceId = Integer.valueOf(args[1]).intValue();
     }
   } catch (Throwable e) {
     System.out.println("Setting the port number to the default 5500");
     portNumber = 5500;
   }

   // Setup the Logger
   LoggerInterface logger = new Logger("Host on " + String.valueOf(portNumber), "Host on " + String.valueOf(portNumber));
   logger.setDisplayBytes(false);
   logger.setDisplayMessages(true);
   // Setup the wrapper
   System.out.println("Listening on port " + portNumber + " with device " + deviceId);
   WrapperInterface wrapper = null;

   try {
     if (portNumber < 128) {
       wrapper =  new SecsIWrapper(portNumber, deviceId);
       // This is the SecsI only parameters we are interested in
       ((SecsIWrapper)wrapper).setIsHost(false);
     } else {
       wrapper =  new HSMSPassiveWrapper (portNumber, deviceId);  //HSMSPassiveWrapper(portNumber, deviceId);
     }
   } catch (Exception e) {
     System.out.println(e);
     return;
   }

   // This will setup the Message Handler for the default deviceId
   wrapper.addMessageHandler(new ExampleMessageHandlerObject());
   wrapper.setLogger(logger);
   // This will make us start listening for Hosts
   wrapper.connect();
   try {
     while (true) {
       Thread.sleep(10000);
     }
   } catch ( Exception ignore ) {
     // ignore
   }
  }

}

(c) ErgoTech Systems, Inc., 2004