SecsHost - A .NET Component for Host SECS Interfaces


The SecsHost .NET component provides a high-level starting point when deploying Host SECS Interface software using the Microsoft .NET Framework.   The 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 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 the latest .NET Framework are distributed in a .zip archive DotNet40HostApp.zip.  The projects in the archive target .NET varsion 4.0 and are compatible with Visual Studio 10 and newer.  There is also an older archive available, DotNet20HostApp.zip.  This archive targets .NET version 2.0 and is compatible with Visual Studio 2005.  Both archives are compatible with the latest .NET and Visual Studio versions.  However, the older archive requires migration which is done automatically when loaded by a newer Visual Studio version.   A Visual Basic example Host Application is separately downloaded as VBHostApp40.zip for .NET 4.0+ and as VBHostApp.zip for .NET 2.0+.  An archive for .NET Core which enables running on Linux and other platforms but does not support Windows Forms is also available. 

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.  

The distribution is designed and tested for up-to-date Windows Professional versions. 

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 DotNetXXHostApp.zip archive to a directory of your choice such as the Projects directory in your Visual Studio Projects folder. If you have already installed the Hume Datahub SDK, you should not add the files in the DotNetXXHostApp.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.

Installation of the example Visual Basic software from the VBHostApp.zip archive or VBHostApp40.zip is the similar.  Unzip the archive file in the same directory chosen for the DotNetXXHostApp.zip so that the topmost VBHostApp directory is a peer directory to the GemHostApp, SecsHost, and the SecsPort directories.   This is a starter application that is not integrated into the documentation.  It is provided for you to extend as you see fit - please review the comments in the VBHostApp/VBHostApp/ConsoleApp.vb source code file for usage information.

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.

The source files are provided with Project and Solution files for an older version of Visual Studio for compatibility with the projects of long time users.  When opening the solution files with newer Visual Studio versions, accept the default action of migrating the project files, and you do not need a backup.  It only takes a moment.  After migration you can update the projects to target a newer .NET version if you like.  Future updates can be done by replacing newer source files and continuing use of your migrated project and solution files.

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,   and (2)  the gem2/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.

Environment Variables HUME_SUPERVISOR_DIR,  HUME_SUPERVISOR_DMHGROUP

An application that uses the SupervisorStart() method such as the example Hume host application can be told to use a specific base working directory for application data files by setting the environment variable, HUME_SUPERVISOR_DIR.  The directory can be specified as a relative path to the .NET app working directory, or as an absolute path.  Unix style slashes should be used.  The directory should already exist.  The default directory for application data files is the Datahub SDK gem2/server directory or the directory where the SecsServer.exe program is found.  The file system is used for saving and loading *.tab SQL files, log files, and recipe transfers.

A custom application can use the SupervisorDirectory property to explicitly set the working directory for application data files.  If this property is set any setting of the HUME_SUPERVISOR_DIR environment variable is ignored.

When multiple Supervisor applications are run on a single computer, they should be started with different DMH message system Groupnames.  The example Hume .NET Supervisor app checks for the environment variable HUME_SUPERVISOR_DMHGROUP during startup.  If a value is found, the value is passed to the SupervisorStart() method instead of the default value "GEMHOST".

Development

You can use the Hume SecsHost .NET Component with your own application either by adding References to the SecsHost.dll, SecsPort.dll and HumeDMH.dll files, or by adding the SecsHost and SecsPort project to your application solution.  It is our experience that you are better off adding the projects to your application solution because you will see better prompting when editing code using the Visual Studio IDE.  

To add the projects to your application solution, follow any of the usual procedures - you can use the main menu (File/Add/Existing Project...) or right click on your solution in the Solution Explorer (Add/Existing Project...).  Navigate to the SecsHost folder and choose the SecsHost.csproj file.  Similarly add the SecsPort project by navigating to the SecsPort folder and choosing the SecsPort.csproj file.

If you choose instead to simply add references to your existing project, you add references to the SecsHost.dll, SecsPort.dll and the HumeDMH.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.

