SecsHost - A .NET Component for Host SECS Interfaces


The SecsHost .NET component is designed to provide a high-level starting point when deploying Host SECS Interface software using the Microsoft .NET Framework .   The .NET component features a fully CLS (Common Language Specification) compliant API and can be used from any of the .NET programming languages, including C#, C++, Visual Basic, and Java.  Without any code development, the component is able to communicate with GEM standard equipment, manage dynamic Event Reports, upload and download process programs, and manage Equipment Constant values.  The component also imbeds extensive fallback logic that accommodates working with non-standard and non-GEM compliant equipment.  A supervisory application is provided with source code that enables you to interactively configure and manage multiple Host interfaces.  Application source code is also provided for a Host Graphical User Interface (GUI), and related dialogs such as property editing, and a window to display detail on the data that is being exchanged over the SECS interface.  The SecsHost component operates with or without these windows being present - it is a true component that can be imbedded and deployed in an application of your own design.  An application developer registers event handlers and callback delegates to receive asynchronous inputs such as Event Reports, Alarm Reports, or specified SECS message types.  The example application code demonstrates using these techniques without undue complexity.  You can readily understand how to use the component and get on with building your own application, or you can customize the application we provide to meet your own requirements.

Feature Summary


User Guide


The SecsHost .NET component is provided as the following files:

The files for .NET 2.0 are distributed in a .zip archive named  DotNet20HostApp.zip.  If you received the DMH software on CDROM, this archive is in the subdirectory LAN_IMAGE.  

In order to run the example application, you need to have either the .NET development software installed, or the .NET runtime installed.  The .NET runtime can be downloaded from  Microsoft as the file, dotnetfx.exe.  Note that the .NET runtime is not presently distributed with or built into the Windows operating systems.

The distribution is designed and tested for Windows XP Professional, and similar up-to-date Windows Professional versions such as Windows Vista or Windows 2000 Pro.

The Hume developed SecsHost component is a "component" as defined by the Microsoft .NET Framework.  As such, it implements the System.ComponentModel.IComponent interface.  Hume Integration is also using the word "component" to describe high level customizable applications such as their Data Collection Component.

Installation

Installation consists of extracting files in the DotNet20HostApp.zip archive to a directory of your choice such as the "Visual Studio 2005/Projects" directory in your "My Documents" folder. If you have already installed the Hume Datahub SDK, you should not add the files in the DotNet20HostApp.zip archive to any of the existing Datahub SDK GEM application directories.  The SecsHost component is able to find and use the Datahub SDK GEM directories without usage of a common directory.

The SecsHost .NET component uses the SECS/GEM application files provided in the Hume Datahub SDK product.  The developer needs to install the Hume Datahub SDK, and specify on the SETUP screen that the GEM/SECS applications should be installed.  The SecsHost component is able to find the Datahub SDK files using the environment variable DMH_BIN which is set when the Datahub SDK is installed.

The situation is simpler for a runtime deployment of your host application.  Instead of installing the Datahub SDK, you can simply deploy a single file executeable, SecsServer.exe.  This file is provided by Hume Integration for the usual case of using the as-provided SDK files.  If you have customized the SDK files, you are able to create a custom version of SecsServer.exe using a build script.  We encourage you to use the full SDK during development so that you have the toolset documentation, the debugging tools, and you are able to view the SDK GEM application source code.  When you are ready for deployment, you can download the SecsServer.zip archive from the Hume customer support website to obtain the SecServer.exe program and its build script.

Environment Variable DMH_DOTNET_TCLDIR

When the SecsHost component is initialized, it needs to find the Datahub SDK files or the SecsServer.exe executable. The startup logic first looks for the SecsServer.exe program in (1) the directory pointed to by the environment variable DMH_DOTNET_TCLDIR and then (2) the current working directory, and then (3) two directory levels up from the current working directory, which is the common development scenario when an executable is run from the subdirectory bin/Debug or bin/Release.   If the SecsServer.exe program is not found, then the startup logic looks for the SecsServer.tcl application script and the supporting files that are part of the Datahub SDK.  The search order for the SecsServer.tcl file is (1) the directory pointed to by the environment variable, DMH_DOTNET_TCLDIR,   (2)  the gem2/server directory of the Datahub SDK installation found using the environment variable DMH_BIN or by checking the default installation path, and (3) the gem/server directory of the Datahub SDK installation found using the environment variable DMH_BIN or by checking the default installation path.

This default logic may fail to find the files in the scenario when the Component is dragged and dropped on a design surface. We recommend you  define and set the environment variable DMH_DOTNET_TCLDIR to establish a well defined startup.  Use slash directory separators.  Environment variables are set by navigating from the Start menu - Start/Settings/Control Panel/System/Advanced/Environment Variables.  An example value is:
DMH_DOTNET_TCLDIR=C:/usr/local/gem/server
In a runtime deployment, the SecsServer executeable file is placed in a directory of your choice as specified by the DMH_DOTNET_TCLDIR environment variable.  The default directories used for process program transfer and trace logging are subdirectories of where the SecsServer.exe or SecsServer.tcl file is found.

Development

To start using the Hume .NET component with an existing project, you first add references to the SecsHost.dll and the SecsPort.dll.  A C# user chooses the Add Reference... menu item from the Project menu.  From the Add Reference dialog, the Browse... button on the .NET tab notebook page is used to indicate the path to the DLL files.

The component software uses the namespace Hume.SECS.  Coding is easier if you add the statement using Hume.SECS; to the using statements of your application source code.  By doing this, the namespace name, Hume.SECS, can be omitted from name references.  A Visual Basic developer uses the Imports statement for the same purpose.

The SecsHost software uses the HumeDMH.dll component internally to control a SECS interface server using the Hume DMH message system.  You may want to explore using the DMH message for your own application requirements such as integrating multiple host interfaces deployed on multiple computer systems.  The Hume SECS software is able to play the host role and the equipment role in multiple instances in the same SECS server process.

Your primary focus as a developer is using the class SecsHost.  This class implements public methods to send and receive SECS messages, and manage a host SECS interface.

Here is the general flow of using and configuring the SecsHost:

  1. Run the GemHostApp.exe application and take a look at the SecsHostEditor dialog in action.  You probably want to have this dialog in your application to let your users easily configure Host interfaces.  Run the application against real equipment, explore the example GUI,  and develop confidence that the core logic will work well in your custom application.
  2. Make a decision as to whether you will modify the GemHostApp project for your own requirements, or create your own application, and include selected features of the Hume application by adding selected files to your project.
  3. You can use the SecsHost component with or without user interface windows being present.  For GUI code, we recommend you add event handlers and delegates from the Load event logic for your window, and remove these event handlers and delegates in the Dispose method.  By using the Load event instead of the constructor, your window entities all exist and are initialized before receiving event invocations.  You double-click on a window form Design view to have the IDE generate an event handling method for the Load event.
  4. Construct a SecsHost instance.   At runtime, constructing the instance causes the child SECS server process to be started.  The Supervisor application uses a constructor that passes many of the configurable property values as string array arguments.  There are also simpler constructors where you create your instance, and subsequently use property assignment statements to configure the instance.
  5. Setup your event handlers and delegate values for callbacks.  The reception of Event Reports and Alarm Reports are dispatched into your application as events.  In general the callbacks and events come into your application from different threads than the starting thread that created your window controls.  Its not documented very clearly by .NET, but for some method invocations, the window controls are not designed to be used by different threads than the main event-dispatching thread of your application.  You may be able to update the .Text properties of TextBox widgets from other threads in .NET 1.1 without seeing problems, but this is not a proper technique, and it is not allowed in .NET 2.0.  The safest course is to copy the techniques in the example application.  You can test whether the current thread is not allowed to make a Control method call using the InvokeRequired property.  When the InvokeRequired property value is true, you should use a delegate and the BeginInvoke method to effect a GUI update.  This may seem overly complex, but it is in fact a simplification and improvement from the Win32 techniques of defining custom WM_ messages and calling WinPostMessage.
  6. Use the MessageTypeAdd method to register callback delegates for SECS message types that you desire to handle in your application.  Getting communication established and capturing alarms and event reports is already provided for.
  7. Change property values to your liking.  This includes setting the connection items such as the serial port or HSMS port and hostname to the desired values.  Call ConnectTypeSet or one of the connectType<Type> methods at this stage to fully initialize the instance data prior to configuring event reports or manually adding event and variables for equipment that does not support discovery features.  If your application has called the SuperSave method in a previous session, the known data items and the report configuration data from the previous session is loaded by initializing the connection type.
  8. At this stage, your application logic can edit the configuration of event reports.  GEM equipment supports letting the host discover status variables and parameters,  so interactive report configuration is usually done after being online and discovering the data items, or after restoring the data items known in a previous session.  If your equipment lacks support for discovery, at this point you can call the manual configuration methods such as VariableAdd and EventAdd.  Proper GEM equipment may lack features for the discovery of events and DVVAL variables.  The Hume equipment software features description variables to provide the host with this configuration information so that manual configuration of these items is not necessary.
  9. Now, with your desired configuration in place, call CommEnable to enable communication with the equipment.  The establishment of communication takes place some time after the call returns.  If you want to exchange SECS messages with the equipment, you can trigger your custom logic from receiving a COM_ENABLE event report, an AUTO_VIRT_INIT event report, or some other event report.  See the EventReportDefine method, the list of Built-in events, and the EventReport callback.  Or, you can receive status indications from the StateChange event, and use those to know when online communication is possible.
  10. If you update any of the connection properties after communication is enabled, call ConnectTypeSet or one of the ConnectType<Type> methods.  The method call will disable communication so you will need to call CommEnable again.  Connection properties include the ConnectionType, BAUD, HsmsHost, HsmsPassive, HsmsPort, and Serial_Port.
  11. Non-connection properties such as the Device ID, timer values, data types, etc. can be updated at any time without disrupting communication.  The Hume software does feature adaptive logic to automatically correct the Device ID, and to learn the data types used by the equipment.  Your configuration effort is substantially reduced compared to other products.
  12. Automatic initialization occurs by default whenever the equipment transitions to an online control state.  The default behavior is to attempt to discover the equipment's alarms, variables, and events, and setup the configured event reports, managed alarms, managed equipment constants, and synchronize the clock.  This behavior is controlled by setting the appropriate property values and/or configuring the managed reports, alarms, or constants.
  13. Call CommDisable to disable host communications.  It is called automatically in the SecsHost Dispose method.

