#!/usr/bin/perl -wT
# run_mode
# Last edited 10/29/2000 6:00pm
#

# example program for the PLC perl module by Dan Baker (dan.baker@bigfoot.com)
# Not affiliated with Allen-Bradley Company, Incorporated.

# You must edit the PLC rc file (usually /plc/PLCproc.rc)
# with information on your PLC's before using this software.
# (See the README file, the example PLCproc.rc file and PLC.pm)

use PLC;

sub usage {
 print "\nUsage:\n  $0 PLCNAME\n\n";
 exit(1);
}

####----------------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#### START OF MAIN PROGRAM
####----------------------XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

use vars qw($opt_D $debug @data_array);

PLC::getopts('D');
$debug = $opt_D;
PLC::debug($debug);

my $PLCname = uc shift; # IP address of PLC (hostname is OK too)

unless ($PLC::quiet) {
 print $PLC::COPYRIGHT;
 print "\nCommand line=$PLC::commandline\n" if $debug;
 print "\nUsing PLC.pm version $PLC::VERSION, revision date $PLC::REVDATE\n\n";
}
usage unless $PLCname;
print "PLCname = $PLCname\n" if $PLC::debug;
PLC::read_rcfile($PLCname);
usage unless defined $PLC::AvailPLCs{$PLCname};

@data_array = PLC::run_mode($PLCname);

if ($PLC::errorcode && !$PLC::quiet) {
 print "\n\n++ ERROR $PLC::errorcode ++\n";
 print "++ $PLC::errormsg[$PLC::errorcode] ++\n\n";
 if ($PLC::errorcode == 6) {
  print "PLC returned error code: ", PLC::ABerrormessage($PLCname),"\n";
 }
 exit(1);
}
else { print "\nDone.\n\n" }

# End of Program
