#Code originally found online:
#Modified by Ibedonc for TomW
#!/usr/bin/perl -w

# Requires Device-Serial perl module.
use Device::SerialPort 0.05;
use strict;
my $mate = "/dev/ttyUSB0";
my $pass;
my $return;
# Constructor & Basic Values
#print localtime(); # amount of seconds since 1970, e.g. 573711711024370
my $ob = Device::SerialPort->new ($mate) || die "Can’t open $mate:$!";

$ob->baudrate (19200) || die "fail setting baudrate";
$ob->parity ("none") || die "fail setting parity";
$ob->databits (8) || die "fail setting databits";
$ob->stopbits (1) || die "fail setting stopbits";
$ob->handshake ("none") || die "fail setting handshake";
$ob->dtr_active (1) || die "fail setting dtr_active";

$ob->rts_active (0) || die "fail setting rts_active";
#$ob->write_settings || die "no settings";
#commented out the write_strings as it seemed like it was turning off the inverter
#sleep 1;

#$pass = $ob->write("a") or die ("Could not write to mate: $!");

sleep 1;

if (($return = $ob->input) ne "")
{
#   $ob->write ($return);
 $return =~ s/[^0-9,]//g;
      print "$return\n";
      }
      else
      {
         print "ERROR!! Did not receive anything from Mate.\n";
         }
         
         undef $ob