When using the Hume GemHostApp example solution the first time, depending on your circumstances, you may need to fixup the references to the DLLs and dependent project files.   Start with the SecsPort project as displayed in the Solution Explorer and see if the Reference to HumeDMH is resolved successfully.  If not, remove the existing reference, and then add it back,  using the Add Reference... action from the right-click menu on the References section.  Click on the Browse tab of the Add Reference dialog, and then select the HumeDMH.dll file in the SecsHost/bin/Release directory.   Next, examine the SecsHost project and display the References.  If the HumeDMH reference is not resolved, then remove the reference and add it back by Browse'ing to the same DLL file as you did for the SecsPort project.  If the SecsPort reference is not resolved, remove it, and again use the Add Reference... action.  This time, press the Projects tab of the Add Reference dialog, and select the SecsPort project.  Finally, examine the GemHostApp project in the Solution Explorer window.  In the Reference section, if the SecsHost or SecsPort references are not resolved, remove them and add them back as dependent projects from the Projects tab.  If the HumeDMH reference is not ok, remove it and add it back by browsing to the DLL.

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.  We suggest you get started by running the GemHostApp.exe application and take a look at the various windows and dialogs in action.  You probably want to use the SecsHostEditor 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.  Decide 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 and code to your project.

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

  1. You can use the SecsHost component with or without user interface windows being present.  For GUI code, we recommend you add event handlers from the Load event logic for your window, and remove these event handlers 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.
  2. 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.
  3. Setup your event handlers for event callbacks.  The reception of Event Reports and Alarm Reports are dispatched into your application as events.  These events are executed by the same thread that constructed the SecsHost instance.  You want to use the main thread of your program to construct the SecsHost so it is safe to directly update window controls with event data.  
  4. 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.
  5. 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.
  6. 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.
  7. 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, trigger your custom logic from receiving the AUTO_VIRT_INIT event report.  This event report occurs every time after an online control state has been entered and the automatic initialization has performed the event report setups.  You will receive this event after recovery from any communication interruption in the future in addition to during the startup.  You can use the AUTO_INIT_RESULT variable to determine whether the initialization logic ran successfully.  See the EventReportDefine method, the list of Built-in events, and the EventReport event description.  You can also receive status indications from the StateChange event.  You do not need to re-invent initialization logic - take advantage of the configurable and robust automatic initialization by using the AUTO_VIRT_INIT event.
  8. 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.
  9. 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.
  10. 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.
  11. Call CommDisable to disable host communications.  It is called automatically in the SecsHost Dispose method.


Tcl Secs Notation

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.  With ASCII string data that contains null characters, the Unicode replacement character \uFFFD may optionally be used by the .NET application as a replacement for the null character \u0000.  This provides a work-around for the behavior of the .NET System.Text.StringBuilder class which truncates StringBuilder text at the first null character when the ToString() method is used.  The Hume .NET API converts the replacement character to the modified UTF-8 byte sequence for null when communicating with the SECS Server.

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 example application is missing code to manually 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 used to 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.   There are also methods provided to explicitly define items in code statements.
 

Custom SECS Message Handling

Use the method MessageTypeAdd to have SECS messages routed to your event handling code.  Use SendReply to respond to the inbound message.  The method SendSecsMsg can be used to initiate sending a new SECS message with optionally waiting for a reply message.  The SendSecsMsg method has an option to execute using a background thread.  With this option, events are still processed, and your application can continue to receive report events, or alarms.  Because of the internal design of the SecsPort, these other method calls are not blocked or delayed because your handler is busy with a conversation.  The API is threadsafe so if you want to start and use your own threads to make method calls, you may.  However, the SendSecsMsg method does not permit re-entrant execution if using the background thread.  If you do not choose to wait for a reply, sending a new message is nearly instantaneous.  Therefore, the re-entrancy restriction only affects usage when you choose to wait for a reply message and you elect to use the background thread.  You may need to disable and enable button actions that use SendSecsMsg with the wait reply option to prevent inadvertant re-entry.  The background thread option eliminates the risk of your GUI application being unresponsive when the host fails to reply promptly, but realize that it allows button actions to be re-entered.