Tcl Secs Notation, TSN

SECS messages are passed into and out of the application as formatted strings.  The format is similar to the notation in the SEMI documents except that the list formatting conventions of the Tcl programming language are followed.  The SecsPort API provides methods to split, join, append, and extract list elements.  In general, curly braces, { }, are used to surround list elements which contain white space.  By using the API calls to append list elements or join strings as list elements, you can be sure that your strings are properly formatted, and you do not need to manually balance opening and closing curly braces.  Developers who have worked with both XML and TSN list notation have found that the TSN notation is more compact, closer to the SEMI documentation, and easier for a human to scan and validate when reviewing diagnostic output.

As general guidance, when you expect a string value, you will get a two element list, of the form "A:n {this is n chars of text}".  If a string value does not have imbedded white space, it may be formatted without braces, such as "A:8 OneToken".  When you use the ListElement or ListSplit methods to parse the text, they take care of parsing and removing surrounding braces for you.  If an empty string is sent, you will see a one element list, A:0.  SECS has the notion of array data - 0 or more values of a given type.  When you expect to receive a single numeric value, you receive a two element list, with the type code as the first element, such as "U4:1 290".  You can also receive an empty array "U4:0" or an array with more than one value as in "U4:3 0 1 2".  Binary data values are formatted using C-language hexadecimal integer notation, for example, "B:3 0x00 0x01 0x02".  You can use the BinToInt method to convert these values to integer values.  With received data, the type code has a length value appended to it after a colon.  With data that you format for sending, the length information is optional, the data is parsed to determine the length.  See the TSN.html document for more details.
 
Semi Octal type code TSN type code Meaning & Examples
00 L List,  L, L:0,   "L {A {atc 100}} {A 1.0.0}", "L:2 {L:2 {U4 200} {U4 210}} {B 0}"
10 B binary - unsigned 8 bit data, "B 0", "B 1 2 3"
11 TF  boolean data, TSN type codes BL or BOOLEAN are also accepted as input, "TF 1"
20 A Character string data.  Traditionally this has meant printable ASCII characters but some implementations are sending any 8 bit characters including nulls using this type.
"A {hello world}", "A hello"
21 J Japan International Standard (JIS-8) encoded text.  This format is not commonly used or supported because in the past the SEMI standards have failed to identify specific reference documents.
22 V1..VE Variant data, also known as Localized Character Strings.  Your .NET unicode text is automatically converted into the chosen encoding.  V1 is for Unicode 2.0, V2 is for UTF-8 encoding.  See the TSN.html document for more details. "V1 {sent as Unicode}"
30 I8 8-byte signed integer, use hex notation for the value, "I8 0x123456789abcdf01"
31 I1 1-byte signed integer, "I1 -3"
32 I2 2-byte signed integer, "I2 99",  "I2 15 -7 99"
34 I4 4-byte integer signed, "I4 -5"
40 F8 8-byte floating point, "F8 6.02e23", "F8 0.1"
44 F4 4-byte floating point, "F4 1.0"
50 U8 8-byte unsigned integer, use hex notation for the value, "U8 0x7fffffffffffffff"
51 U1 1-byte unsigned integer, "U1 0"
52 U2 2-byte unsigned integer, "U2 512"
54 U4 4-byte unsigned integer, "U2 979"

 

Built-in SECS Data, Message Handling, Events

The SecsHost component has built-in logic to handle many of the standard SECS message types.  You do not have to code or provide for complex GEM capabilities such as configuring and receiving dynamic event reports, or managing the equipment communication and state models. See the table at the end of this document for more detail on the built-in message types.  If you are not familiar with the Hume host SECS software, you may wonder if the API is missing methods, for example to add variable definitions or event definitions.  In most cases, the software automatically determines the Status Variables and Equipment Constants by querying the equipment.  The SECS standards lack support for directly determining types of events.  The software listens to the events reported by the equipment, and adds them to its table of known event types.  If new Status Variables are seen in an Event Report, the software automatically saves configuration records for the newly discovered variables.  So instead of laboriously configuring event and variables from some inaccurate manual, you simply deploy the software, and run the equipment to accumulate configuration information.  Discrete Variable Event Reports (S6F3) and Discrete Variables are another area where the standards are deficient, and do not provide for programmatic introspection.  The built-in logic saves configuration information on the format of Discrete Event Reports and their included variables as they are encountered.  The Supervisor application has the ability to copy the accumulated configuration information determined from an equipment interface to new names.  This provides the ability to clone working interfaces for use with multiple instances of similar equipment in your factory.  In the rare circumstances where you want to manually make configuration changes, you can use the DebugTableWindow method to bring up a GUI that enables you to interactively examine, edit, and save the SECS Server configuration tables.
 

Custom SECS Message Handling

Use the method MessageTypeAdd to have SECS messages routed to your callback code for custom handling.  You can use this method to provide handling logic for new message types, and you can also use this method to replace the built-in handling of selected message types.  Your callback executes in a different thread than your main Windows event dispatching thread so use thread safe techniques for accessing application data or GUI controls.  The positive side of using a different thread is that your handling logic can be coded to use simple synchronous wait-for-reply SECS conversations without locking up your GUI.  For example, your callback can use SendReply to respond to the inbound message, and then initiate a synchronous conversation using SendSecsMsg and specifying that the logic should wait for the reply message.  While your handling code is progressing through the synchronous conversation, other software in your application can be handling event reports, or alarms or managing other interfaces.  Because of the internal design of the SecsHost, these other method calls are not blocked or delayed because your handler is busy with a conversation.

Logic in your application can send SECS messages or initiate conversations using the SendSecsMsg method.  For HSMS communication,  if you are sending a message and not waiting for the reply, SendSecsMsg can be used from your GUI code without fear of making your GUI unresponsive.  In some cases you need to wait for a SECS reply message.  If you are using HSMS, under most circumstances, the reply or failure to reply will be resolved within a few seconds.   The unusual circumstance is that you still have a TCP/IP connection so your send is successful, but then there is no reply, and you wait the full T3 period.  If the risk of this delay is not acceptable, you can create a new thread, and use the new thread to perform the SECS conversation where you need to wait for the reply message.

For SECS-I serial communication, timing is somewhat different.  With SECS-I there is no underlying TCP/IP connection that can signal the application when it is broken.  So there is a higher risk of your sending thread being in an unresponsive wait to determine if a send is successful, and then in a longer wait to obtain the reply.  So you may want to use a separate thread than your GUI thread to send SECS messages or conduct send-and-reply conversations.

Miscellaneous Notes

You can use multiple instances of the SecsHost class to provide more than one SECS interface.  Each interface can have its own custom handling of message types.  You may also use multiple instances of the Hume SecsPort equipment component in the same application.  A typical use of multiple host instances is to act as a host for sub equipment and provide a single control interface to the factory software.


SecsHost API Reference


 SecsHost Properties
