#!/usr/bin/perl -wT
# testall

#	gets diagnostic status data
#	from all PLC's listed in /plc/PLCproc.rc

#	If you use a high debug level (testall -DDDDDD for example),
#	you will get more debugging information than you ever wanted.

# Last edited 10/24/2000 10:00am
#

# 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;


###$PLC::scanfor_delay = 0.2;
###$PLC::writeserial_delay = 0.05;

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

PLC::getopts('qD');
$debug = $opt_D;
PLC::debug($debug);
$PLC::quiet = $opt_q unless $PLC::debug;

sub doit {
 my $PLCname = $_[0];
 @data_array = PLC::PLCcommand(@_);
 if ($PLC::errorcode && !$PLC::quiet) {
  print "\n\n++ ERROR $PLC::errorcode ++\n";
  print "++ $PLC::errormsg[$PLC::errorcode] ++\n\n";
  exit(1);
 }
 if (defined($data_array[0])) {
  unless ($PLC::quiet) {
   print "\nPLC name = $PLCname\n";
   PLC::printreturndata($PLC::PLCproc{$PLCname});
   print "\n\n";
  }
 }
 else { # PLCcommand returned undef
  print STDERR "\n\n++ Some kind of error ++\n\n" unless $PLC::quiet;
  exit(2);
 }
}

PLC::read_rcfile(); # generate hash of PLCnames

for (keys %PLC::AvailPLCs) {
 doit($_,6,3); # get diagnostic status for each PLC in /plc/PLCproc.rc
}

# End of Program