Logic in your application can send SECS messages or initiate conversations using the SendSecsMsg method without choosing to use the background thread.  In this mode you will avoid a re-entrant execution error return because multiple invocations of SendSecsMsg are serialized in a DMH message system queue.  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 the cases where you wait for a SECS reply message, when using HSMS, under most circumstances, the host's reply or failure to reply will be resolved within a few seconds.   The unusual circumstance is that you still have a TCP/IP connection to the host so your send is successful, but then the host does not reply, and a timeout takes the full T3 period.  So the default choice of the SendSecsMsg logic is to use the background thread if you are waiting for the reply.  With SECS-I serial communication, timing is completely 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 the sending thread being in an unresponsive wait to determine if a send is successful, or in a long wait to obtain the reply.  So you may want to indicate use of the background thread with a SECS-I connection.

SendSecsMsg and Threading Choices Summary (SecsHost)
Calling Thread/ WaitForReply
useWorkerThread=true
useWorkerThread=false
GUI thread, WaitForReply=true
(useWorkerThread defaults to true)
Events are dispatched.  A re-entrant execution error is possible.  You may want to disable and enable button actions since the GUI stays responsive.
Events are not dispatched.  A re-entrant execution error is not possible because multiple invocations are serialized in a DMH message system queue.  The GUI may be unresponsive if the other party does not respond promptly.
GUI thread, WaitForReply=false
(useWorkerThread defaults to false)
Events are dispatched.  A re-entrant execution error is possible but highly unlikely with HSMS since the method returns almost immediately.
Events are not dispatched.  A re-entrant execution error is not possible.   For HSMS communication, the method call returns almost immediately.
Other thread, WaitForReply=true
(useWorkerThread defaults to false)
Event dispatching is not affected.  A re-entrant execution error is possible. 

Since you have your own worker thread, go ahead and use it either by letting the useWorkerThread choice default, or by setting it false.
Event dispatching is not affected.  A re-entrant execution error is not possible.

This is a smart choice to provide your own worker thread(s) but it adds complexity to your application.
Other thread, WaitForReply=false
(useWorkerThread defaults to false)
Event dispatching is not affected.  A re-entrant execution error is possible but highly unlikely with HSMS since the method returns almost immediately. Event dispatching is not affected.  A re-entrant execution error is not possible.  For HSMS communication, the method call returns almost immediately.

You should never wait for a reply unless you have a valid reason to do so.   You can use the MessageTypeAdd to register handling code for the asynchronous receiving of replies too.

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 constructed by the SupervisorStart method.  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 equipment 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.
static
ListDictionary SecsHost.Instances
This static data item is a dictionary to the instantiated SecsHost objects.  The key value of each dictionary entry is the Name property of the SecsHost instance, and the value of each dictionary entry is a reference to the SecsHost object.
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.



bool PPbodyFileMode
This boolean property controls whether S7F3 and S7F6 process program transfer messages are handled by direct data transfers to and from files bypassing handling the messages in memory.  This avoids possibly large memory allocations and enables transferring process programs that are as large as the 16 meg limit of Stream 7.   Setting the option also reduces the data that is seen by tracing and logging - only summary information can be seen in the diagnostics.  The default value is false.  It is recommended to set the option true if process programs sizes are as large as 1 meg.  The mode is transparent to the application; the ProcessProgramDownload and Upload methods work the same and the built-in SECS Server Stream 7 receiving with StateChange notifications work the same irrespective of the PPbodyFileMode setting.
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. 
bool ReportsUnlink
This boolean property accommodates certain equipment that requires the S2F35 report link message to be sent first with an empty list of reports, and then sent again with the desired reports.  The target equipment features built-in reports that must be explicitly unlinked in this manner.  The default value is false. meaning extra S2F35 messages are not sent.  The property value affects the event report setup logic that executes when Initialize is called, or during automatic initialization.
int RTY SECS-I maximum send retry, range 0..31, default 3
bool secsTraceUseGuiThread Set this property true to force SecsTrace events to occur in the SecsHost constructor thread, which is typically the main GUI thread of the application.   You would only set this true if you were receiving the SecsTrace events in your application instead of using the built-in Trace Window class.  The behavior prior to August 2013 was to post these events on the main GUI thread.  The behavior was changed to improve the GUI performance of the Tracewin class.   The default value is false.
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 IGNORE.
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.
static string SupervisorDirectory
The default directory for file system saving and loading is where the SecsServer.exe program is found, or where the Datahub SDK gem2/server directory is found.  This property can be set by a custom application in order to specify a different base directory for file system writing and reading.  The directory argument may be relative to the .NET application working directory or an absolute directory path specification.  Use slashes for path separators, for example, "C:/Users/cim/data".  When used, the property must be set before SupervisorStart() is called or any connections are instantiated, and may only be called once.  Specifying a system environment variable, HUME_SUPERVISOR_DIR, with the desired directory value works as an alternative to using this method for applications that call the SupervisorStart() method.  Setting the property affects all SECS connection instances including possible SecsPort instances which are using the SECS Server process.

Applications that directly instantiate SecsHost instances instead of calling SupervisorStart() can also use this property to specify the root working directory for file system writing and reading for all SecsHost instances.  The property value must be set before instantiating any SECS connection instances.  Here we assume these apps do not use the SecsHost constructor that uses table rows from the supervisor startup table.
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 

int TraceLogMaxWidth This property allows setting an approximate maximum number of characters in text lines when saving Trace data to log files.  Lines that are longer than the maximum are trimmed and a short explanation message is appended.  The property helps you reduce the size of the log files when large Process Programs are transferred or other long data messages are logged.  The value may be configured as 0 for no limit, or a value greater than or equal to 1000; the default is 4000.
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 useS1F21 Whether to use S1F21 during initialization to determine the Data Value Variables (DVVALs).  The default value is false.  The message type is not supported by older equipment.
bool useS1F23 Whether to use S1F23 during initialization to determine the Data Collection Events.  The default value is false.  The message type is not supported by older equipment.
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.
bool SecsHost.useUserControls
This is a static boolean property to provide for disabling the usual instantiation and use of UserControl instances for the purpose of passing events to the main GUI thread of the application.  The default value is true.  Disabling the use of UserControl instances has been found necessary for compatibility with deployment as a Windows Service using Windows Communication Foundation (WCF).  The desired value of this property should be set before starting the Supervisor logic or creating SecsHost instances.  When the value is set false, the logic will not invoke the SendSecsMsg background worker thread by default, and therefore Application.DoEvents() will not be called by default.


 
SecsHost Events
Event Handler and Argument Data  Description


All event handlers - NOTES
 
 
 
 
 

 

We are documenting events in this section.  Events are easier to develop with than other delegate callbacks because of better handling by the .NET IDE tools.  

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 executed by the same thread that instantiated the SecsHost.  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;
}
 
delegate type AlarmReportEventHandler.

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.

We expect you to use our example application in addition to this document for coding help.  Here is an example code sequence generated by the IDE that shows how to receive this event:

// secshost is our SecsHost instance
secshost.AlarmReport += new AlarmReportEventHandler(secshost_AlarmReport);

 void secshost_AlarmReport(object sender, AlarmReportEventArgs e)
        {
            Console.WriteLine("Alarm ALID=" + e.ALID);
        }

void EventReport(object sender,EventReportEventArgs e)

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

delegate type EventReportEventHandler

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. 

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.

static void
SecsHost.SecsHostsUpdated(object sender, EventArgs e)

delegate type EventHandler