Property Access Description
bool autoInit Configures whether the interface should execute initialization logic automatically when an online control state is established or re-established.  Since the actions performed during initialization are configurable using other properties, most application will configure the individual actions, and leave this overall flag at its default value of true.
bool autoStart Configures whether the interface should be started automatically with communication enabled.  This property is used if the interface is created using the constructor method that accepts the property values as string array arguments.  The default value is false.
int BAUD If you are using the SECS-I, RS-232 connection type, this property sets the baudrate of the serial port.  The default value is 9600.
string CEID_OFFLINE The event report identifier (CEID) that signifies that the equipment is transitioning to an off-line control state.  This value is used by the logic that tracks the equipment control state.  The default value is "4000".
static DmhClient SecsPort.dmh SecsHost and SecsPort instances use a shared connection to the DMH message system in order to communicate with the SECS server process.  The connection instance, dmh, is public in case you want to access it in your application. 
string CommState Read-only value of your GEM Communication State.  Possible values are DISABLED, ENABLED {NOT COMMUNICATING}, and COMMUNICATING.   The StateChange event is used to obtain asynchronous notification of this property value change.
int ConnectionType Configures the basic choice of connection type.  IntelliSense prompting shows the choices.  The value 0 means SECS-I RS-232, 1 means SECS-I terminal server, 1993 is for non-standard Draft HSMS, 1995 is for standard HSMS.  The default is 1995.
string ControlState A read-only value of the GEM Control State.  Possible values are OFF-LINE and ON-LINE.
int DEVID The SECS Device ID.  An identifier imbedded in SECS header data usually left at the default of 0.  The SecsHost software has adaptive logic to correct an improper value.  Settable range is 0..32767.
static SecsPort.DMHGroupName The DMH message system groupname used by the SECS server.  The same groupname should be specified to the constructor of every SecsHost or SecsPort instance in the application in order to share the same SECS server process.
string HsmsHost For an active HSMS connection, specifies the TCP/IP hostname or IP address of the Host computer.  The default value is "localhost".
bool HsmsPassive For an HSMS connection, whether the SecsHost plays the passive, TCP/IP server role.  The default value is false since the usual role for the host is non-passive. 
int HsmsPort For an HSMS connection, the TCP/IP socket port number.  Defaults to 5555.
bool MULT A flag used for SECS-I only to specify whether the equipment can handle owing more than one reply at a time.  The default value is true.
string Name The SecsHost name passed to the constructor and used in the SECS server process as a Tcl command name, a global array name, and an identifier in SQL table records.
string RecipeDirectory A pathname to the file system directory where Process Program files are located.  The default value is the relative subdirectory  "<Name>_recipes" of the directory where the SECS server is executing.  Note that by default, each interface has its own directory for Process Program files.  Reading this property returns the absolute directory path to the process program directory.
bool ReportsClear
This boolean property controls whether to delete all existing event reports during initialization before defining new ones.  When this value is false, the report definition logic deletes reports one at a time as each new report is defined to make sure the report ID is not in use  The value can be set true to eliminate possible undesired event reports, or to have only a single deletion message sent when setting up new reports. The default is false. 
bool ReportsEnable
Setting this boolean property true insures that all equipment based events are enabled for reporting during initialization.  If the value is set false, only the events that are specifically configured with data reports or for being enabled are enabled.  However, if there are no event reports configured, then all equipment based event reports are enabled irrespective of this property setting.  So, the meaning of the property is to  insure that all equipment based events are enabled, and the false value is not used for disabling event reports. The default value is true.
int RTY SECS-I maximum send retry, range 0..31, default 3
string SerialPort For a SECS-I connection, the serial port device such as "COM1".  The default value is "COM1".
string SpoolInit Controls initialization of equipment spooling.  The allowed values are PURGE, UNLOAD, or IGNORE.  The default value is UNLOAD.
string State A read-only value of the low-level connection state.  Possible values include OFFLINE, LISTENING, and COMMUNICATING.  You will see the OFFLINE state if the connection to the host is broken, or in the case of SECS-I implicitly broken by a conversation timeout.  The StateChange event is used to obtain asynchronous notification of this property value change.
int T1 SECS-I Inter-Character Timeout in milliseconds, range 100..10000, default 500
int T2 SECS-I Protocol Timeout in milliseconds, range 200..25000, default 10000
int T3 SECS Reply Timeout in milliseconds, range 1000..120000, default 45000
int T4 SECS-I Inter-Block Timeout in milliseconds, range 1000..120000, default 45000
int T5 HSMS Connect Separation Timeout - the delay between re-connection attempts in milliseconds, range 1000..240000, default 10000.  The T5 timer value is also used for SECS-I host logic as a retry timer for communication attempts.
int T6 HSMS Control Transaction Timeout in milliseconds, range 1000..240000, default 5000
int T7 HSMS Not Selected Timeout in milliseconds, range 1000..24000, default 10000
int T8 HSMS Network Intercharacter Timeout, default value 5000.  This value is not used.
int TRACE Used as a bitfield to control diagnostic trace information for SECS port activity which is passed to the application in the SecsTrace event.  By setting specific bits, the corresponding output is turned on. 

General Tracing: (TraceType = trace) 
Bit        Output Description 
0x0001     Read and write calls
0x0002     state changes including connection attempts 

Receive Tracing: (TraceType = rtrace) 
Bit        Description for Received Messages 
0x0100     Header binary dump 
0x0200     Header interpretation 
0x0400     Stream and Function description
0x0800     Message data binary dump 
0x0004     The Message as TSN 

Send Tracing: (TraceType = strace) 
Bit        Description for Sent Messages 
0x1000     Header binary dump
0x2000     Header interpretation
0x4000     Stream and Function description
0x8000     Message data binary dump
0x0008     The Message as TSN 

RcResult SetTraceSaving(bool save, bool compress, int maxDayFiles, string saveDir, string zipCmd)

public class RcResult {
   int rc;   // return code
   string result;
   }

bool TraceDataSaved

bool TraceDataIsCompressed

string TraceSaveDir

int TraceSaveMaxDayFiles

string TraceSaveZipCmd

The toolset software has the configurable feature of continuously saving the SECS communication trace data to files - one file per day, up to a maximum number per year, and optionally compressing the closed file from the previous day shortly after midnight.  The SetTraceSaving method is used to reconfigure the logging feature with the various properties being set atomically in one call.  The RcResult return value is used as follows.  If the rc value is less than 0 the SetTraceSaving() arguments were not acceptable and an error message is provided as the result string.  If the rc value is 0, the call succeeded.  If the rc value is greater than 0, the call succeeded with an advisory message as the result string.  For example, a message occurs if compression is set true but there is a maximum of only 1 file, so there is no distinct file for the previous day to compress.

The saving logic writes each day's output to a distinct file, in the directory named by the saveDir argument.  The maxDayFiles argument controls how many day files are saved per year.  It can be configured between 1 and 366.  When file saving is initiated, the output filename is set to traceNNN.txt where the NNN value is the current day of the year, 0 to 365, modulo the maxDayFiles value.  If this file already exists and has been written to earlier in the same day, then the output is appended to it, otherwise the file is created as a new file. Note that if the maxDayFiles value is set to 1, each day's output is saved to the same filename, trace000.txt.  The default values provide for saving the data from each connection in a separate directory.  Separate directories are required for each connection.  When trace data is being written, the compress argument controls whether the logic attempts to compress the output file when it is closed at the end of the day (midnight).  For compression to occur, the maxDayFiles value must be greater than 1 and a non-blank compression command must exist as the zipCmd argument.  The default assignment of zipCmd is similar to zip -m tracetxt.zip. This command causes the data file from the previous day to be moved into the tracetxt.zip archive, creating the archive if it does not exist.   The compression logic appends the day file name to the configured command before execution.  Only trusted persons should be allowed to configure the compression command because of the security considerations.


int TracewinMaxWidth
The approximate maximum number of characters to display in a single line of the trace window.  This value guards against excessive data use when long messages such as recipe transfer occur and the trace window is displaying connection activity.  Range 1000..120000, default 4000.
string tDATAID The SECS TSN type code for DATAID items.  Defaults to U4.
string tDATALENGTH The SECS TSN type code for DATALENGTH items.  Defaults to U4.
string tLENGTH The SECS TSN type code for LENGTH items.  Defaults to U4.
string tPPID The SECS TSN type code for PPID items.  Defaults to A.
string tREPGSZ The SECS TSN type code for REPGSZ items.  Defaults to U4.
string tRPTID The SECS TSN type code for RPTID items.  Defaults to U4.
string tTOTSMP The SECS TSN type code for TOTSMP items.  Defaults to U4.
string tTRID The SECS TSN type code for TRID items.  Defaults to A.
bool useS1F3 Whether to use S1F3 during initialization to query Status Variable values.  After initialization, subsequent value changes are ordinarily known to the host by being received in event reports. The default value is true.
bool useS1F11 Whether to use S1F11 during initialization to determine Status Variables.   Since the set of variables does not ordinarily change, and can be loaded from saved data, the initialization query can be disabled if it is time consuming.  The default value is true.
bool useS1F13 Whether to use S1F13 during initialization to establish communications.  The default value is true, and is almost always appropriate since the logic will use S1F1 if S1F13 is rejected. However, there is some defective equipment in use that gets confused if it receives S1F13.
bool useS1F17 Whether to use S1F17 during initialization to request the Online Control State.  The default value is true.
bool useS2F13 Whether to use S2F13 during initialization to query Equipment Constant values.  The default value is true.
bool useS2F29 Whether to use S2F29 during initialization to determine Equipment Constants.  The default value is true.  Since the set of constants does not ordinarily change, and can be loaded from saved data, the initialization query can be disabled if it is time consuming.
bool useS2F31 Whether to use S2F31 during initialization to synchronize the equipment clock.  The default value is true.
bool useS5F5 Whether to use S5F5 during initialization to determine Alarm types.  The default value is true.  This query is not used during every initialization. It is only used if the logic sees an enabled alarm type that it does not already know about.
bool useS5F7 Whether to use S5F7 during initialization to determine enabled Alarms.  The default value is true.
bool useS13
This boolean property chooses whether to enable using Stream 13 large process program transfer message types.  In addition to the Stream 13 messages, this property also enables or disables using S7F27, S7F29, S7F37, S7F38, S7F41, and S7F42 which are used with Stream 13 for transferring large unformatted, process programs.  The default value is true which causes an S13F9 reset message to be sent during initialization.  Stream 13 message types are preferred for transferring large data sets because the data is split into multiple smaller messages which require less memory use.


 
SecsHost Events
Event Handler and Argument Data  Description


