From 16bdb3de2d0ac84e5e63831cccfd275679d493d4 Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Tue, 13 Apr 2021 12:25:52 +0200 Subject: [PATCH] add support for KA3000 devices --- powersupplies/web/htdocs/build_index.pl | 8 + powersupplies/web/htdocs/pwr.pl | 32 +++- powersupplies/web/htdocs/pwr_ka3000.htm | 195 ++++++++++++++++++++++++ powersupplies/web/htdocs/pwr_remote.pl | 28 +++- 4 files changed, 257 insertions(+), 6 deletions(-) create mode 100644 powersupplies/web/htdocs/pwr_ka3000.htm diff --git a/powersupplies/web/htdocs/build_index.pl b/powersupplies/web/htdocs/build_index.pl index c416157..4151fea 100755 --- a/powersupplies/web/htdocs/build_index.pl +++ b/powersupplies/web/htdocs/build_index.pl @@ -52,6 +52,14 @@ print <Power Supply $dev_id [connected to $ser_dev] +EOF +} + +if($type =~ /KA3000/) { +print <Power Supply $dev_id [connected to $ser_dev] + + EOF } diff --git a/powersupplies/web/htdocs/pwr.pl b/powersupplies/web/htdocs/pwr.pl index e1fc870..c6b21e9 100755 --- a/powersupplies/web/htdocs/pwr.pl +++ b/powersupplies/web/htdocs/pwr.pl @@ -16,6 +16,7 @@ use Time::HiRes qw( usleep); use POSIX qw/floor ceil strftime/; use Fcntl; use Storable qw(lock_store lock_retrieve); +no warnings 'uninitialized'; my $envstring = $ENV{'QUERY_STRING'}; $envstring =~ s/%20/ /g; @@ -66,7 +67,7 @@ elsif($ser_dev =~ /^SER(.*)/) { else { if ($ser_speed != 0){ my $command = "stty -F $ser_dev speed $ser_speed -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke"; - print stderr "$command\n"; +# print STDERR "$command\n"; $command .= " -ixoff " if $ser_type eq 'PSP'; my $res = qx($command); } @@ -82,6 +83,7 @@ else { else { print HMP_serial() if (($ser_type eq "HMP" or $ser_type eq "HMC") && $isIP == 0) or $ser_type eq "PST"; print PWRSW_serial() if $ser_type eq "PWRSW"; + print KA3000_serial() if $ser_type eq "KA3000"; print HMP_ethernet() if (($ser_type eq "HMP" or $ser_type eq "HMC") && $isIP == 1); print PSP() if $ser_type eq 'PSP'; } @@ -189,6 +191,26 @@ sub HMP_serial { return; } + +sub KA3000_serial { + print strftime("%H:%M:%S &", localtime()); + my $fh; + if(-e $ser_dev && -w $ser_dev) { + sysopen($fh, $ser_dev, O_RDWR|O_NDELAY) or die $!; + } + else { print "Device not found"; return;} + + while ( my $command = shift(@new_command) ) { + $command = uri_unescape($command); + my $x = getValue($fh,$command,$cnt++); + $x =~ s/\&//; + $x = ord($x) if $command eq "STATUS?"; + print $x."&" if $command =~ /\?/; + usleep(40000);# if $ser_type eq "PST"; + } + close $fh; + return; + } sub HMP_ethernet { @@ -209,12 +231,14 @@ sub HMP_ethernet { sub serial_rw { my ($fh, $command,$forceread) = @_; my $x = ""; - if ($ser_type eq 'PSP') {$command .= "\r";} else {$command .= "\n";} + if ($ser_type eq 'PSP') {$command .= "\r";} + elsif ($ser_type ne 'KA3000') {$command .= "\n";} + print $fh "$command"; # print $command; if($ser_type eq 'PWRSW' || $forceread || $command =~ /\?/) { for my $i (0..500) { - $x .= <$fh>; + $x .= <$fh>; if($x && ($x =~ /\n/ || $x =~ /\r/) ) { chomp $x; last; @@ -237,7 +261,7 @@ sub getValue { else { usleep(10000); my $val = serial_rw($fh,$cmd,$forceread); - if($val eq "") { + if($val eq "" && $ser_type ne 'KA3000') { return $db->{$cmd.$cnt}{val}; } addDB($cmd.$cnt,$val); diff --git a/powersupplies/web/htdocs/pwr_ka3000.htm b/powersupplies/web/htdocs/pwr_ka3000.htm new file mode 100644 index 0000000..5751a74 --- /dev/null +++ b/powersupplies/web/htdocs/pwr_ka3000.htm @@ -0,0 +1,195 @@ + + + + + + +Power Supply Monitor and Access + + + + + + + + +
+ + + + + + +
+ Output + +
Settings [V/A] + + + + + +
Actual[V/A] + + + + + +
Output Relais + + + + +
Enable read-back +   + +
+
+ + + + diff --git a/powersupplies/web/htdocs/pwr_remote.pl b/powersupplies/web/htdocs/pwr_remote.pl index 7bd7c30..c2478cc 100644 --- a/powersupplies/web/htdocs/pwr_remote.pl +++ b/powersupplies/web/htdocs/pwr_remote.pl @@ -70,6 +70,7 @@ transmit_command() if $ser_type eq "PSP"; #if new command, send it! receive_answer() if $ser_type eq "PSP"; # always called HMP_serial() if $ser_type eq 'HMP'; +KA3000_serial() if $ser_type eq "KA3000"; sub transmit_command { @@ -104,6 +105,27 @@ sub HMP_serial { } +sub KA3000_serial { + print strftime("%H:%M:%S &", localtime()); + my $fh; + if(-e $ser_dev && -w $ser_dev) { + sysopen($fh, $ser_dev, O_RDWR|O_NDELAY) or die $!; + } + else { print "Device not found"; return;} + + while ( my $command = shift(@new_command) ) { + $command = uri_unescape($command); + my $x = getValue($fh,$command,$cnt++); + $x =~ s/\&//; + $x = ord($x) if $command eq "STATUS?"; + print $x."&" if $command =~ /\?/; + usleep(40000);# if $ser_type eq "PST"; + } + close $fh; + return; + } + + sub receive_answer { @@ -176,7 +198,9 @@ sub receive_answer { sub serial_rw { my ($fh, $command,$forceread) = @_; my $x = ""; - if ($ser_type eq 'PSP') {$command .= "\r";} else {$command .= "\n";} + if ($ser_type eq 'PSP') {$command .= "\r";} + elsif ($ser_type ne 'KA3000') {$command .= "\n";} + print $fh "$command"; # print $command; if($ser_type eq 'PWRSW' || $forceread || $command =~ /\?/) { @@ -204,7 +228,7 @@ sub getValue { else { usleep(10000); my $val = serial_rw($fh,$cmd,$forceread); - if($val eq "") { + if($val eq "" && $ser_type ne 'KA3000') { return $db->{$cmd.$cnt}{val}; } addDB($cmd.$cnt,$val); -- 2.43.0