perltux has asked for the wisdom of the Perl Monks concerning the following question:
This test program can also be downloaded from my website at the following URL: http://obd-amigos.linuxtech.net/test1/amigos-test1.pl#!/usr/bin/env perl use strict; use warnings; use POSIX qw(strftime); use Tk; my %pid=( DCDC_A_51=>{cmd=>'22 46 5B', cu=>'51', desc=>'DC/DC output curren +t t30', unit=>'A', d=>2, formula=>'sprintf("%.2f", U16(1 +,4)/16)'}, DCDC_V_51=>{cmd=>'22 46 5C', cu=>'51', desc=>'DC/DC output voltag +e t30', unit=>'V', d=>2, formula=>'sprintf("%.2f", U16(2 +5,253)/512)', val=>'---'}, DCDC_W_51=>{ desc=>'DC/DC power output' +, unit=>'W', action=>'sprintf("%.0f", ($pid +{DCDC_V_51}{val} * $pid{DCDC_A_51}{val}))', val=>'---'} ); my $mw=MainWindow->new(); $mw->Button(-text=>" Test ", -command=>sub{test()}, -font=>'Helvet +ica 18 bold', -pady=>20)->pack(); MainLoop; sub test { $pid{DCDC_V_51}{val}=eval($pid{DCDC_V_51}{formula}); print $pid{DCDC_V +_51}{val} ."\n"; $pid{DCDC_A_51}{val}=eval($pid{DCDC_A_51}{formula}); print $pid{DCDC_A +_51}{val} ."\n"; my $formula=$pid{DCDC_W_51}{action}; $pid{DCDC_W_51}{val}=eval($formula); print $pid{DCDC_W_51}{val} ."\n"; } sub U16 { my($a,$b)=@_; return ($a*256+$b); }
|
|---|