Low cost solutions to Data Acquisition and Control, with a snap.
Data Sheets and Application Notes Product Warranty Return Policy Privacy Notice How to Order Company Profile

How to use variables

During run-time, ModCom performs various tasks such as transmitting commands, manipulating Screen Objects, sensing operator input, watching for specific conditions to act upon, etc. Each task is defined by the user ahead of time by setting up the run-time properties of various objects. The user-entered fields that define the object's properties can contain a simple static value such as a number, text string, or object ID label, but it can also contain a variable - allowing dynamic control of the task being performed. This is accomplished by substituting the user-entered value with the name of a Screen Object which should determine that value at run-time. And if the value of the Screen Object changes, so does the value being used to define the properties of the object performing the task.

Defining Variables:

To define a variable or collection of variables, create a Screen Object for each one, such as a Data Window, Input Window, Text Window, Level Gauge, Dial Gauge, Meter Gauge, Signal Lamp, Event Counter, or Event Timer. These Screen Objects can be a part of the main viewing page that contains all the other run-time objects, but they can also just as easily be grouped together and placed on a separate page so that they are obscure from the user during general operation. Note, there are a number of global variables that are reserved by ModCom to hold significant data during run-time and are listed below. These global variables can be used in any user-entered field which accepts variables.

{recdata} = the last data packet which was received by the COM port. (see note below)

{rawdata} = same as {recdata} but the header character has been striped off.

{systemtime} = current time retrieved from the computer system.

{systemhour} = current hour retrieved from the system time.

{systemmin} = current minute retrieved from the system time.

{systemsec} = current second retrieved from the system time.

{systemdate} = current date retrieved from the computer system.

{systemyear} = current year retrieved from the system date.

{systemmonth} = current month retrieved from the system date.

{systemday} = current day of month retrieved from the system date.

{systemdow} = current day of week retrieved from the system date.

Note, any data which is received in direct response to a command transmitted by another object within ModCom will not be stored in {recdata} or {rawdata} unless the transmitting object has the word "Conditionals" typed into its box called "Send the response to this Screen Object".

Using Variables:

To use a variable in a user-entered field of an object's properties setup box, simply type in the object ID label of the Screen Object that you wish to have represent the value and encapsulate it in curly braces like this: {DataWindow1} Doing so will cause the value of the user-entered field to be equal to the number which is displayed in the Data Window in real time. It is perfectly legal to concatenate variables with fixed characters such as putting a variable in the middle of a text message being sent to a Text Window, or using a variable to represent the suffix of an object's name when it's listed as a target of a function. For instance, if the "Turn on this Lamp" function uses Lamp{Counter1} as the target, incrementing the counter will cause a different lamp to turn on next time the function is executed. When transmitting a command string, using the syntax AVA{DataWindow1} allows the header, command title, and channel number to remain fixed, while the numerical data changes on the fly as the Data Window is updated. Concatenating multiple variables with multiple fixed characters can make things even more interesting. Using the string {hour}:{min}:{sec} allows each section of a time value to be calculated individually, then conjoined into a format which can be sent to an Event Timer. Note however, that each variable will have to equal a 2-digit number in order to produce a valid time structure.

Variable Examples:

Controlling an Analog Output with an Analog Input: Transmitting the command string AVA{DataWindow1} to an Analog Output Module will set the voltage on channel A to the value shown in a Data Window, which could be for instance, in the process of polling an Analog Input Module. In this case, the Analog Input channel must be set to MODE 1 and the multiplier factor of the Data Window must be set to 0.1 to convert the readings from the Analog Input Module to the same format as the Analog Output Module. Placing a 2nd Data Window on the screen and using the string mentioned above for its polling command, will force the Analog Output Module to track the Analog Input Module automatically.

Creating a Clock or Date Indicator: The global variable {systemtime} contains the current time of the system clock and can not only be used to test for specific times of day, but can be used to construct a working clock which can be viewed during run-time. To do this, simply place a Text Window on the screen and use a Conditional statement to continually update it with the current time. Using the expression {TextWindow1} <> {systemtime}, will evaluate to TRUE at anytime the system clock changes. Then use the "Show Message" function to send the new {systemtime} to the Text Window. A similar approach can be used to create a date indicator using the {systemdate} variable like this. If {TextWindow1} <> {systemdate} then send {systemdate} to the text window.

Conditional statements: The logical expression used in a Conditional statement will almost always contain variables of some sort or another. Whether testing the value of a Screen Object, or testing the value of one of the global variables. The variable {recdata} can be used to test for a specific data packet received from a data module. This variable can be compared directly to a user-entered text string, or to a Screen Object such as a Text Window which could contain the response from a previous command transmission or simply a text string sent to it by some other function. Using the expression {recdata} = A{rawdata}, will evaluate to TRUE at anytime data is received containing a header character equal to "A". This would allow the Conditional to be triggered by any data packet coming form a specific data module regardless of what comes after the header character.

Function definitions: Many of the functions operate on a particular object which is specified in the box to the right of the function selection menu. If this field contains a variable, it is possible to control which object is the target in a dynamic fashion. Suppose you wish to execute a Script in response to an event, but also want to change the Script selection for the next time the event occurs. For instance, the first time run Script1, the next time run Script2, the next time run Script3, etc. To do this, place an Event Counter on the screen and use it as a variable to represent the suffix of the Script's name which is listed in the function triggered by the event. In other words, instead of having the event start Script1, have it start Script{Counter1}. Then write a series of Scripts called Script1, Script2, Script3, etc., and have each one increment the counter at the end of its operation. That way, each time the event occurs and causes its function to execute, the function's target Script will be the next one down on the list, and so on. An alternate approach instead of incrementing a counter, would be to use a Text Window as the variable and have each Script write a new name to that window before terminating.

Changing the Log File Name: A variable can even be entered in place of a log file name making it possible to change the file name during run-time. For instance, suppose you wish to log data at regular intervals to a main file during normal conditions, but if a certain event occurs, log the data to a special file to keep it separate from the rest. Simply create a Text Window to be the log file variable, set its default message to "DataLog.txt", and enter the Text Window's ID label in the log file title box. Then when the run-loop is executing and data is being logged to file, the file name will be retrieved from the default message in the Text Window. If an event occurs that merits a change in the log file name, have the event trigger a Conditional which will change the message in the Text Window and thus start logging the data to a new file.

 

 

ModCom HMI/SCADA Software Certificate
 

Click for the BBB Business Review of this Computer Software Publishers & Developers in Fort Walton Beach FL