bacnet.pl - Scriptable BACnet communications
This is a tool for scriptable BACnet communication. Users can write their own scripts using standard Perl syntax and API defined in this tool to perform desired execution sequences. For details on this tool's API, see Documentation.html. For other Perl documentation, see http://perldoc.perl.org
Usage: bacnet.pl [program_options] [-- script_args]
This program executes a script in perl syntax to perform BACnet/IP operations.
Possible program options: --script=s The script to execute. --log=s The file to log all output. --help This help message.
Possible environment variables are: BACNET_IFACE - set this value to dotted IP address of the interface (see ipconfig) for which you want to bind. Default is the interface which Windows considers to be the default (how???). Hence, if there is only a single network interface on Windows, the applications will choose it, and this setting will not be needed. BACNET_IP_PORT - UDP/IP port number (0..65534) used for BACnet/IP communications. Default is 47808 (0xBAC0). BACNET_APDU_TIMEOUT - set this value in milliseconds to change the APDU timeout. APDU Timeout is how much time a client waits for a response from a BACnet device. BACNET_BBMD_PORT - UDP/IP port number (0..65534) used for Foreign Device Registration. Defaults to 47808 (0xBAC0). BACNET_BBMD_TIMETOLIVE - number of seconds used in Foreign Device Registration (0..65535). Defaults to 60000 seconds. BACNET_BBMD_ADDRESS - dotted IPv4 address of the BBMD or Foreign Device Registrar.
In addition to having all standard Perl flow control, functions, and modules, the this tool provides an API for performing BACnet communication functions.
This function implements the ReadProperty service. There are no built in retry mechanisms. NOTE: all enumerations are defined in bacenum.h
The following example will read AV0.PresentValue from device 1234
my ($res, $failed) = ReadProperty(1234, 'OBJECT_ANALOG_VALUE', 0, 'PROP_PRESENT_VALUE');
This function implements the ReadPropertyMultiple service. There are no built in retry mechanisms. NOTE: all enumerations are defined in bacenum.h
The following example will read AV0.PresentValue and AV1.PresentValue from device 1234
my @RPM_request = (); my @RPM_answer = (); my $failed; push @RPM_request, ['OBJECT_ANALOG_VALUE', 0, 'PROP_PRESENT_VALUE', -1]; push @RPM_request, ['OBJECT_ANALOG_VALUE', 1, 'PROP_PRESENT_VALUE', -1]; (undef, $failed) = ReadPropertyMultiple(1234, \@RPM_answer, @RPM_request);
This function implements the WriteProperty service. There are no built in retry mechanisms. NOTE: all enumerations are defined in bacenum.h
The following example will write 1.0 to AV0.PresentValue in device 1234
my ($res, $failed) = WriteProperty(1234, 'OBJECT_ANALOG_VALUE', 0, 'PROP_PRESENT_VALUE', 'BACNET_APPLICATION_TAG_REAL', 1.0);
This function implements the TimeSync and UTCTimeSync services
$isFailure = TimeSync($deviceInstance, $1, $2, $3, $4, $5, $6) unless $isFailure;
This function prints out to the desired method of logging (STDOUT or file). NewLine characters are not required when making calls to this function. If any NewLine characters are specified, they will be stripped out. To print an empty line, pass in a space as the message. NOTE: This function will honor previous requests to silence the log (see SilcenseLog for details)
The following example will print out "hello world"
Log("Hello World");
This function requests that all future log messages be either suppressed or enabled.
The previous value of whether or not the log was silenced before caling this function.
The following example will print out "hello", but not "world"
Log("Hello"); SilenceLog(1); Log("World");
This function will try to execute the requested command up to specified number of times, awaiting the requested answer, with a specified pause between retries. NOTE: the only functions which can be executed by this function are ones which return two parameres in the form of ($response, $isFailure)
The following example will execute the ReadProperty function to read a property from an object (see ReadProperty for details on those arguments) with up to $maxRetries retries (with $retryDelay delay between retries) or unitl the desired answer of 42 is received.
my ($resp, $isFailure) = Retry( \&ReadProperty, [$deviceInstance, 'OBJECT_ANALOG_VALUE', 0, 'PROP_PRESENT_VALUE'], 42, $maxRetries, $retryDelay ); if ($isFailure) { die "Value was not 42. Last response was '$resp'"; }
The following example will try to execute a WriteProperty (see that function for details on its arguments) until the write succeeds.
my ($resp, $isFailure) = Retry( \&WriteProperty, [$deviceInstance, 'OBJECT_ANALOG_VALUE', 0, 'PROP_PRESENT_VALUE', 'BACNET_APPLICATION_TAG_REAL', 42.0], "Acknowledged", $maxRetries, $retryDelay ); if ($isFailure) { die "Could not write 42. Last response was '$resp'"; }