All event handlers - NOTES
 
 
 
 
 

 

We are documenting both events and most of the delegate callback functions in this section.  Events are somewhat easier to develop with because of better handling by the .NET IDE tools.  However, they cannot return values to the event initiator.  In some cases we have elected to use delegate callbacks in order to receive and use application return values.

The IntelliSense code generation of the .NET IDE turns around the usual sequence of writing an event handling method and then registering it.  Instead, try registering an event handler using the += operator.  Press the Tab key when prompted to create event handling methods with the correct arguments.

The .NET framework hides the difference between executing a static method or an object method as an event handler.  You are able to use either kind of method.

When the event happens, your handler method is called.  You can cast the event sender object to (SecsHost) to have a reference to the component instance.


void AlarmReport(object sender, AlarmReportEventArgs e)

class AlarmReportEventArgs : EventArgs {
  string ALID;
  bool is_set;
  string ALTX;
  string clock;
}
 

This event is raised upon receiving an S5F1 alarm report message.  Modern GEM equipment posts events for alarm set and alarm clear conditions so the idea of alarms as distinct from events is becoming obsolete.
void EventReport(object sender,EventReportEventArgs e)

class EventReportEventArgs : EventArgs {
  string CEID; 
  string EventID; 
  ListDictionary data;
}

Use the EventReportDefine method to create data collection event reports.  Your application needs to call the Initialize method after defining the desired event reports to setup and enable the desired event reports with the equipment.  After Initialize is called, only the event reports you have configured are enabled with the equipment.  So if you want the equipment to report all of its events, call the method EventsEnable after calling Initialize

Events can be given meaningful names and descriptions using the EventUpdate method.  In the event report data, you receive both the underlying event identifier sent by the equipment, the CEID value, and the identifier for the event you have optionally customized, the EventID.   The data of the event report is passed as a ListDictionary instance which contains variable name and value pairs.  The variable names are from the VFEIname column of the SECS server ei_variable table.  You are able to assign your own variable names using the VariableUpdate method.  Using a host given name for variables allows the logic to ensure that each name is unique, and provides for uniform naming across equipment instances.  If you do not provide your own name values for variables, the default variable names are assigned using the naming conventions of the Sematech Virtual Factory Equipment Interface (VFEI) standard.  The ability to rename events and variables is referred to as Virtual Reporting.

The default names for variables are computed as follows.  The variable names defined by the equipment are folded to uppercase, with white space and non-alphanumeric letters being replaced by underscores.  Hyphens are not changed. An underscore is inserted for each  transition from lowercase to uppercase in the equipment provided name.  If the computed name is not unique for the equipment instance, the name is made unique by concatenating an underscore and the variable ID.  For example, the equipment variable name PPExecName is assigned the default name PP_EXEC_NAME.  The following 8 computed names are exceptions to the naming algorithm and are reassigned based on the Sematech VFEI standard: 
ESTABLISH_COMMUNICATONS_TIMEOUT becomes COM_TIMER, 
MDLN becomes EQ_MODEL_ID, 
PREVIOUS_PROCESS_STATE becomes PREV_PROC_STATE, SOFTREV becomes EQ_SOFT_VER, 
MID becomes MATERIAL_ID, 
CMD becomes CMD_VAR, 
TID becomes TID_VAR, and 
MTY becomes MTY_VAR.

SecsMessageReceiveDelegate See the MessageTypeAdd method described in the next section to see how to receive SECS messages in your application.
void SecsTrace(object sender, SecsTraceEventArgs e)

class SecsTraceEventArgs : EventArgs {
string traceType;
string text;
}

This event provides you with the detailed information of SECS message traffic that is viewed in the SECS Trace window - see the Tracewin method.  The flow of  information is controlled by setting the TRACE property.
static void SecsPort.ServerError(object sender, ServerErrorEventArgs e)

class ServerErrorEventArgs : EventArgs {
string message;
}

The SecsHost class reports Tcl programming errors that are trapped in the SECS Server process as ServerError events.  An example would be trying to send an improperly formatted SECS message.  These error events will happen during development but should be rare once the code is debugged.
void StateChange(object sender, ValueChangeEventArgs e)

class ValueChangeEventArgs : EventArgs {
string varname;
string newvalue;
}

This event notifies your application of state value changes. Possible varname values include 
  • state - the State property value changed
  • comm_state - the CommState property value changed
  • control_state - the ControlState property value changed
  • dataset_delete - a process program has been replaced with a newly received one.  Stream 13 messages were used for the transfer.  The newvalue argument is the ppid.
  • dataset_download - a process program was downloaded to the equipment using Stream 13 messages.  This event happens when the S7F29 length verification message is received with the correct length specified.  The newvalue argument is the ppid.
  • dataset_upload - a process program was received using Stream 13 transfer messages.   Proper GEM equipment will also post an UploadSuccess event.  The newvalue argument is the ppid.
  • recipe_delete - a process program was replaced with an uploaded version using Stream 7 messages.
  • recipe_download - a process program was downloaded to the equipment using Stream 7 messages.
  • recipe_upload - a process program was received from the equipment using Stream 7 messages.
Your application gets notified of the initial values of these items when the SecsHost connection type is initialized.  With the recipe_* events, the newvalue string is the process program identifier (ppid).

SecsHost Methods
METHOD DESCRIPTION
General Comments
 
 

 

The List manipulation methods are actually implemented by the HumeDMH.dll component, and exposed for your convenience by the SecsHost component.
RcResult AlarmAdd(string ALID, string ALTX, string ID_TSN)

struct RcResult {
   int rc;   // return code
   string result;
   }

This method is used to manually add alarm definitions for equipment that does not support discovery of alarm types using S5F5.  The ALID argument value is the alarm type identifier which is usually an integer.  The ALTX argument is static text for the alarm description and it is limited to 40 characters in length.  The ID_TSN argument is the SECS item data type for the ALID in TSN notation such as U4. 

If the method succeeds, the rc field in the result structure is set to 0. It is not an error if the alarm definition already exists, the argument values are used to update the existing definition.  A non-zero result indicates an error, and the result string should be examined.  Possible error return codes include:
-2  invalid ALID
-3  invalid ALTX value 
-4  an error occured using the ID_TSN value to format the ALID value as a SECS data item
-9  unexpected SQL error

void AlarmEnable(string ALID, bool is_enabled) Enable or disable reporting of an Alarm type (S5F1).
bool AlarmIsEnabled(string ALID) Test if the reporting of an alarm type is enabled 
bool AlarmIsSet(string ALID) Test if the alarmed state is currently set
DataTable AlarmTable() This method returns current data from the SECS Server ei_alarm table for the SecsHost instance.  The columns of the table include: spname, ALID, is_enabled, is_set, ALTX, host_managed, and host_wants_enabled.
int BinToInt(string binValue)

 

Converts a SECS B (Binary  - Semi "10") data value usually formatted as a hexadecimal string to an integer value.
void CommDisable() Disable SECS communication.  The SecsHost is initialized without communication enabled so using this method only makes sense after CommEnable has been called.
RcResult CommEnable()

struct RcResult {
   int rc;   // return code
   string result;
   }

Enables SECS communication.  The CommState property value will change and StateChange events will be received.  These changes are the asynchronous indications for success or failure to establish communication.  You may want to display the trace window  in order to see detailed information on the status of communication attempts.  If there is an error setting up the connection, the return code value will be non-zero, and the result string will be an error message.
RcResult ConnectTypeHsmsActive(string host_or_ip, int port) This method is an alternative to setting the underlying property values to specify an active HSMS connection type, and calling ConnectTypeSet().
RcResult ConnectTypeHsmsPassive(int port) This method is an alternative to setting the underlying property values to specify a passive HSMS connection type, and calling ConnectTypeSet().
RcResult ConnectTypeSerial(string comDevice, int baudrate) This method is an alternative to setting the underlying property values to specify a SECS-I connection type, and calling ConnectTypeSet().
RcResult ConnectTypeSet()

struct RcResult {
   int rc;   // return code
   string result;
   }

This method is called to use the current property values and initialize a SECS interface for the indicated connection type.  It is called by the ConnectType<Type> methods.  If you are setting connection property data directly, call this method after your property values are set.  The method returns the value 0 to indicate success.  If communication is enabled when this method is called, it becomes disabled as a result of setting up the new connection.  A non-zero return code value indicates an error setting up the connection, in which case the result will be an error message.
RcResult ConnectTypeTerminalServer(string host_or_ip, int port) This method is an alternative to setting the underlying property values to specify a SECS-I connection type over a TCP/IP terminal server connection and calling ConnectTypeSet().
void ControlStateOffline() This method sends a S1F15R message to request the offline control state. 
int ControlStateOnline() This method sends a S1F17R message to request the online control state.  If the return value is 0 or 2 the online state is indicated.
void Copy(SecsHost dest) This method copies the configurable SecsHost property values to another instance.
string CopyAll(SecsHost dest) This method calls Copy to copy the current property values to another instance, and it also copies table records of events, event reports, alarms, variables, etc in the SECS Server to the destination instance.  The return value is a string formatted as a list of two integers - the total number of table rows found, and the number of rows copied.  In normal circumstances, the two values are equal.
void DebugDMHStatus(bool show) This method causes the DMH message system status window to either be shown or dismissed.
void DebugInspect() This method can be used to exec the Inspect introspection debugger.
void DebugTclConsole(bool show) This method causes a console window for the SECS Server to be shown or dismissed.
void DebugTableWindow(bool show) This method causes the Datahub table management GUI to be shown or dismissed. 
void DebugTraceWindow(bool show) This method is used to display a window which updates to show SECS message traffic and state information for the SecsHost.   There are menu options to control the data displayed, and menu actions to save the displayed data to the file system.  This method invokes the Tcl version of the Trace window which is created by the SECS Server process.  See the Tracewin method to instantiate a native .NET window with similar function.  Including the .NET window version in your application is desirable to help diagnose communication problems. 
void Dispose() As a .NET component, the SecsHost inherits a public Dispose method that can be called to shutdown. 
 RcResult EventAdd(string CEID, string ID_TSN, string eventName, string description)

