Advertisement
Guest User

Untitled

a guest
Jul 11th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 7.87 KB | None | 0 0
  1. proc startup {} {
  2.    
  3.    #lista zmiennych globalnych
  4.    global a
  5.    set a 0
  6.  
  7.    global b
  8.    set b 0
  9.    
  10.    global reference
  11.    set reference 1  
  12.  
  13.    global min_value
  14.    set min_value 0
  15.    
  16.    global max_value
  17.    set max_value 0
  18.  
  19.    global time1
  20.    set time1 0
  21.    
  22.    global time2
  23.    set time2 0
  24.  
  25.    global c_time1
  26.    set c_time1 0
  27.    
  28.    global c_time2
  29.    set c_time2 0
  30.    
  31.    global listoperator
  32.    set listoperator {}
  33.    
  34.    #zmienna globalna w innym zapisie
  35.    set ::sum 0
  36.    
  37.    
  38.    #interwał czasowy
  39.    antInstallHook "5 s"
  40.    
  41.    #zainicjalizowanie/stworzenie kanałów, które wyświetlać będą konkretne wartości
  42.    antInitializeChannels "Test_channel_1_Callback_From_Sine" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "kV" Logging: "1" ReadingHook: "1m"}
  43.    antInitializeChannels "Test_channel_2_Callback_From_Square" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "kJ" Logging: "1" ReadingHook: "1m"}  
  44.    antInitializeChannels "Test_channel_3_Aritmetic_Function" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "MPH" Logging: "1" ReadingHook: "1m"}
  45.    antInitializeChannels "Test_channel_4_Sum_Of_Sine_And_Square" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "kg" Logging: "1" ReadingHook: "1m"}
  46.    antInitializeChannels "Test_channel_5_Product_Of_Sine_And_Square" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "oz" Logging: "1" ReadingHook: "1m"}
  47.    antInitializeChannels "Test_channel_6_Sine_Value_Powered_By_Module_Property" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "lux" Logging: "1" ReadingHook: "1m"}
  48.    antInitializeChannels "Test_channel_7_Minimal_Sine_Value" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "W" Logging: "1" ReadingHook: "1m"}
  49.    antInitializeChannels "Test_channel_8_Maximal_Sine_Value" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "mA" Logging: "1" ReadingHook: "1m"}
  50.    antInitializeChannels "Test_channel_9_Sum_Of_Last_10_Sine_Values" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "s" Logging: "1" ReadingHook: "1m"}
  51.    antInitializeChannels "Test_channel_10_Integral_Of_Sine" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "lbs" Logging: "1" ReadingHook: "1m"}
  52.    antInitializeChannels "Test_channel_11_Derivative_Of_Sine" {Access: "Writable" ValueType: "Double" Format: "#0" Unit: "km" Logging: "1" ReadingHook: "1m"}
  53.    
  54.    #zainstalowanie wywołań wartości kanałów: Sine i Square z Generatora
  55.    antInstallChannelCallback *Generator/Sine {} "callback"
  56.    antInstallChannelCallback *Generator/Square {} "callback1"
  57. }
  58.  
  59.  
  60. proc shutdown {} {
  61.    # Actions on module's shutdown
  62. }
  63.  
  64.  
  65. proc timerHook {hook_name timestamp} {
  66.    
  67.   if {$hook_name eq "5 s"} {
  68.       # Action on particular hook
  69.      
  70.       #ustalenie wartości kanału '3' na losową wartość podniesioną do potęgi 900
  71.       antSetChannelValue "Test_channel_3_Aritmetic_Function" [expr pow(rand(),900)]
  72.    }
  73. }
  74.  
  75.  
  76. #procedura dodawania elementów listy
  77. #proc listaddition {l} {
  78. #   set total 0.0;
  79. #   foreach nxt $l {
  80. #      set total [expr {$total + $nxt}]};
  81. #      return $total
  82. #   }
  83.  
  84.    
  85. #procedura callback dla kanału Sine
  86. proc callback {channel_name timestamp channel_value status} {
  87.    
  88.    #odwolanie do zmiennych globalnych
  89.    global a
  90.    global b
  91.    global reference
  92.    global min_value
  93.    global max_value
  94.    global c_time1
  95.    global c_time2    
  96.    global time1
  97.    global time2
  98.    global listoperator
  99.    
  100.    #zadeklarowanie zmiennej 'a' równiej wartości kanału Sine
  101.    set a $channel_value
  102.    
  103.    
  104.    #zadeklarowanie zmiennej 'b' równej propertiesowi modułu
  105.    set c [antGetSetting "ExponentOfPower"]
  106.    
  107.    
  108.    #porównywanie wartosci z kanalu z wykorzystaniem zmiennej 'reference'
  109.    #1 - wstępne przypisanie pierwszej wartości kanału zarówno jako wartość minimalna oraz maksymalna
  110.    if {$reference==1} {
  111.       set min_value $channel_value
  112.       set max_value $channel_value
  113.      
  114.    #wyzerowanie odniesienia, żeby nie przypisywana więcej była wartość wstępna  
  115.       set reference 0
  116.    }
  117.    
  118.    #2 - jeżeli kolejna wartość kanału jest mniejsza od dotychczasowej wartości minimalnej, wartość minimalna zostaje nadpisana tą wartością
  119.    if ($min_value>$channel_value) {
  120.       set min_value $channel_value
  121.    }
  122.    
  123.    #3 - jeżeli kolejna wartość kanału jest większa od dotyhczasowej wartości maksymalnej, wartośc maksymalna zostaje nadpisana tą wartością
  124.    if ($max_value<$channel_value) {
  125.       set max_value $channel_value
  126.    }
  127.  
  128.  
  129.  
  130.  
  131.  
  132.    if {1 == $status} {
  133.      
  134.      #zagregowanie 10 najnowszych wartości kanału Sine
  135. #     lappend listoperator $channel_value
  136.      
  137.      #jeżeli lista zawiera 10 elementów
  138. #     if {[llength $listoperator]==10} {
  139.      
  140.      #następuje zsumowanie 10 wartości kanału w oparciu o utworzoną wcześniej procedurę listadditon
  141. #     set ::sum [listaddition $listoperator]
  142.  
  143.      #ustalenie wartości kanału '9' na sumę 10 wartości kanału Sine
  144. #     antSetChannelValue "Test_channel_9_Sum_Of_Last_10_Sine_Values" $::sum
  145.      
  146.      #po wyciągnięciu sumy 10 wartości kanału, następuje wyzerowanie listoperatora oraz przechowującej sumę zmiennej suma
  147. #     set listoperator [lreplace $listoperator 0 0]
  148. #     set ::sum 0
  149. #     }
  150.      
  151.      
  152.      
  153.      
  154.      
  155.  
  156.      #ustalenie wartości kanału '1' na wartość kanału Sine
  157.      antSetChannelValue "Test_channel_1_Callback_From_Sine" $channel_value
  158.      
  159.      #ustalenie wartości kanału '6' na wartość kanału Sine podniesiona do potęgi równej propertiesowi modułu (x^y)
  160.      antSetChannelValue "Test_channel_6_Sine_Value_Powered_By_Module_Property" [expr pow($channel_value, $c)]
  161.      
  162.      #ustalenie wartości kanału '7' na wartość minimalną kanału Sine
  163.      antSetChannelValue "Test_channel_7_Minimal_Sine_Value" $min_value
  164.      
  165.      #ustalenie wartości kanału '8' na wartość maksymalną kanału Sine
  166.      antSetChannelValue "Test_channel_8_Maximal_Sine_Value" $max_value
  167.  
  168.       #ustalenie wartości kanału '9' na sumę 10 wartości kanału Sine
  169.       #antSetChannelValue "Test_channel_9_Sum_Of_Last_10_Sine_Values" $sum
  170.      
  171.    
  172.      #wyświetlenie logów informujących o pobranej wartości
  173.      antLog "Sine value is $channel_value"
  174.      
  175.      antLog "The value of channel $channel_name has been set to $channel_value at [antTimeToString $timestamp]"  
  176.  
  177.    } else {
  178.      
  179.      antLog "Failed to set channel $channel_name"
  180.      
  181.    }
  182. }
  183.  
  184.  
  185. #procedura callback1 dla kanału 'Square''
  186. proc callback1 {channel_name timestamp channel_value status} {
  187.    
  188.    #odwołanie do zmiennych globalnych
  189.    global a
  190.    global b
  191.    
  192.      
  193.    if {1 == $status} {
  194.      
  195.      #zadeklarowanie zmiennej 'b' równiej wartości kanału Square
  196.      set b $channel_value
  197.      
  198.      #ustalenie wartości kanału '2' na wartość kanału Square    
  199.      antSetChannelValue "Test_channel_2_Callback_From_Square" $channel_value      
  200.      
  201.      #ustalenie wartości kanału '4' równej sumie wartości kanałów Sine i Square
  202.      antSetChannelValue "Test_channel_4_Sum_Of_Sine_And_Square" [expr $a+$b]
  203.      
  204.      #ustalenie wartości kanału '5' równej iloczynowi wartości kanałów Sine i Square
  205.      antSetChannelValue "Test_channel_5_Product_Of_Sine_And_Square" [expr $a*$b]
  206.      
  207.      
  208.      
  209.      #wyświetlenie logów informujących o pobranych wartościach kanału, sumy oraz iloczynu
  210.      antLog "Square value is $channel_value"
  211.      antLog "The value of channel $channel_name has been set to $channel_value at [antTimeToString $timestamp]"  
  212.      antLog "The damned sum of Sine and Square channel values is: [expr $a+$b]"
  213.      antLog "A deprecated product of Sine and Square channel values is: [expr $a*$b]"
  214.    
  215.    } else {
  216.      
  217.      antLog "Failed to set channel $channel_name"
  218.      
  219.    }
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement