public abstract class SecsConn extends Object implements DmhReceiveItf
In general we can trap and ignore Exceptions when communicating with the SECS server because we have installed a callback for receiving notification of Server errors using onServerError().
Modifier and Type | Field and Description |
---|---|
static String |
TIMEOUT
"TIMEOUT" string constant which is used as a failure reply
|
static int |
TRACE_DEFAULT_BITS
default trace window initialization trace bits, value 0x440E
|
static int |
TRACE_READ_WRITE_IO
trace bit for low level read/write IO activity, 1
|
static int |
TRACE_RECV_HDR_HEX
trace bit for received header hex display, 0x0100
|
static int |
TRACE_RECV_HDR_INTERP
trace bit for received header interpretation, 0x0200
|
static int |
TRACE_RECV_MSG_HEXDUMP
trace bit for received message data hex display, 0x0800
|
static int |
TRACE_RECV_MSG_TSN
trace bit for received message as TSN text, 0x0004
|
static int |
TRACE_RECV_SF_DESC
trace bit for received message type description, 0x0400
|
static int |
TRACE_SEND_HDR_HEX
trace bit for sent header hex display, 0x1000
|
static int |
TRACE_SEND_HDR_INTERP
trace bit for sent header interpretation, 0x2000
|
static int |
TRACE_SEND_MSG_HEXDUMP
trace bit for sent message data hex display, 0x8000
|
static int |
TRACE_SEND_MSG_TSN
trace bit for sent message as TSN text, 0x0008
|
static int |
TRACE_SEND_SF_DESC
trace bit for sent message type description, 0x4000
|
static int |
TRACE_STATE_LOGIC
trace bit for state changes including connection attempts, 2
|
Constructor and Description |
---|
SecsConn(String name,
String DmhGroup,
boolean isEquip)
Initialize the SECS connection including the start of a child
SECS Server process.
|
Modifier and Type | Method and Description |
---|---|
int |
binToInt(String binValue)
convert a SECS binary value formatted as hex 0xnn or base 10 to int
|
abstract void |
commDisable()
disable SECS communication
|
abstract RcResult |
commEnable()
enable SECS communication
|
RcResult |
connectTypeHsmsActive(String hostOrIpAddress,
int port)
set the connection type to HSMS active
|
RcResult |
connectTypeHsmsPassive(int port)
set the connection type to HSMS passive
|
RcResult |
connectTypeSerial(String comDevice,
int baudrate)
host only - set the connection type to a serial port
|
abstract RcResult |
connectTypeSet()
Apply current connection type data set as properties.
|
RcResult |
connectTypeTerminalServer(String host_or_ip,
int port)
host only, set the connection type to a Terminal Server/IP connection
|
static void |
debugDmhStatus(boolean show)
show or hide the SECS Server DMH message system status window
|
static void |
debugInspect()
exec the Datahub SDK inspect debugger to debug the SECS Tcl server
|
static void |
debugTableWindow(boolean show)
show or hide the SECS server SQL table GUI
|
static void |
debugTclConsole(boolean show)
show or hide the SECS server Tcl command console
|
void |
debugTraceWindow(boolean show)
Show or hide the SECS server SECS trace window for this connection.
|
void |
dmhReceive(DmhClientItf dmh,
String Data,
String Dest,
String ReplyMailbox)
This is a callback for this code to receive messages from the SECS server.
|
int |
getBAUD()
property value BAUD, default 9600
|
static String |
getBinDir()
directory where DMH executables are - a read-only value
|
String |
getCommState()
CommState value
Possible literal text values are
DISABLED, ENABLED {NOT COMMUNICATING}, COMMUNICATING |
int |
getConnectionType()
property value ConnectionType
See getConnectionType for details. |
String |
getControlState()
property value ControlState
A read-only value of the actual GEM Control State, which reflects your ControlIntentOnline value, your ControlModeRemote value, and host dynamics. |
int |
getDEVID()
property value DEVID, the SECS device ID, default 0
|
static DmhClientItf |
getDmh()
DMH connection to the SECS Server - read-only
|
static String |
getDmhGroupName()
DMH Group name - read-only
|
String |
getHsmsHost()
property value HSMS Connection Hostname or IP address.
|
boolean |
getHsmsPassive()
property value HsmsPassive - whether to act as a passive server instead of an active client
|
int |
getHsmsPort()
property value HsmsPort - the HSMS socket port, default value is 5555
|
static String |
getJavaServerDir()
directory where SecsServer[.exe] or SecsServer.tcl is found
treat it as a read-only property
|
String |
getName()
A unique name for the SECS connection, used as an identifier for saved data,
Set during construction.
|
String |
getProcessProgramDir()
The Process Program Directory - you can set a relative path such as "./pp".
|
int |
getRTY()
property value SECS-I retry maximum
|
String |
getSerialPort()
property value SECS-I SerialPort, default is COM1 on Windows
|
String |
getState()
The low-level connection state, OFFLINE, LISTENING, COMMUNICATING and more,
The value is null until the interface instance has been constructed
in the SECS server process.
|
int |
getT1()
property value, SECS-I T1 timer
|
int |
getT2()
property value, SECS-I Protocol timeout timer
|
int |
getT3()
property value, SECS Reply timeout timer
|
int |
getT4()
property value, SECS-I interblock timeout timer
|
int |
getT5()
property value, HSMS re-connection attempt timer
|
int |
getT6()
property value, HSMS control transaction timeout.
|
int |
getT7()
property value, HSMS not selected timeout.
|
int |
getT8() |
int |
getTraceBits()
get the TraceBits which control tracing of SECS communication
|
int |
getTraceLogMaxWidth()
the maximum width of a line in characters when saving SECS communication
trace data to log files, 0 = no limit, or >= 1000
|
String |
getTraceSaveDir()
the file system directory for trace data save files
|
int |
getTraceSaveMaxDayFiles() |
String |
getTraceSaveZipCmd()
The compression command which is executed in the saving directory
with the additional argument of the day file name which has just been
closed at midnight.
|
int |
getTracewinMaxWidth() |
boolean |
isEquip()
host or equipment role
|
boolean |
isHsms()
whether the connection type is HSMS or a non-standard variant
|
boolean |
isHsmsPassive() |
boolean |
isPPbodyFileMode()
Return the configured state of whether S7F3 and S7F6 process program
transfers are direct with files bypassing memory.
|
boolean |
isTraceDataCompressed() |
boolean |
isTraceDataSaved() |
static boolean |
isWindows()
are we running on Windows? read-only
|
boolean |
linktest()
Synchronously test a COMMUNICATING HSMS connection to verify that
the link is responsive.
|
void |
linktestAsync()
Cause a linktest HSMS control message to be sent to test if a
healthy connection still exists.
|
static String |
listElement(String s,
int index)
Parse text structured as a list for the nth element.
|
static String |
listElement(String s,
int i,
int j)
Parse a nested list - the ith element is parsed as a list for the jth item.
|
static String |
listElement(String s,
int i,
int j,
int k)
Parse a doubly nested list - the ith element is parsed as a list for the jth item,
then the jth item is parsed for the kth element.
|
static String |
listJoin(String[] list)
A convenience method to convert a string array to a list.
|
static String[] |
listSplit(String s)
A listSplit method that returns an empty list instead of an exception
if the input text is not a valid list.
|
void |
messageTypeAdd(int stream,
int function,
SecsMessageReceiveItf callback)
Specify a SECS message type to be received and handled by your application.
|
void |
messageTypeRemove(int stream,
int function)
Cancel receiving of a message type, either of a built-in message type
handled by the SECS server, or one that is being handled in the Java application.
|
SecsTraceItf |
onSecsTrace(SecsTraceItf handler)
register a callback for
SECS message traffic diagnostic tracing
|
static ServerErrorItf |
onServerError(ServerErrorItf handler)
SECS Server and DMH connection error delivery.
|
ValueChangeItf |
onStateChange(ValueChangeItf handler)
register a callback for the state change event
|
void |
sendAbort(int stream,
int primaryFunction)
Send a function 0 abort message in lieu of a proper reply.
|
void |
sendReply(int stream,
int function,
int transactionID)
send a SECS reply message - header only, no data.
|
void |
sendReply(int stream,
int function,
int transactionID,
String tsnData)
Send a SECS reply message with data.
|
void |
sendS9(int function,
String header)
Send a Stream 9 error message:
F1 bad device ID, F3 bad stream, F5 bad function, F7 bad data, F9 T3 reply timeout, F11 too much data, F13 conversation timeout |
RcResult |
sendSecsMsg(int stream,
int function,
boolean wantReply,
String tsnData,
boolean waitForReply)
Send a primary SECS message, optionally indicating a reply is wanted, and
optionally waiting for the reply message.
|
static int |
serverLicenseCheck()
Return a status code for the license when using SecsServer[.exe].
|
static RcResult |
serverReply(String tclCommand)
Send a Tcl command to the Server and wait for the reply.
|
static void |
serverSqlCmd(String cmd)
Send an SQL command to the SECS Server for evaluation without
waiting for a reply.
|
static String |
serverSqlReply(String cmd)
Execute an SQL command in the Server process and wait for the reply
|
static void |
serverStart(String GroupName)
startup the SECS Server if not already started
|
static void |
serverStop()
disconnect from and possibly terminate the SECS Server
|
static void |
serverTclCmd(String cmd)
Send a Tcl command to the Server process without waiting for the reply.
|
static String |
serverTclReply(String cmd)
Send a Tcl command to the Server and wait for the reply.
|
void |
setBAUD(int baudrate)
property value BAUD, default 9600
must issue connect type call to use a new value |
void |
setConnectionType(int v)
We recommend you use connectTypeHsmsPassive() or connectTypeHsmsActive() instead of
this method.
|
void |
setDEVID(int DEVID)
property value DEVID, the SECS device ID, default 0
|
void |
setHsmsHost(String hostnameOrIpAddr)
property value HSMS Connection Hostname or IP address
|
void |
setHsmsPassive(boolean passive)
property value HsmsPassive - whether to act as a passive server instead of an active client
|
void |
setHsmsPort(int p)
property value HsmsPort - the HSMS socket port, default value is 5555
|
void |
setPPbodyFileMode(boolean isFileMode)
Specify if S7F3 and S7F6 process program transfers are direct with
files bypassing possibly large memory allocations.
|
void |
setProcessProgramDir(String path)
The Process Program Directory
Also known as the RecipeDirectory - a relative pathname value is relative to the SECS Server
working directory not the Java program working directory.
|
void |
setRTY(int v)
SECS-I retry maximum, default 3, range 1..31
|
void |
setSerialPort(String SerialPort)
SECS-I serial port, default is COM1 on Windows
|
void |
setT1(int v)
SECS-I inter-character timeout, default 500, range 100..10000
|
void |
setT2(int v)
T2, SECS-I Protocol timeout, default 10000, range 200..25000
|
void |
setT3(int v)
T3, SECS reply timeout, default 45000, range 1000..120000
|
void |
setT4(int v)
T4, SECS-I interblock timeout, default 45000, range 1000..120000
|
void |
setT5(int v)
T5, HSMS delay between re-connection attempts.
|
void |
setT6(int v)
T6, HSMS control transaction timeout.
|
void |
setT7(int v)
T7, HSMS not selected timeout.
|
void |
setT8(int v)
T8 is not used
|
void |
setTraceBits(int TRACE)
used as a bitfield to control tracing of SECS communication
|
void |
setTraceLogMaxWidth(int v)
The maximum width of a line in characters when saving trace data to log files.
|
RcResult |
setTraceSaving(boolean save,
boolean compress,
int maxDayFiles,
String saveDir,
String zipCmd)
Control over saving of trace data as day files.
|
void |
setTracewinMaxWidth(int v)
the maximum width in characters for the display of trace data
|
void |
tclCmd(String tclCommand)
Send Tcl code to the SECS server command mailbox for evaluation
without waiting for a reply.
|
RcResult |
tclReply(String tclCommand)
Send Tcl code to the SECS server command mailbox and wait for the
evaluation result.
|
void |
traceWin(boolean show)
Show or hide the native Java trace window with logging configuration allowed.
|
void |
traceWin(boolean show,
boolean allowLogging)
Show or hide the native Java trace window which displays the SECS
connection status and activity.
|
void |
traceWinDeleted()
the Tracewin notifies us when disposed (internal call)
|
static boolean |
tsnTypeIsOk(String valueTsn)
A quick but non-rigorous validation of the TSN type code for a variable.
|
public static final String TIMEOUT
public static int TRACE_DEFAULT_BITS
public static int TRACE_READ_WRITE_IO
public static int TRACE_RECV_HDR_HEX
public static int TRACE_RECV_HDR_INTERP
public static int TRACE_RECV_MSG_HEXDUMP
public static int TRACE_RECV_MSG_TSN
public static int TRACE_RECV_SF_DESC
public static int TRACE_SEND_HDR_HEX
public static int TRACE_SEND_HDR_INTERP
public static int TRACE_SEND_MSG_HEXDUMP
public static int TRACE_SEND_MSG_TSN
public static int TRACE_SEND_SF_DESC
public static int TRACE_STATE_LOGIC
public SecsConn(String name, String DmhGroup, boolean isEquip) throws Exception
name
- the connection nameDmhGroup
- DMH message system groupnameisEquip
- equipment or host usageException
- if the connection name is improper or
initialization of the SECS server process fails.public int binToInt(String binValue)
binValue
- string representation of a hexadecimal or decimal integerpublic abstract void commDisable()
public abstract RcResult commEnable()
public RcResult connectTypeHsmsActive(String hostOrIpAddress, int port)
hostOrIpAddress
- hostname or IP addressport
- TCP/IP port valuepublic RcResult connectTypeHsmsPassive(int port)
port
- TCP/IP portpublic RcResult connectTypeSerial(String comDevice, int baudrate)
comDevice
- baudrate
- public abstract RcResult connectTypeSet()
public RcResult connectTypeTerminalServer(String host_or_ip, int port)
host_or_ip
- the hostname or IP address of the terminal serverport
- TCP/IP portpublic static void debugDmhStatus(boolean show)
show
- true to showpublic static void debugInspect()
public static void debugTableWindow(boolean show)
show
- public static void debugTclConsole(boolean show)
show
- public void debugTraceWindow(boolean show)
show
- public void dmhReceive(DmhClientItf dmh, String Data, String Dest, String ReplyMailbox) throws Exception
dmhReceive
in interface DmhReceiveItf
Data
- message dataDest
- destination mailboxReplyMailbox
- reply mailboxdmh
- the DMH connection instanceException
public int getBAUD()
public static String getBinDir()
public String getCommState()
public int getConnectionType()
public String getControlState()
public int getDEVID()
public static DmhClientItf getDmh()
public static String getDmhGroupName()
public String getHsmsHost()
For an active HSMS connection, the TCP/IP hostname or IP address of the HSMS passive server.
defaults to "localhost".
public boolean getHsmsPassive()
public int getHsmsPort()
public static String getJavaServerDir()
public String getName()
public String getProcessProgramDir()
public int getRTY()
public String getSerialPort()
public String getState()
public int getT1()
public int getT2()
public int getT3()
public int getT4()
public int getT5()
public int getT6()
public int getT7()
public int getT8()
public int getTraceBits()
public int getTraceLogMaxWidth()
public String getTraceSaveDir()
public int getTraceSaveMaxDayFiles()
public String getTraceSaveZipCmd()
public int getTracewinMaxWidth()
public boolean isEquip()
public boolean isHsms()
public boolean isHsmsPassive()
public boolean isPPbodyFileMode()
public boolean isTraceDataCompressed()
public boolean isTraceDataSaved()
public static boolean isWindows()
public boolean linktest()
public void linktestAsync()
public static String listElement(String s, int index)
s
- text structured as a white space separated listindex
- 0 based subscriptpublic static String listElement(String s, int i, int j)
s
- text structured as a white space separated listi
- index into listj
- index into ith element of listpublic static String listElement(String s, int i, int j, int k)
s
- text structured as a white space separated listi
- index into listj
- index into ith element of listk
- index into jth elementpublic static String listJoin(String[] list)
list
- public static String[] listSplit(String s)
s
- text structured as a white space separated listpublic void messageTypeAdd(int stream, int function, SecsMessageReceiveItf callback) throws Exception
You can provide for new SECS message types, or you can replace the built-in handling of particular messages. However, you should not replace the basic Stream 1 message that manage communication and the control state model unless you are prepared to rewrite most of the Hume application.
Most message types can only be exchanged when an online control state has been established, so be mindful of the communication and control state before sending or expecting to receive messages.
Use the sendReply method to send reply messages.
An equipment instance also uses sendS9 and sendAbort methods to indicate errors or to abort message conversations.
stream
- message type Stream identifierfunction
- message type Function identifiercallback
- an object that implements the SECS message receiving interfaceException
public void messageTypeRemove(int stream, int function)
You should not cancel receiving of the basic messages which manage the communication and control states.
stream
- function
- public SecsTraceItf onSecsTrace(SecsTraceItf handler)
handler
- public static ServerErrorItf onServerError(ServerErrorItf handler)
Register a callback for a trapped error in SECS server.
The SecsConn 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.
Another source of error messages are trapped Java exceptions that occur during DMH whenMsg receiving or the DMH connection to the SECS server being lost.
Programming error events may happen during development but are not expected once your application is debugged.
handler
- public ValueChangeItf onStateChange(ValueChangeItf handler)
handler
- public void sendAbort(int stream, int primaryFunction) throws Exception
stream
- primaryFunction
- Exception
public void sendReply(int stream, int function, int transactionID)
stream
- the received stream message type valuefunction
- the received function value plus onetransactionID
- passed to you by the receiving callbackpublic void sendReply(int stream, int function, int transactionID, String tsnData)
stream
- the received stream message type valuefunction
- the received function value plus onetransactionID
- passed to you by the receiving callbacktsnData
- TSN formatted message datapublic void sendS9(int function, String header)
function
- value, usually 7 for improper dataheader
- the header value from the receiving callbackpublic RcResult sendSecsMsg(int stream, int function, boolean wantReply, String tsnData, boolean waitForReply)
stream
- function
- wantReply
- whether to request a reply messagetsnData
- can be null or blank for header only messageswaitForReply
- whether to wait for a reply or TIMEOUTpublic static int serverLicenseCheck()
public static RcResult serverReply(String tclCommand)
tclCommand
- Tcl code for remote executionpublic static void serverSqlCmd(String cmd)
cmd
- SQL statementpublic static String serverSqlReply(String cmd)
cmd
- SQL command stringpublic static void serverStart(String GroupName) throws Exception
GroupName
- the DMH group nameException
public static void serverStop()
public static void serverTclCmd(String cmd)
cmd
- Tcl language command stringpublic static String serverTclReply(String cmd)
cmd
- public void setBAUD(int baudrate)
baudrate
- public void setConnectionType(int v) throws Exception
ConnectionType, default is 1995,
0 = serial SECS-I
1 == terminal server SECS-I
1993 == non-standard draft HSMS
1995 == standard HSMS
v
- Exception
public void setDEVID(int DEVID) throws Exception
DEVID
- Exception
public void setHsmsHost(String hostnameOrIpAddr)
hostnameOrIpAddr
- public void setHsmsPassive(boolean passive)
default is true for equipment
passive
- public void setHsmsPort(int p)
p
- port valuepublic void setPPbodyFileMode(boolean isFileMode)
isFileMode
- public void setProcessProgramDir(String path)
path
- pathname valuepublic void setRTY(int v) throws Exception
v
- Exception
public void setSerialPort(String SerialPort)
SerialPort
- public void setT1(int v) throws Exception
v
- millisecondsException
public void setT2(int v) throws Exception
v
- millisecondsException
public void setT3(int v) throws Exception
v
- millisecondsException
public void setT4(int v) throws Exception
v
- millisecondsException
public void setT5(int v) throws Exception
v
- millisecondsException
public void setT6(int v) throws Exception
v
- millisecondsException
public void setT7(int v) throws Exception
v
- Exception
public void setT8(int v)
v
- public void setTraceBits(int TRACE)
TRACE
- public void setTraceLogMaxWidth(int v) throws Exception
v
- Exception
public RcResult setTraceSaving(boolean save, boolean compress, int maxDayFiles, String saveDir, String zipCmd)
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 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. The RcResult return value of setTraceSaving() is used as follows. If the rc value is less than 0 the 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.
save
- whether to persist trace datacompress
- whether to compress saved day filesmaxDayFiles
- maximum number of day filessaveDir
- saving directoryzipCmd
- compression commandpublic void setTracewinMaxWidth(int v) throws Exception
v
- Exception
public void tclCmd(String tclCommand)
tclCommand
- public RcResult tclReply(String tclCommand)
tclCommand
- public void traceWin(boolean show)
show
- public void traceWin(boolean show, boolean allowLogging)
show
- allowLogging
- public void traceWinDeleted()
public static boolean tsnTypeIsOk(String valueTsn)
valueTsn
-