struct RcResult {
   int rc;   // return code
   string result;
   }

This method is used to manually add event definitions for equipment that does not support discovery of event types.  The CEID argument value is the event type identifier which is usually an integer.  The ID_TSN argument is the SECS item data type for the CEID in TSN notation such as U4.  The eventName argument is a virtual name for the event type defined by the user.  The desciption argument can be used to provide guidance in selection lists.  If any of the arguments ID_TSN, eventName, or desciption are provided as null or empty strings, then default values are used:  U4 for ID_TSN, and the CEID value as a string for the eventName.

If the method succeeds, the rc field in the result structure is set to 0.  No error occurs if an event definition with the same CEID already exists - the other fields are updated per the call arguments.  A non-zero result indicates an error, and the result string should be examined.  Possible error return codes include:
-2  invalid CEID
-3  invalid eventName value 
-4  an error occured using the ID_TSN value to format the CEID value as a SECS data item
-9  unexpected SQL error

string [] EventChoice() This method returns an array of {CEID EventName Description) string values of event types that do not currently have an associated event report.  The method is used to help implement the GUI feature of new report creation.
Equipment Constant Update see ParameterUpdate Equipment Constant is a misnomer.
int EventDiscovery() The SECS-II standard does not provide a way to discover equipment events.  This method is called to attempt event discovery by enabling all events and asking the equipment which events are enabled.  This technique requires that the equipment support the underlying message types and implements an EventsEnabled variable that has the expected name.  A positive return value indicates the number of new event types discovered.  Negative return values indicate various failure modes.
int EventsEnable()
int EventsEnable(string CEIDlist, bool is_enabled)
Called with no arguments, EventsEnable requests that the equipment enable all event reports.  By providing arguments, you can request the enabling or disabling of selected events.  The SecsHost automatically enables the reporting of events for which you have configured event reports during online initialization.   A negative return value indicates an unexpected internal error.  The value 0 means success, and 1 means at least one of the events does not exist.
bool EventIsHostEnabled(string CEID) Test if reporting of an event type has been configured in the SecsHost software to be enabled during the initialization logic.
bool EventIsReported(string CEID) Test if the reporting of an event is currently established with the equipment.
int EventReportDefine(string eventName, string [] varNames) Create or update an event report configuration.  The eventName argument is the virtual name of the event which can be configured to be different than the CEID value by using the EventUpdate method.  The varNames argument is an array of the virtual names of the variables whose values are to be reported when the event occurs.  The method VariableChoice provides a current list of virtual variable names.  You can use the VariableUpdate method to provide your own virtual variable names.  The default virtual variable names are assigned per the conventions of Sematech as explained in the EventReport Event section above.  After calling this method, you need to call the Initialize method to have your desired event reports setup and enabled with the equipment.  The Initialize method is called automatically whenever an online control state is established if the AutoInit property is true.

The method returns 0 for success, -1 if the eventName is not known, or -2 if a variable is not known.  If  you have more than one machine event with the same virtual event name, each machine event will be setup with the desired report.

void EventReportDelete(string eventName) Delete an event report configuration.
string [] EventReportConfig(string virtualName) This method returns a four element string array for the configuration of an event report.  The elements are CEID, virtualName, Description, and Variables.  Use ListSplit to split the Variables element into the individual virtual variable names.  A null is returned in case of error.
DataTable EventReportConfigs() This method returns a DataTable of the existing event report configurations.  The table columns are CEID, EventName, Description, and Variables.
DataTable EventTable() This method returns a DataTable featuring a subset of the SECS server's event table for the current SecsHost.  The included columns are: spname, CEID, VFEIname, host_managed, host_wants_enabled, event_class, is_reported, and description.
string EventUpdate(string CEID, string eventName, string description) Assign or update the virtual event name and description for an event type.  Per the SECS-II standard, events use integer values for identifiers.  There is no standardization of values.  You are able to provide meaningful names and descriptions for events.  You can use this feature to great advantage and create virtual equipment drivers with standard event and variable names.  If the description value is passed as null, the current value for the event is not changed.
int Initialize() Performs online initialization which enables communication and sets up event reports.  Initialization is controlled by your settings of property values, and configured items.  It optionally includes:
  • establishing communications if not already established
  • requesting the equipment go online if the online control state is not already established
  • querying the status of alarms and variables if being online is new
  • synching the equipment clock
  • setting equipment constant values for the ones that you have configured persistent values
  • setting up event reports per your configuration
  • enabling all events if you do not have any configured equipment based event reports so you can capture the event definitions needed for event reports
  • unloading, purging, or ignoring the spool
By default this initialization is attempted automatically whenever an online control state is established.  The autoInit property is used to disable automatic initialization.

The return value is 0 for success.  Error return values include:  -1 TIMEOUT, 1 communication failed, 2 not online, 3 clock set, 4 setting of Eq. Constants, 5 disabling of events & reports, 6 event & report enabling, 7 alarm management, 8 Spool init, or ei_custom_init error.

StringBuilder ListAppend(string list, string element);

StringBuilder ListAppend(StringBuilder list, string element1);

StringBuilder ListAppend(StringBuilder list, string element1, string element2);

StringBuilder ListAppend(StringBuilder list, string element1, string element2, element3);

StringBuilder ListAppend(StringBuilder list, string element1, string element2, element3, element4);
 

These methods are used to add one to four list elements to text that is formatted as a Tcl list.  It is a good programming practice to use ListAppend or ListJoin to build a Tcl list, in order to make sure that imbedded white space or other special characters are properly delimited with curly braces or escaped with backslashes.  A null value may be passed as any of the string argument values, in order to represent an empty list or empty element.  However, a null value should not be passed as a System.Text.StringBuilder argument.  The System.Text.StringBuilder class is designed to support more efficient string modification than using instances of the string class.  The input StringBuilder objects are modified by reference and returned as the return value of the methods.  You can construct a StringBuilder instance that does not contain any characters to represent an empty list.   The overloaded method calls make it convenient to add up to four list elements in one call.  If you need to add more elements, call the methods repeatedly.
string ListElement(string list, int index1);

string ListElement(string list, int index1, int index2);

string ListElement(string list, int index1, int index2, int index3);

This function is similar to the lindex function of Tcl.  It will parse text formatted as a Tcl list and return the specified element.  Indexing starts from 0.  Arguments index2 and index3 may be used to indicate that parsing of the TclList should continue up to two additional levels as a nested list structure. If a specified index is out of bounds, an empty string is returned.  Not all strings are valid Tcl lists.  If an invalid list is parsed, the method call throws the FormatException.
string ListJoin(string [] argv); Joins together strings as Tcl list elements forming a result string that is a Tcl list.  Braces are added as needed to delimit empty elements, or to delimit special Tcl character sequences involving backslashes , square brackets, etc. 
string [] ListSplit(string list) ListSplit( ) parses a string formatted as a Tcl list into an array of string elements.  The function understands the Tcl usage of quotes, braces and backslash sequences.  Not all strings are valid Tcl lists.  If an invalid list is parsed, the method call throws the FormatException.  Failure occurs when there are unmatched braces, unmatched quotes, or non-whitespace following braces or quotes.
void MessageTypeAdd(int stream, int function, SecsMessageReceiveDelegate callback)

delegate void SecsMessageReceiveDelegate(object sender, int stream, int function, bool send_reply, int transactionID, string TSN_data, string header)

Call this method to have SECS messages processed by your custom handler methods when the SecsHost has established communication with the equipment.  You can provide for new SECS message types, or you can replace the SecsHost handling of particular messages.  For example, you could take over the handling of S6F3 discrete data reports for equipment that uses non-standard formats.  Use the SendReply, SendS9, and SendAbort methods to send reply messages. 
void MessageTypeRemove(int stream, int function) This method is used to cancel SECS message handlers that you have setup using MessageTypeAdd or to cancel the handling of particular messages by the built-in SecsHost logic.  If you have called MessageTypeAdd for the specified message type, the Add is cancelled.  If you have not called MessageTypeAdd, the SECS server is told not to handle the message. Unhandled primary messages are replied to with an abort reply.
RcResult ParameterAdd(string varID, string ID_TSN, string value_TSN, string varName, string virtualName, string description)

struct RcResult {
   int rc;   // return code
   string result;
   }

