This example shall implement the following functionality: if a rising edge of a Boolean input is detected, the output shall be set to true. After a defined delay, the output shall be set to false again. If the output is currently set to true and another rising edge at the input is detected, the time delay for setting the output to false shall be reset. The following figure shows the functionality mentioned above.
Creating the command
Within the BMS Studio, start the XLogic Editor using the corresponding icon in the toolbar. Then select the entry "New Command ..." from the menu "File". A new dialog opens that is used to define the name of the command as well as its inputs, outputs, and parameters.
...
The dialog with all correct values is shown in the figure above.
Command flow
As next the command flow has to be defined. The proposed command shall be split into two different parts -- one part that processes the input and one part that process the output. To achieve this, insert two "CMD BLOCK"s and set the comment of the first one to "Process input" and the comment of the second one to "Process output". Figure \ref{fig:delayed_off_flow} shows the final command flow.
"Process input"
As next the "Process input" block shall be implemented. By doing a double click on the corresponding block, the work sheet of the "CMD BLOCK" opens. Within this work sheet, define the command flow that is shown in the following figure.
...
In the following, the above mentioned blocks are explained in more detail.
"Edge detection"
The command flow of the "Edge detection" block is shown in the following figure.
...
It consists of the following blocks:
"Is edge detected?"
This condition verifies whether a positive edge is detected at the input. The condition is shown in here.
"Set edge'"
Here, the variable "edge" is set which indicates that an edge has been detected. The implementation is shown in the following figure.
"Reset edge"
This block is used to reset the variable "edge". The implementation is shown in the following figure.
"Set last value edge"
Here, the current value of the input is stored in the variable "last input" which is used in the next command execution to perform the edge detection. The implementation is shown in the following figure.
"Is edge detected?"
This condition verifies whether an edge has been detected in the previous "CMD BLOCK". Using an "EQUAL" block, the current value of the variable "edge" (retrieved by the "VARIABLE VALUE" block in combination with a "VARIABLE NAME" block) is compared to the constant "TRUE" (provided by a "BOOL" block). The implementation of the "Is edge detected" condition is shown in the following figure.
"Set counter"
This block resets the counter to the value that is specified by the "Delay" parameter. The implementation of the "Set counter" block is shown in the following figure.
"Is output false?"
After having reset the counter, the output shall be set to true if it is not already true. To achieve this, the output has to verified. Figure \ref{fig:delayed_off_is_output_false} shows the implementation of the required condition.
"Write true to output"
The following figure shows how the output is set to true. Note that a "WRITE OUTPUT ITEM" block also forwards the value to the bus if a physical data point is behind the server item.
"Process output"
After having finished the "Process input" block, the "Process output" block has to be implemented. By doing a double click on the corresponding block, the work sheet of the "CMD BLOCK" opens. Within this work sheet, define the command flow that is shown in the following figure.
...
In the following, the above mentioned blocks are explained in more detail.
"Is counter 0?'
Using a "LESS OR EQUAL" block, the current counter value which is stored within the variable "counter" is compared with zero. To get the value of the variable, a "VARIABLE VALUE" block is used. Since the variable may be uninitialized after server startup, zero is specified as default value. The implementation of this condition is shown in the following figure.
"Is output true?'
If the current counter value is zero, the delay interval is elapsed and the output shall be reset to false again. However, to avoid that multiple "false" telegrams are sent to the bus, the output shall only be set to false if the output is currently true. The implementation of the required test is shown in the following figure.
"Write false to output'
The following figure shows how the output is set to false. To forward the value also to the bus if the output is a physical data point, a "WRITE OUTPUT ITEM" is used. If the value shall only be set internally and not forwarded to the bus, a "SET OUTPUT VALUE" block has to be used instead.
"Decrement counter'
If the current counter value is not zero, the delay interval has not been elapsed and thus the counter value has to be decremented by one. The following figure shows the implementation of this functionality. Decrementing the value is done using a "SUB" block. The incoming "Input 1" connector is connected to outgoing "VALUE" connector of the "VARIABLE VALUE" block that provides the current counter value. The "Input 2" connector is connected to the "NUMBER" block that provides the constant value 1. The result of the subtraction is stored in the "counter" variable again using a "SET VARIABLE" block.
Saving the command and using the command within the NETx BMS Server
To provide the command to the NETx BMS Server, it has to be compiled. This can be done by clicking the "Save" icon within the toolbar which saves and compiles the current command. In addition, it is possible to change several options of a command. To open the "Options" dialog, the entry "Options ..." within the menu "File" has to be selected. Within this dialog, basic information about the command can be specified. The flag "Add to Catalog" defines whether the command shall be visible within the catalog of the XLogic Editor. If activated, the command can be reused in other commands. If the option "Auto-Compile" is set, the command is automatically compiled whenever the project is saved.
...