The SecsHostsUpdated event happens when a windowing application calls the Editor method and the user successfully creates a new SecsHost instance or changes the startup configuration of an existing instance.  The event is used by our example applications to trigger a refresh of the displayed list of SecsHost instances.
void SecsMsgReceive(object sender, SecsMsgReceiveEventArgs e)

class SecsMsgReceiveEventArgs : EventArgs
    {
        public int stream;
        public int function;
        public bool sendReply;
        public int transactionID;
        public string TsnData;
        public string header;
}

delegate type for events SecsMsgReceiveEventHandler
See the MessageTypeAdd method described in the next section  to register to receive specific SECS messages in your application with the SecsMsgReceive event.

Events are easier to use than other callbacks.  However, it is also possible to use a delegate callback to have a specific message type delivered to a custom handler.  There is a form of MessageTypeAdd using the following delegate type:

delegate void SecsMsgReceiveDelegate(object sender, int stream, int function, bool send_reply, int transactionID, string TSN_data, string header)
void SecsTrace(object sender, SecsTraceEventArgs e)

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

delegate type SecsTraceEventHandler

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 SecsHost.ServerDisconnected(object sender, EventArgs e)

delegate type EventHandler
If the SECS Server process exits your application receives the ServerDisconnected event.  This event is not ordinarily expected.  A production application will limit access to the SECS Server windows so that users will not use the Exit menu items on these windows.
static void SecsHost.ServerError(object sender, ServerErrorEventArgs e)

class ServerErrorEventArgs : EventArgs {
string message;
}

delegate type ServerErrorEventHandler

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;
}

delegate type ValueChangeEventHandler

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. 
Equipment Constant Update see ParameterUpdate Equipment Constant is a misnomer; we have started calling ECVs Equipment Configuration Variables, and we invite you to do likewise.


void Editor(bool fileSaveOnOK)

static void SecsHost.Editor(SecsHost sh, bool fileSaveOnOK)
The Editor methods are used in a windowing application to bring up the Startup Configuration Editor window.  The editor window provides for editing the connection properties, timers, and use of various message types during initialization.  If the SecsHost argument is passed as null to the static method (Nothing in Visual Basic), then the editor is used to create a new SecsHost instance.  The boolean argument fileSaveOnOk controls whether the edited configuration is saved on the file system as a row in the SQL table file, ei_startup.tab, when the user commits his editing changes by pressing the Ok button.  The saved startup configurations are used by applications that call SupervisorStart to initialize the set of configured SecsHost instances.  An application that calls SupervisorStart will either set the fileSaveOnOk flag true when invoking the editor, or it will call the SuperSave method when the user has indicating saving the current configuration is desired.

Whether the startup configuration is saved or not, the editor does affect the current properties of a SecsHost instance when the user accepts the editing changes by pressing the Ok button.  An application can have its own saving and restoring techniques and not use the SupervisorStart method.  The editor logic posts the SecsHostsUpdated event when the user has created a new SecsHost instance or has successfully edited an existing instance.  This event is the trigger for updating a displayed list of interfaces or for custom saving of a changed configuration.  The application can iterate the existing instances using the SecsHost.instances ListDictionary.
 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.
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.
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.
string [] EventReportConfigEx(string virtualName) This method returns a five element string array for the configuration of an event report.  The elements are CEID, virtualName, Description, Variables, and RPTID.  Use ListSplit to split the Variables element into the individual virtual variable names.  The RPTID value is an empty string if there is no SECS Report ID associated with the event or if the associated RPTID value is the same as the CEID value.  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.
int EventReportDefine(string eventName, string [] varNames)

int EventReportDefine(string eventName, string [] varNames, string rptID)
Create or update an event report configuration. 

An event report is a set of variable values that is sent from the tool using S6F11 or S6F13 when the tool control state is online and a particular event occurs. This method configures SECS server table data that represents a desired report, data that links the specified event to the report, and data that indicates that the event should be enabled for reporting. The desired configuration of event reporting is communicated to the tool using S2F33, S2F35, and S2F37 when the initialize method is called, or whenever the tool enters an online control state and automatic initialization is enabled.

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 may want to call the Initialize method to have your desired event reports setup and enabled with the equipment.  The initialization logic is executed automatically whenever an online control state is established if the AutoInit property is true.