This method is used to manually add parameter (ECV) definitions for equipment that does not support discovery of them using S2F29.  The varID argument value is the parameter identifier which is usually an integer.  The ID_TSN argument is the SECS item data type for the varID in TSN notation such as U4.  The value_TSN argument is the data type of the parameter value in TSN notation such as "F4".  The varName argument is a name for the parameter as defined by the equipment.  The virtualName argument is a name for the parameter chosen by the user.  The desciption argument can be used to provide guidance in selection lists.  If any of the arguments ID_TSN, varName, virtualName, or desciption are provided as null or empty strings, then default values are used:  U4 for ID_TSN,  the varID value as a string for the varName, and programmatic mapping of the varName value for the virtualName.

If the method succeeds, the rc field in the result structure is set to 0.  No error occurs if a definition with the same ID already exists - the other fields are updated per the call arguments.  A non-zero result indicates an error, and the result string should be examined.  Possible error return codes include:
-2  invalid varID
-3  invalid varName value 
-4  an error occured using the ID_TSN value to format the varID value as a SECS data item
-5 an error occured using the value_TSN value to format an example value
-9  unexpected SQL error

string ParameterUpdate(string varID, string newValue) Use this method to set the value of an Equipment Constant.  The return value is "0" for success, -1 and an error message if improper data is used, "1" if the variable does not exist, "2" if the equipment refuses to change the value at present, and "3" if the equipment rejects the new value. 
string [] ProcessProgramList() Obtain the current list of process programs using S7F19R.  The return value is null in case of error such as the equipment not being online or not supporting S7F19.
RcResult ProcessProgramDownload(string pathname)

struct RcResult {
   int rc;   // return code
   string result;
   }

Download a process program to the equipment using Stream 7 messages.  The process program must be in the process program directory.  If there is no saved table record in file ei_ppid.tab describing the process program file, the logic assumes that the file format contains both the PPID and PPBODY in text TSN notation which was the upload format used prior to May 2008.  The return value of the method call is a two element structure, a return code and text.  The return code is 0 for success, in which case the text will be the PPID (the process program name).  Possible error codes include:
-1 unexpected transaction error
-2 file not found
-6 SECS transaction error
-10 file open or read error
-11  no upload description data and the file data is not consistent with the older upload format



RcResult ProcessProgramLargeRequest(string ppid)

struct RcResult {
   int rc;   // return code
   string result;
   }
This method initiates the upload of a process program to the host using the message types of Stream 13 which are designed for large data set transfers.  Using these messages is more complex than the usual Stream 7 transfer messages so they are less commonly supported.  The ppid argument value is the process program identifier used by the equipment.  The upload logic saves only the data passed as the body of the process program in the uploaded file.  The ppid value used to identify the process program may not be a valid filename.  The upload logic assigns a unique filename to the uploaded program, using the ppid value if possible.  The logic also creates or updates a file of SQL statements, ei_ppid.tab, in the process program directory.  The ei_ppid.tab file saves the ppid value to filename mapping, as well as the datatype of the transferred program.  The ei_ppid.tab file has to be preserved along with the uploaded process programs in order to download them in the future.

The return value is a two element structure, a return code and text.  The return code is 0 if the transfer is initiated successfully as determined by the reply to S7F41.  The transfer is not complete when the method returns.   The large data set transfer logic receives the file in the subdirectory, dataset_transfer, of the directory set by the ProcessProgramDir property.  When the transfer is complete, if there is already an earlier version of the process program file in the process program directory, then there is a StateChange event with the name dataset_delete and the newvalue being the ppid value, which informs you that the earlier version file is being replaced.  Next, there is a StateChange event with the name dataset_upload and the newvalue being the ppid value which informs you of the successful upload completion.  Proper GEM equipment will also post UploadSuccess or UploadFailure data collection event reports to indicate completion as well. 

If the transfer does not complete successfully, there is additional status information is the SECS server table ei_dataset_xfer.   It is possible to query this table or subscribe to data changes of this table to better integrate transfer status information.

Possible error results include values of the ACKC7 reply to S7F41 and the following:
1 permission not granted
4 PPID not found
6 other error
-6  error when sending S7F41 or receiving the S7F42 reply
-14 A large PP receive is already in progress for ppid
-15 Stream 13 transfers are disabled either from configuration or initialization failure
-17 error when parsing the S7F42 reply



RcResult ProcessProgramLargeSend(string filename)

struct RcResult {
   int rc;   // return code
   string result;
   }
This method initiates the download of a process program to the equipment using the message types of Stream 13 which are designed for large data set transfers.  Using these messages is more complex than the usual Stream 7 transfer messages so they are less commonly supported.  The filename argument value is the file name of a previously uploaded process program in the process program directory.  The file is expected to contain only the data of a process program - this transfer method is not compatible with the previously used upload format that saved both the PPID and PPBODY in TSN notation.  The filename may not be the same as the process program identifier, ppid.  The saved information in the ei_ppid.tab file in the ProcessProgramDir is checked for a possibly different ppid

The return value is a two element structure, a return code and text.  The return code is 0 if the transfer is initiated successfully as determined by the reply to S7F37.  The transfer is not complete when the method returns.  After the data has been sent to the equipment, per GEM, the equipment is expected to verify the byte count of the download process program file using S7F29.  When this verification occurs with the correct byte count, there is a StateChange event with the name dataset_download and the newvalue being the ppid value.   If the transfer does not complete successfully, there is additional status information is the SECS server table ei_dataset_xfer.  

Possible error results include values of the ACKC7 reply to S7F37 and the following:
1 permission not granted
6 other error
-4  PPID filename not found
-6  error when sending S7F37 or receiving the S7F37 reply
-14 A large PP receive is already in progress for ppid
-15 Stream 13 transfers are disabled either from configuration or initialization failure
-17 error when parsing the S7F38 reply
RcResult ProcessProgramUpload(string ppid)

struct RcResult {
   int rc;   // return code
   string result;
   }

Upload a process program from the equipment to our file system.  The return value is a two element structure, a return code and text.  The return code is 0 for success, in which case the text will be the pathname of the saved program..  Possible error codes include
-1 unexpected transaction error
-2 upload refused or failed
-3 file system error
void SecsHost() 

void SecsHost(string spname, string dmhGroup)

void SecsHost(string spname, string [] cols, string [] row) 

void SecsHost(System.ComponentModel.Icontainer c)

The constructor.  The spname argument becomes the name of a global data item and a Tcl command in the SECS Server process.  It needs to be unique for each SecsHost instance, and not coincide with a keyword in the Tcl programming language.  The default value of spname is similar to host0. The name should be a single alphanumeric token. 

One of the constructor forms accepts property values as string arrays.  This form is used by our example Supervisor application.  Take a look at the source code for the SecsHost to understand the names used for the property values.  Essentially there is a direct mapping of properties to column names in an SQL table, ei_startup, which is used to manage interface startup information.

The dmhGroup argument becomes the DMH message system group name used by the SecsHost and SECS Server process.  If you are instantiating more than one SecsHost  instance in your process, construct each instance using the same dmhGroup name argument so that the SECS Server process is shared.  If you want to have both SecsHost and SecsPort equipment interfaces in the same application, use the constructor choices that allow you to specify the same dmhGroup argument value so the SECS Server is shared.  The groupname chosen needs to be unique among other DMH server instances on the computer where the SecsHost is executing.  The default value is GEMHOST.  This value does not conflict with the default value for Hume Datahub instances which is mbx, or the default value for the GemEqApp which is GEM.  The name should be a single alphanumeric token.

The  SECS Server process can be debugged remotely by connecting to the DMH mailbox SERVER_RPC@hostname:dmhGroup using the Inspect application or using the DMH mailbox SERVER_SQL@hostname:dmhGroup by the hubclient application.

void SendAbort(int stream, int primaryFunction) This method is used to send an F0 abort message in lieu of a proper reply.  It is used to indicate that the received message is not appropriate in the current context.
void SendReply(int stream, int function, int transactionID)

void SendReply(int stream, int function, int transactionID, string TSN_data)

This method is used by your custom SECS message handling logic to send reply messages either with or without data.  The reply data is formatted as Tcl Secs Notation text.
void SendS9(int function, string header) This method is used to indicate an error condition response to a received message - it is sent in lieu of a normal reply.  You will not receive a message type, unless you register for it.  In general, host software has less of a need to send Stream 9 messages than equipment software.
string SendSecsMsg(int stream, int function, bool reply_wanted, string TSN_data, bool wait4reply)

RcResult SendSecsMsgRcResult(int stream, int function, bool reply_wanted, string TSN_data, bool wait4reply)

struct RcResult {
   int rc;   // return code
   string result;
   }
 
 
 
 
 

 

