datahub_command

datahub_command — sends commands to the DataHub.

Syntax

datahub_command (command, sync?)
    

Arguments

command

A string containing a DataHub configuration command.

sync

1 sends the command synchronously; 0 sends the command asynchronously.

Returns

The result of the command, as a string.

Description

This function sends configuration commands to the DataHub, in Lisp format. It returns the result of the command as a string. For more information on DataHub commands, please refer to the Using DataHub Commands chapter of the Cascade DataHub or OPC DataHub manual.

Setting the sync parameter to 1 (synchronous) may slow the execution a tiny bit, but it ensures that the DataHub will complete the command before your script continues. Setting the sync parameter to 0 will allow your script to continue whether or not the DataHub command has executed. For most cases, we recommend setting it to 1, just to be on the safe side. This ensures that your script will execute commands in the order expected. The tiny delay for synchronous execution is in micro-milliseconds—insignificant for most applications.

Escaping Characters

Since commands are sent within strings, you probably need to escape certain characters, using the backslash (\). For example, to escape the quote marks delineating the string "my_string", you would enter the string as: \"my_string\".

Windows File Paths

Normally if a command is in a configuration file, you need to escape the backslash in file names, like this:

c:\\tmp\\datahub.log

But, if you are issuing the command from gamma using datahub_command you need to escape each of those two backslashes, like this:

c:\\\\tmp\\\\datahub.log

So the command would be:

datahub_command ("(log_file \"c:\\\\tmp\\\\datahub.log\")")

Since the quotes are optional (though recommended) in DataHub commands you could do this:

datahub_command ("(log_file c:\\\\tmp\\\\datahub.log)")

Fortunately, recent Microsoft operating systems will accept forward slashes in file names, so for those versions you can do this:

datahub_command ("(log_file c:/tmp/datahub.log)")

Example

This example creates a new point in the DataHub, and sets its value to an empty string.

if (undefined_p($default:MyNewPoint))
{
    datahub_command ("(create default:MyNewPoint)", 1);
    datahub_command ("(set default:MyNewPoint\"\")", 1);
}