For a less complex application, you may wish to define a distinct event report for each equipment event type that you wish to receive in the application. With the simplest form of this method call, you do not specify the optional SECS Report ID (RPTID) value, and by default the logic creates a distinct event report using the CEID value as the underlying RPTID value.

It is possible to apply a single call to this method to more than one tool event by assigning the same virtual event name value to multiple tool events. The virtual event name value is assigned using the EventUpdate method. When this event naming trick is used and the SECS RPTID value is not specified, the like named events are configured to have separate and equal report definitions using their CEID values for RPTID values.

The SECS Report ID (RPTID) value needs to be specified for certain less capable equipment that are not able to use the CEID values for RPTID values. There is at least one tool type that only allows RPTID values from 1 to 255 (type U1) but has CEID values outside of this range. Specifying the RPTID value can also be useful to apply a single event report definition to more than one event type. If this is done, the latest update of the event report definition is applied to all of the events that are associated (linked) to the specified RPTID. So specifying a common RPTID can be used to reduce the editing needed to manage and update a set of similar event types.

A knowledgeable user can skip using this API and use SECS messages directly to fully exploit the ability to re-use event report definitions with multiple tool events and to have more than one event report definition linked to a tool event. This API only configures 1 or 0 event reports per tool event.

The method returns 0 for success, -1 if the eventName is not known, -2 if a variable is not known or -3 if the specified or defaulted RPTID value is not compatible with the tRPTID property.

void EventReportDelete(string eventName) Delete an event report configuration.
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.

bool Linktest() Synchronously test a COMMUNICATING HSMS connection to verify that the link is responsive.  May take up to timeout period T6 to return. On failure, the HSMS socket connection is closed and the CommState will no longer be COMMUNICATING.  Useful to force a broken connection to be discovered. Some tools respond to a linktest even when not responsive to SECS messages. For these tools, SendSecsMsg with S1F1R is advised instead. Returns true if the link is up, false if the link is down
void LinktestAsync() Cause a linktest HSMS control message to be sent to test if a healthy connection still exists.  Forces discovery of a bad connection after a T6 timeout. If the link test fails, the HSMS socket connection is closed and the CommState is no longer COMMUNICATING.  The method is useful for periodic polling if there is an issue with broken connections not being discovered soon enough. Some tools respond to a linktest even when not responsive to SECS messages. For these tools, SendSecsMsg with S1F1R is advised instead.
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)

void MessageTypeAdd(int stream, int function, SecsMsgReceiveDelegate callback)

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

Use the first form of MessageTypeAdd to have received SECS messages of the specified type delivered to your application as a SecsMsgReceive event.  Events are easier to code than other callbacks because of the support of the IDE.

Use the second form of the method to have SECS messages dispatched to your callback handler.

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 method to send reply messages. 

Parsing code for any standard SECS message type may be copied from the Hume website.

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 ECV parameter.  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 spname value should also not be a simple token like a, i, or spname which might conflict with a variable name in the SECS server logic.  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.
RcResult SendSecsMsg(int stream, int function, bool replyWanted, string TsnData, bool waitForReply)

RcResult SendSecsMsg(int stream, int function, bool replyWanted, string TsnData, bool waitForReply, bool useWorkerThread)

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. The stream and function arguments are the message type identifiers of SECS.  The TsnData argument is a string representation of the message body using the type notation of TSN.   The list methods ListAppend and ListJoin are recommended for building complex messages to insure valid formats. 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 methods differ in that the second form provides the boolean argument useWorkerThread which is used to explicitly specify whether a background thread should be used to perform the call.   If this option is defaulted by using the first form, then a worker thread is used if you are executing on the thread that constructed the SecsHost, and you are waiting for a reply.  When the background thread is used, the method call continues to service the application event loop.  See the detailed discussion above.