These methods are used to send a primary SECS message, optionally indicating a reply is wanted, and optionally indicating that the call should wait for a reply.  A null or empty string value may be used for the TSN_data argument when a header only message is to be sent.  If a multiblock enquire/grant transaction is required for the message type, the SecsHost software does it automatically.  The reply value for the SendSecsMsg() method  is a string formatted as a two element list.  The first element is an integer code, and the second element is reply or diagnostic data.  The SendSecsMsgRcResult() method is identical in function, except that the return data is parsed into a structure.  The possible return values are:
-1
errorMessage  - the error message starts with "ERROR" and describes the fault
-2
DISABLED   - communication is disabled so the message could not be sent
-4 
SENDFAILURE   - the send attempt failed.
-5 
BUSY   - an eq_send call is currently active.  You should not see this error, since by design send commands are serialized using DMH messages to the connection's command mailbox.
-8
MULTIBLOCK_REFUSED - You are sending a message type that requires multiblock enquire/grant and the equipment failed to send the code 0 GRANT reply.  (Possible with message types S2F33, S2F35, S2F45, S4F19, & S7F3).
SENT_NO_REPLY  - sent successfully no reply requested
SENT_NO_REPLY_WAIT  - sent successfully, a reply was indicated, not waiting for the reply was indicated.  The reply will be ignored when it arrives.
ReplyTsnData   -sent ok, reply requested and received.
-6 
TIMEOUT  - sent ok, reply requested, no reply, T3 timeout. 
-7 
ABORTED  - sent ok, F0 abort reply received.
-8 
REJECTED  - sent ok, Stream 9 error message "reply".
String.StartsWith() is a simple way to check the return code, and ListElement( ) or ListSplit( ) are designed to parse the formatted reply message. Here is an example of working with the reply format:

   string reply = secshost.SendSecsMsg(1,17, true, "", true);
   // reply: <rc> <result> 
   string msg;
   if ( !reply.StartsWith("0 ") ) 
   {   msg = "unsuccessful transaction: " + reply;  }
   else   {
    // parsing "0 {B:1 0xnn}"
    string hexvalue = secshost.ListElement(reply, 1, 1);
    int intvalue = secshost.BinToInt(hexvalue);
    ...
   }

static void ServerSQLCmd(string sql) Send an SQL command to the SECS Server process without waiting for a reply.  This method is used by the SecsHostsoftware and made public in case of custom requirements.
static string ServerSQLReply(string sql) Send an SQL command to the SECS Server process and wait for the reply.  This method is used by the SecsHost software and made public in case of custom requirements.
static void ServerTclCmd(string tclCommand); Send a Tcl command to the SECS Server process without waiting for a reply.  This method is used by the SecsHost software and made public in case of custom requirements.  After a SecsHost instance has been constructed and the connection type set, the TclCmd( ) method should be used instead of this method for commands that are directed to a particular interface instance.  Why?  Doing so serializes the commands for a particular interface, and provides re-entrant execution protection.
static string ServerTclReply(string tclCommand); Send a Tcl command to the SECS Server process and wait for the reply message.  This call is used by the SecsHost software and made public in case of custom requirements.  After a SecsHost instance has been constructed and the connection type set, the TclReply( ) method should be used instead of this method for commands that are directed to a particular interface instance.
static int SuperSave() Save the SECS server table data including interface startup configurations.  You can write your own applications with your own persistence mechanisms.  Our example Supervisor application uses this method to save the state of the configured interfaces for the next session.
static void SupervisorStart (string DmhGroup) This method is the startup call for our Supervisor application example.  It restores data from the last SuperSave call, and instantiates all of the configured interfaces.  The interfaces that are configured with autoStart true, are enabled for communication.
static DataTable SecsHost.TableRead(DataTable table, string query) The TableRead and TableSchema static methods provide generic capability to create DataTable instances in your .NET application that clone data from the SECS Server process.  First, the TableSchema method is used to create an empty DataTable that has the desired schema.  Next, the TableRead method is used to load or refresh rows of data using a fresh query of the server table data. Look at the source code for the SecsHost AlarmTable method for an example.
static DataTable SecsHost.TableSchema(string tablename, string columns) Clone the schema of a Server Table or subset - see the description of TableRead directly above.
void TclCmd(string tcl) This method is used to send Tcl code to the SECS server command mailbox for the connection.  It is used by the SecsHost software and made public to support custom requirements.
string TclReply(string tcl)

RcResult TclReplyRcResult(string tcl)

struct RcResult {
   int rc;   // return code
   string result;
   }

These methods are used to send Tcl code to the SECS server command mailbox for the connection and wait for the evaluation result.  They are used by the SecsHost software and made public to support custom requirements.  With TclReply() the string return value is structured as a list and may be parsed using ListSplit or ListElement.  The first element is a return code for the evaluation with 0 meaning success.  The second element is the return value from the executed Tcl code, or an error message if the return code is not 0.  With TclReplyRcResult( ) the same data has been parsed and is returned as separate fields in the RcResult data structure.
int TraceSetup(string traceId, int periodSeconds, int totalSamples, int samplesPerReport, string SVIDs) Control TRACE Reports - a convenience method to send the S2F23R message.  If totalSamples is 0, the trace is disabled.  If totalSamples is greater than 0, you should insure that it is an even multiple of samplesPerReport.  The reporting period value specified in seconds, periodSeconds, is subject to equipment limitations.  The SVIDs argument is a white space delimited list of Status Variable identifiers.  The return values are 0 = success, 1 = too many SVIDs, 2 = no more traces allowed, 3 = invalid period specified, -1 = error such as not being in online communication, -2 = at least one unknown SVID, -3 at least one variable is not a Status Variable (class SV). 

The method also creates or updates event report configuration data so that the S6F1 trace reports are received as event reports with the CEID of TRACE_REPORT.  When there are multiple samples per report, the event report logic parses the received data into multiple event reports, one per sample.  In this situation you will usually want the CLOCK variable as one of the reported items to know the observation time of the sample.  If you want to have more than one trace report series active at a time, then you can use the MessageTypeAdd() method to register for the S6F1 messages and receive them directly without using the virtual event report receiving logic.

void Tracewin(bool show); The SecsHost is able to instantiate and manage a Form window class, Tracewin, which provides a controllable display of the data being exchanged across the SECS interface.  The argument is set to true to display the window, or false to close the window.  There are menu options to provide hex dump formatting of the data, or higher level descriptive formatting.  There are also menu actions to save the displayed data to the file system. 
RcResult VariableAdd(string varID, string ID_TSN, string varName, string virtualName, string description, string varClass)

struct RcResult {
   int rc;   // return code
   string result;
   }

This method is used to manually add variable definitions for equipment that does not support discovery of them.  The varID argument value is the variable identifier which is usually an integer.  The ID_TSN argument is the SECS item data type for the varID in TSN notation such as U4.  The varName argument is the name for the variable as defined by the equipment.  The virtualName argument is a name for the variable chosen by the user.  The desciption argument can be used to provide guidance in selection lists.  The varClass argument value is set to "SV" for Status Variables and "DVVAL" for Data Value variables.  If any of the arguments ID_TSN, varName, VFEIname, or desciption are provided as null or empty strings, then default values are used:  U4 for ID_TSN,  the varID value as a string for the varName, and programmatic mapping of the varName value for the VFEIname.

If the method succeeds, the rc field in the result structure is set to 0.  No error occurs if a definition with the same ID already exists - the other fields are updated per the call arguments.  A non-zero result indicates an error, and the result string should be examined.  Possible error return codes include:
-2  invalid varID
-3  invalid varClass value 
-4  an error occured using the ID_TSN value to format the varID value as a SECS data item
-9  unexpected SQL error

string [] VariableChoice() This method returns a list of variable names which are candidates for use in dynamic Event Report configuration.  A null value is returned in case of error.
string VariableGetId(string virtualNames)

string [] VariableGetId(string [] virtualNames)

These methods are used to map variable Virtual names assigned by using the VariableUpdate method or assigned by default when the variables are first known, to the identifiers used by the equipment.  The latter are typically integer values such as SVID's or ECID's.  If called with a string argument, the virtualNames value may contain 1 or more white space separated names, and the result will be a white space separated list of the corresponding Ids.  An empty result is returned for an unknown name value.  If called with a string array argument, each array element is expected to contain a single name, and a string array result is returned for the corresponding Id values.
HostVariableInfo VariableGetInfo(String varID)

public struct HostVariableInfo {
  public string varID;
  public string idTsn;
  public string varName;
  public string virtualName;
  public string description;
  public string varClass;
  public string valueTsn;
  public string varMethod;
  public string varValue;
  public string tLatest;
  public string units;
  public string minValue;
  public string maxValue;
  public string defaultValue;
};

This method returns the known configuration and value information of a variable or Equipment Constant Variable (ECV).  A structure with the varID set to null is returned for an unknown varID input value.  The information comes from the replies to messages that are sent during the online initialization, from data received in event reports and trace reports, or from the restored table data of a previous session.
string VariableGetVirtualName(string Ids)

string [] VariableGetVirtualName(string [] Ids)

These methods are used to map variable identifiers which are typically integer values (SVID, ECID, etc) to the Virtual names assigned by using the variableUpdate method or assigned by default when the variables are first known.  If called with a string argument, the Ids value may contain 1 or more white space separated Id values, and the result will be a white space separated list of the corresponding Virtual names.  An empty name result is returned for an unknown Id value.  If called with a string array argument, each array element is expected to contain a single Id, and a string array result is returned for the corresponding Virtual names.
DataTable VariableTable() This method returns a current subset of the SECS server variable table for the SecsHost instance.  The included columns are varID, varname, VFEIname, description, varclass, value_TSN, varmethod,  varvalue, host_setval, host_managed, and t_latest.
int VariableUpdate(string varID, string virtualName, string description) You are able to assign meaningful names and descriptions to the equipment variables using this method.  The virtualName values are used in Event Report configurations and as the variable names in the Event Report event data.  If the description field is passed as a null value, the current description is not changed.

SecsHost Built-in Features


