stir/V1 (old)/stirctl
Michael Wesemann 6eb004d420 -
2019-10-04 17:11:38 +02:00

71 lines
2.2 KiB
Perl
Executable File

#!/usr/bin/perl
###################################################################################### stir controll (mwx'2019)
use Device::SerialPort;
use Time::HiRes qw( usleep );
$dev='/dev/ttyACM0';
my $port = Device::SerialPort->new($dev); ################################################### setup serial port
$port->baudrate(9600);
$port->databits(8);
$port->parity("none");
$port->stopbits(1);
$port->lookfor();
$cmd=join(':',@ARGV);$cmd='info' if ($cmd=~/^\s*$/);
@r=split(':',&scmd($cmd));
print " LEFT RIGHT\n";
printf("Stirrer On: %6d %6d\n", $r[0],$r[16]);
printf("Speed: %6d %6d\n", $r[1],$r[17]);
printf("Boost Speed: %6d %6d\n", $r[2],$r[18]);
printf("RPM: %6d %6d\n", $r[3],$r[19]);
printf("Average RPM: %6d %6d\n", $r[4],$r[20]);
printf("Regulation: %6d %6d\n", $r[5],$r[21]);
printf("Boost On: %6d %6d\n", $r[6],$r[22]);
printf("Boost Time: %6d %6d\n", $r[7],$r[23]);
printf("Catch On: %6d %6d\n", $r[8],$r[24]);
printf("Catch Time: %6d %6d\n", $r[9],$r[25]);
printf("Rise Time: %6d %6d\n", $r[10],$r[26]);
printf("Off Time: %6d %6d\n", $r[11],$r[27]);
printf("Random Range: %6d %6d\n", $r[12],$r[28]);
printf("Random Value: %6d %6d\n", $r[13],$r[29]);
printf("Boost Remain: %6d %6d\n", $r[14],$r[30]);
printf("Off Remain: %6d %6d\n", $r[15],$r[31]);
printf("VERSION: %s\n",$r[32]);
printf("UPTIME: %s\n",&dhms($r[33]/1000));
printf("ERROR: %d\n",$r[34]);
sub scmd() { ##################################################################################### send command
my($cmd,$quiet)=@_;
$port->write($cmd);
my $founddata=0;
$msg="";
for ($i=0;$i<1000;$i++) {
$in = $port->lookfor();
$founddata=1 if ($in ne "");
$msg.=$in;
last if ($in eq "" && $founddata);
&usleep(2500);
}
$msg=~s/[\r\n]+//g;
return $msg;
}
sub dhms { ######################################################################## convert secs to dd:hh:mm:ss
my($t)=@_;my ($d,$h,$m,$s);
$s=$t%60;$t=($t-$s)/60;$m=$t%60;$t=($t-$m)/60;$h=$t%24;$t=($t-$h)/24;$d=$t;
return sprintf("%d:%02d:%02d:%02d",$d,$h,$m,$s);
}
########################################################################################################### END