The SendSecsMsg() return value is a structure containing an integer return code and a string result.  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   - the background thread is currently active.  You may see this error when the worker thread is used if you re-enter your sending logic.  If the worker thread is not used, 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.  Enquire/grant messages by default are not used for HSMS communication, but it is possible to enable them. (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.
-9
REJECTED  - sent ok, Stream 9 error message "reply".
ListElement( ) or ListSplit( ) can be used to parse a reply message. See the example application code and the source code of the SecsHost component.

Prior to June 2009,  the SendSecsMsg method returned a string result and the method SendSecsMsgRcResult was used to obtain the RcResult structure.  The RcResult class does support casting to a string result if the older format is desired.
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 SecsHost software 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.
void StartupSync()
This method creates or updates a row in the SECS Server ei_startup SQL table with the property values of the SecsHost instance.  The method supports the persistence of startup information used by the Supervisor application.  The tables used by the SECS Server are described in the Tcl/Tk SECS/GEM application document.
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.  The tables used by the SECS Server are described in the Tcl/Tk SECS/GEM application document.
static int SuperSaveStartup()
Saves only the startup configurations of the current SecsHost instances as the file of SQL statements, ei_startup.tab, in the working directory of the SECS Server.  
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.

If the application has not set the SupervisorDirectory property, a check is made for the existence of a system environment variable HUME_SUPERVISOR_DIR when this method is executed.  If a value exists, the SupervisorStart method sets the SECS Server working directory using the value before attempting to read or write application data.
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.  The tables used by the SECS Server are described in the Tcl/Tk SECS/GEM application document.
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 method can also be used to insure that variable definitions exist and reports using them can be defined before initialization logic is executed.  The most common scenario is that initialization logic is run and discovered data is saved by calling SuperSave() during a prior session, and this method is not used.  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 virtualName should be unique.  System assigned virtualName values are described above with the EventReport event description.  If both the varName and the virtualName values are set to the varID value, the built-in initialization logic of processing S1F12 will replace the varName and virtualName values with system computed values.  Therefore, provide a different varName value if you wish to use the varID value as the virtualName. The description 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 description 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.
RcResult VariableQuery(int varID)
RcResult [] VariableQuery(int [] varID)
RcResult VariableQuery(String varName)
RcResult VariableQueryVirtual(String virtualName)

struct RcResult {
   int rc;   // return code
   string result;
   }
These methods are used to obtain the value of a Parameter or Status Variable using the numeric or name identifier.  The varName argument represents the name given the variable by the equipment.   Note that some equipment has the same variable names used more than once.   The VariableQueryVirtual method uses the virtual variable name as the argument value which is unique for each variable.   There is also an array version of VariableQuery that asks the host for one or more variable values in one method call, and returns an array of return code values and results.  With the array version, if you combine querying for Parameters and Status Variables, then there will be two SECS message exchanges to query the values according to their type. 

An alternative to these methods that can include DVVAL variables is to define an event report that includes the desired variables, and then to ask for the event report using SendSecsMsg to send S6F17R.

For the methods to succeed, you must be communicating in an online state, and the variables must be known from the replies that are received during online initialization to S1F11 and S2F29.  The variable data can either be discovered during the current session, or known by loading variable data saved from a previous session.

If the method succeeds, the rc field in the result structure is set to 0.   A non-zero rc result indicates an error, and the result string can be examined for a description.  Possible error return codes include:

-1 unexpected error
-2  communication is not enabled
-3 unknown identifier (can occur if initialization queries have not been completed)
-6  no reply TIMEOUT, abort reply, or Stream 9 error reply
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 SecsHost data collection 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.  When the event is posted, the value of the AUTO_INIT_RESULT variable is set to 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.
COM_DISABLE
This event report occurs when communication with the equipment is lost.
COM_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"
S1F21R H L:0 "Data Variable Namelist Request"
S1F22 E L:n {L:3 VID DVVALNAME UNITS} "Data Variable NL Reply"
S1F23R H L:0 "Collection Event Namelist Request"
S1F24 E L:n {L:3 CEID CENAME {L:a VID}} "Collection Event NL Reply"
       
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"
S7F27R
E
L:2 {A <ppid>} {L {L:3 {B <ackc7a>} {U4 <seqnum>} {A <errw7>}}}
"Process Program Verification Send"
S7F28
H

"Process Program Verification Acknowledge"
S7F29R
E
{U4 <length>}
"Process Program Verification Inquire"
S7F30
H
<PPGNT>
"Process Program Verification Grant"
S7F37R
E, H
A <dsname>
"Large Process Program Send"
The sender wishes to send a large process program using Stream 13 messages.
S7F38
E, H
B <ackc7>
"Large Process Program Acknowledge"
Return values are: 0 = ok, 1 = permission not granted
S7F41R
E, H
A <dsname> "Large Process Program Request"
The sender of this message wishes to receive a large process program using Stream 13 messages.
S7F42
E, H
B <ackc7> "Large Process Program Acknowledge"
Return values are: 0 = ok, 1 = permission not granted, 4 = PPID not found, 6 = other error
Error value 6 is returned if there is a file system error such as the file being locked. 




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>  




S13F1R E L:1 {A <dsname>}
"Send Data Set Send"
Per the process program transfer scenarios in GEM E30, only the equipment sends S13F1R to offer uploading a large, unformatted PP.
S13F2
H
L:2 {A <dsname>} {B <ackc13>}
"Send Data Set Acknowledge"
Per GEM E30, this reply is expected to be sent only by the host.
S13F3R
E, H
L:3 {U4 <handle>} {A <dsname>} {U4 <ckpnt>}
"Open Data Set Request"
S13F4
E, H
L:5 {U4 <handle>} {A <dsname>} {B <ackc13>} {U1 <rtype>} {U4 <reclen>}
"Open Data Set Data"
Ackc13 return code values are: 0 = ok, 2 = unknown data set name, 3 = bad checkpoint value,  9 = handle in use, or 66 = file system error
The equipment can use any data type for HANDLE but the U4 type is used for sending.  The <rtype> value sent is 0 indicating a stream.  The <reclen> value sent as a maximum read size is 65536 which reflects a balance of many considerations.
S13F5R
E, H
L:2 {U4 <handle>} {U4 <readln>}
"Read Data Set Request"
If the maximum read size, <reclen>, is greater than 32768, the host sets <readln> to 16384.  If the maximum read size is less than or equal to 32768, the host uses the maximum read size as the <readln> value.
S13F6
E, H
L:4 {U4 <handle>} {B <ackc13>} {U4 <ckpnt>} {L:n {B <fildat>}}
"Read Data Set Data"
Ackc13 return code values are: 0 = ok, 6 = no open data set for the handle, 7 file system error, 8 = at end of data.
On sending, the host sends <fildat> as a single list item binary vector (L:1 {B <fldat>}).  On receiving, the host is able to handle lists of any number of elements.  Only data types B or A are allowed for <FILDAT>.
S13F7R
E, H
L:1 {U4 <handle>}
"Close Data Set Send"
S13F8
E, H
L:2 {U4 <handle>} {B <ackc13>}
"Close Data Set Acknowledge"
Ackc13 return code values are: 0 = ok, 6 = no open data set for the handle
S13F9R
E, H

"Reset Data Set Send"
The property value use_S13 determines whether this message is send during initialization.
S13F10
E, H

"Reset Data Set Acknowledge"

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.


Version Information

Date of last document revision: $Date: 2022/11/16 17:53:59 $

The SecsPort class was revised in June 2009 to simplify its usage.

All events are now executed by the same thread that constructed the SecsHost instance.  Also, it is possible to use the component with only event callbacks and not any other type of callback delegate.  The SendSecsMsg method returns an RcResult structure and the older string value format is gone.  The RcResult class does support being cast to a string if you want the original string result value.  We recommend you use the parsed RcResult structure instead.