This section of the document has information on the built-in features of the SecsHost software in regards to the SEMI E5 and GEM standards.
 

Built-In Variables and Events

The SecsHost software creates certain variable table records to hold configured property values.  These records are of little interest to the .NET developer since they are managed through property value settings.

There is only one other variable record of note.  The AUTO_INIT_RESULT variable exists to save the execution result when the initialization logic executes automatically.  It is common to configure this variable to be part of the event report for the AUTO_VIRT_INIT event.  This dynamic event report can be configured and received even if the underlying equipment does not support dynamic event reports.  The event report is created and managed by the SecsHost software.  There are three other events that are synthesized in the SecsHost software and presented to the application using the same mechanisms used to dispatch equipment based event reports.  Here is a list of the built-in driver events:

AUTO_VIRT_INIT
This event report occurs when the autoInit property is left at its default value of true, and the SecsHost attempts the initialization logic for the virtual reporting system automatically after establishing an online control state with the equipment.  The value of the variable is a two element list.  The first element indicates whether there was a trapped execution error during initialization.  The first element will ordinarily be 0 to indicate that execution proceeded without error.  The second element will be an error message if an execution error was trapped.  In the usual success case, the second element is the return code from the ei_initialize procedure.  The following return values are possible: 0 meaning success, 1 communication failure, 2 request online failed, 3 clock synchronization failed, 4 failed setting equipment constants, 5 failed disabling events, 6 failed enabling events and reports, 7 failed enabling disabling alarms, 8 spool initialization failed.  You can and should edit the properties of your SecsHost so the initialization does not attempt to use message types that your equipment cannot handle.
COMM_DISABLE
This event report occurs when communication with the equipment is lost.
COMM_ENABLE
This event report occurs when communication with the equipment is established (or re-established).
TRACE_REPORT
The SecsHost logic maps Trace Reports into Event Reports with this event name.  This lets you use common software to capture trace and event reports.

Built-in Handling of SECS Message Types

The E5 standard identifies data items used in message items with all uppercase letters such as CEID.  Typically, the standard allows for different data types to be used for a particular message item.  Historically, the host software has been required to know and use the specific data types that the equipment implements when the standard allows for different data types.  That is why the SecsHost has configurable properties for the data types that the built-in logic uses and that cannot be discovered automatically.  For most message types, the Hume SECS equipment software accepts any data type for a message data item as long as the value is equivalent.  This behavior cannot be assumed for other implementations.  The table below lists the subset of message types where the SecsHost has built-in handling of the message type, or sends the message type as part of its built-in logic.  Other message types can be easily sent by your application using the SendSecsMsg method or received and handled by your application using the MessageTypeAdd method.  The Data Formats in the table below show the Host message formats in situations where host and equipment send the same message type with different data formats.
 
Type Sender Data Format Comments
S1F1R H, E   "Are You There?"
S1F2 H L "On Line Data"
S1F3R H L [<SVID>]*
<SVID>  := {U4 <varID>}
"Selected Equipment Status Request" 
S1F4 E L [<SV>]* "Selected Equipment Status Data"
The data type of the SV value depends on the variable.
S1F11R H L [<SVID>]*  "Status Variable Namelist Request"
S1F12 E L [{L:3 <SVID> <SVNAME> <UNITS>}]+  "Status Variable Namelist Reply"
S1F13R H,E L  "Establish Communications Request"
S1F14 H L:2 {B 0} L  "Establish Communications Request Acknowledge"
S1F15R H   "Request OFF-LINE"
S1F16 E <OFLACK> "OFF-LINE Acknowledge"
S1F17R H   "Request ON-LINE"
S1F18 E <ONLACK> "ON-LINE Acknowledge"
       
S2F13 H L [<ECID>]* "Equipment Constant Request"
S2F14 E L [<ECV>]* "Equipment Constant Data"
S2F15R H L [{L:2 <ECID> <ECV>}]* "New Equipment Constant Send"
S2F16 E <EAC> "New Equipment Constant Ack"
S2F17R H   "Date and Time Request"
S2F18 E A:16 YYYYMMDDHHMMSScc 
A:12 YYMMDDHHMMSS
"Date and Time Data"
S2F23R H L:5 <TRID> <DSPER> <TOTSMP> <REPGSZ> {L [<SVID>]+}  "Trace Initialize Send"
S2F24 E <TIAACK> "Trace Initialize Acknowledge"
S2F25R H,E B [<b>]* "Loopback Diagnostic Request"
S2F26 H B [<b>]*  "Loopback Diagnostic Data"
S2F29R H L [<ECID>]* "Equipment Constant Namelist Request"
S2F30 E L [L:6 <ECID> <ECNAME> <ECMIN> <ECMAX> <ECDEF> <UNITS>]+  "Equipment Constant Namelist"
S2F31R H A:16 YYYYMMDDHHMMSScc 
A:12 YYMMDDHHMMSS
"Date and Time Set Request"
S2F32 E <TIACK> "Date and Time Set Acknowledge"
S2F33R H L:2 <DATAID> {L [{L:2 <RPTID> {L [<VID>]*}]*} "Define Report"
S2F34 E <DRACK> "Define Report Acknowledge"
S2F35R H L:2 <DATAID> {L [<CEID> {L [<RPTID>]*}]*} "Link Event Report"
S2F36 E <LRACK> "Link Event Report Acknowledge"
S2F37R H L:2 <CEED> {L [<CEID>]*} "Enable/Disable Event Report"
S2F38 E <ERACK> "Enable/Disable Event Report Acknowledge"
S2F39R H L:2 <DATAID> <DATALENGTH> "Multi-block Inquire"
S2F40 E <GRANT> "Multi-block Grant"
       
S4F25R H L:2 <DATAID> <DATALENGTH> "Multi-block Inquire"
S4F26 E <GRANT> "Multi-block Grant"




S5F1R E L:3 <ALCD> <ALID> <ALTX> "Alarm Report Send"
S5F2 H B 0 "Alarm Report Ack"
S5F3R H L:2 <ALED> <ALID> "Enable/Disable Alarm Send"
S5F4 E <ACKC5> "Enable/Disable Alarm Ack"
S5F5R H <ALID vector> "List Alarms Request"
S5F6 E L [{L:3 <ALCD> <ALID> <ALTX>}]* "List Alarm Data"
S5F7R H   "List Enabled Alarm Request"
S5F8 E L [{L:3 <ALCD> <ALID> <ALTX>}]* "List Enabled Alarm Data"
       
S6F1 E L:4 <TRID> <SMPLN> <STIME> {L [<SV>]+} "Trace Data Send"
S6F3[R] E L:3 <DATAID> <CEID> [{L:n {L:2 <DSID1> {L:m [{L:2 <DVNAME> <DVVAL>}]*}}]* "Discrete Variable Data Send"
S6F4 H B 0 "Discrete Variable Data Ack"
S6F5R E L:2 <DATAID> <DATALENGTH> "Multi-block Data Send Inquire"
S6F6 H B 0 "Multi-block Grant"
S6F11R E L:3 <DATAID> <CEID> {L [{L:2 <RPTID> {L [<V>]+}}]+} "Event Report Send"
S6F12 H B 0 "Event Report Ack"
S6F13R E L:3 <DATAID> <CEID> {L [{L:2 {U4 <rptid>} {L [{L:2 {U4 <vid>} <V>}]+}}]+} "Annotated Event Report Send"
S6F14 H B 0 "Annotated Event Report Ack"
S6F23R H <RSDC> "Request or Purge Spooled Data"
S6F24 E <RSDA> "Request or Purge Spooled Data Ack"
       
S7F1R H,E L:2 <PPID> <LENGTH> "Process Program Load Inquire"
S7F2 E,H <PPGNT> "Process Program Load Grant" - The SecsHost always sends B 0.
S7F3R H,E L:2 <PPID> <PPBODY> "Process Program Download"
S7F4 E,H <ACKC7> "Process Program Download Acknowledge"
S7F5R H,E <PPID> "Process Program Upload Request"
S7F6 E,H L:2 <PPID> <PPBODY> "Process Program Upload Data"
S7F19R H   "Current Process Program Dir Request"
S7F20 E L [<PPID>]* "Current Process Program Data"




S*F0     abort replies are handled as a special case of reply
S9F1 E <MHEAD> "Unknown Device ID"  - The SecsHost has logic to automatically correct this error when first establishing communication.
S9F3 E <MHEAD> "Unknown Stream"
S9F5 E <MHEAD> "Unknown Function"
S9F7 E,H <MHEAD> "Illegal Data"
S9F9 E,H <MHEAD> "Transaction Timeout"
T3 timeout
S9F11 E <MHEAD> "Data Too Long" 
       
S10F1 E L:2 {B 0} {A <text>} "Terminal Request"
the example application handles this message type
S10F3R H L:2 <TID> {A <text>} "Terminal Display, Single"
 S10F4  E  <ACKC10>  

License Terms

Subject to Change Without Notice

The Hume .NET SecsHost software is licensed for development and runtime use at no additional charge for computers that are licensed for development use of the Hume Integration Datahub SDK.

Hume Integration is also pleased to offer separate runtime licenses for using the SecsHost software on systems that are not licensed as development systems.  Contact Hume Integration for more information.


Document Version

Date of last revision: $Date: 2008/08/12 14:00:24 $