| 1 | package Lab::Instrument::TemperatureControl::TLK43; | ||
| 2 | #ABSTRACT: Electronic process controller TLKA41/42/43 (SIKA GmbH) with RS485 MODBUS-RTU interface | ||
| 3 | $Lab::Instrument::TemperatureControl::TLK43::VERSION = '3.899'; | ||
| 4 | use v5.20; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use Lab::Instrument; | ||
| 8 | use Lab::Bus::MODBUS_RS232; | ||
| 9 | use feature "switch"; | ||
| 10 | use Data::Dumper; | ||
| 11 | use Carp; | ||
| 12 | |||
| 13 | our @ISA = ("Lab::Instrument"); | ||
| 14 | |||
| 15 | our %fields = ( | ||
| 16 | supported_connections => ['MODBUS_RS232'], | ||
| 17 | slave_address => undef, | ||
| 18 | connection => undef, | ||
| 19 | |||
| 20 | MemTable => { | ||
| 21 | Measurement => 0x0200, # measured value | ||
| 22 | Decimal => 0x0201, # decimal points dP | ||
| 23 | CalculatedPower => 0x0202, # calculated power | ||
| 24 | HeatingPower => 0x0203, # available heating power | ||
| 25 | CoolingPower => 0x0204, # available cooling power | ||
| 26 | State_Alarm1 => 0x0205, # state of alarm 1 | ||
| 27 | State_Alarm2 => 0x0206, # state of alarm 2 | ||
| 28 | State_Alarm3 => 0x0207, # state of alarm 3 | ||
| 29 | Setpoint => 0x0208, # current setpoint | ||
| 30 | State_AlarmLBA => 0x020A, # state of alarm LBA | ||
| 31 | State_AlarmHB => 0x020B, # state of alarm HB (heater break) | ||
| 32 | CurrentHB_closed => 0x020C, # current for HB with closed circuit | ||
| 33 | CurrentHB_open => 0x020D, # current for HB with open circuit | ||
| 34 | State_Controller => 0x020F | ||
| 35 | , # state of controller (0: Off, 1: auto. Reg., 2: Tuning, 3: man. Reg. | ||
| 36 | PreliminaryTarget => 0x0290, # preliminary target value (TLK43) | ||
| 37 | AnalogueRepeat => 0x02A0, # value to repeat on analogue output (TLK43) | ||
| 38 | |||
| 39 | # SP group (parameters relative to setpoint) | ||
| 40 | nSP => 0x2800, # number of programmable setpoints | ||
| 41 | SPAt => 0x2801, # selects active setpoint | ||
| 42 | SP1 => 0x2802, # setpoint 1 | ||
| 43 | SP2 => 0x2803, # setpoint 2 | ||
| 44 | SP3 => 0x2804, # setpoint 3 | ||
| 45 | SP4 => 0x2805, # setpoint 4 | ||
| 46 | SPLL => 0x2806, # low setpoint limit | ||
| 47 | SPHL => 0x2807, # high setpoint limit | ||
| 48 | |||
| 49 | # InP group (parameters relative to the measure input) | ||
| 50 | HCFG => 0x2808, # type of input with universal input configuration | ||
| 51 | SEnS => 0x2809, # type of sensor (depends on HCFG) | ||
| 52 | rEFL => 0x2857, # coefficient of reflection | ||
| 53 | SSC => 0x280A, # start of scale | ||
| 54 | FSC => 0x280B, # full scale deflection | ||
| 55 | dP => 0x280C, # decimal points (for measurement) | ||
| 56 | Unit => 0x280D, # 0=°C, 1=F | ||
| 57 | FiL => 0x280E, # digital filter on input (OFF .. 20.0 sec) | ||
| 58 | OFSt => 0x2810 | ||
| 59 | , # offset of measurement with dP decimal points (-1999..9999) ? | ||
| 60 | rot => 0x2811, # rotation of the measuring straight line | ||
| 61 | InE => 0x2812 | ||
| 62 | , # "OPE" functioning in case of measuring error (0=OR, 1=Ur, 2=OUr) | ||
| 63 | OPE => 0x2813, # output power in case of measuring error (-100..100) | ||
| 64 | dIF => 0x2858, # digital input function | ||
| 65 | |||
| 66 | # O1 group (parameteres relative to output 1) | ||
| 67 | O1F => 0x2814 | ||
| 68 | , # functioning of output 1 (0=OFF, 1=1.rEg, 2=2.rEg, 3=Alno, 4=ALnc) | ||
| 69 | Aor1 => 0x2859, # Beginning of analogue output 1 scale (0=0, 1=no_0) | ||
| 70 | Ao1F => 0x285A | ||
| 71 | , # functioning of analogue output 1 (0=OFF, 1=inp, 2=err, 3=r.SP, 4=r.SEr) | ||
| 72 | Ao1L => 0x285B | ||
| 73 | , # Minimum reference for analogical output 1 for signal transmission (with dP, -1999..9999) | ||
| 74 | A01H => 0x285C | ||
| 75 | , # Maximum reference for analogical output 1 for signal transmission (with dP, A01L..9999) | ||
| 76 | |||
| 77 | # O2 group (parameteres relative to output 2) | ||
| 78 | O2F => 0x2815 | ||
| 79 | , # functioning of output 2 (0=OFF, 1=1.rEg, 2=2.rEg, 3=Alno, 4=ALnc) | ||
| 80 | Aor2 => 0x285D, # Beginning of analogue output 2 scale (0=0, 1=no_0) | ||
| 81 | Ao2F => 0x285E | ||
| 82 | , # functioning of analogue output 2 (0=OFF, 1=inp, 2=err, 3=r.SP, 4=r.SEr) | ||
| 83 | Ao2L => 0x285F | ||
| 84 | , # Minimum reference for analogical output 2 for signal transmission (with dP, -1999..9999) | ||
| 85 | A02H => 0x2860 | ||
| 86 | , # Maximum reference for analogical output 2 for signal transmission (with dP, A02L..9999) | ||
| 87 | |||
| 88 | # O3 group (parameteres relative to output 3) | ||
| 89 | O3F => 0x2816 | ||
| 90 | , # functioning of output 3 (0=OFF, 1=1.rEg, 2=2.rEg, 3=Alno, 4=ALnc) | ||
| 91 | Aor3 => 0x2861, # Beginning of analogue output 3 scale (0=0, 1=no_0) | ||
| 92 | Ao3F => 0x2862 | ||
| 93 | , # functioning of analogue output 3 (0=OFF, 1=inp, 2=err, 3=r.SP, 4=r.SEr) | ||
| 94 | Ao3L => 0x2863 | ||
| 95 | , # Minimum reference for analogical output 3 for signal transmission (with dP, -1999..9999) | ||
| 96 | A03H => 0x2864 | ||
| 97 | , # Maximum reference for analogical output 3 for signal transmission (with dP, A03L..9999) | ||
| 98 | |||
| 99 | # O4 group (parameters relative to output 4) | ||
| 100 | O4F => 0x2817 | ||
| 101 | , # functioning of output 4 (0=OFF, 1=1.rEg, 2=2.rEg, 3=Alno, 4=ALnc) | ||
| 102 | |||
| 103 | # Al1 group (parameteres relative to alarm 1 | ||
| 104 | OAL1 => 0x2818 | ||
| 105 | , # Output where alarm AL1 is addressed (0=OFF, 1=Out1, 2=Out2, 3=Out3, 4=Out4) | ||
| 106 | AL1t => 0x2819 | ||
| 107 | , # Alarm AL1 type (0=LoAb, 1=HiAb, 2=LHAb, 3=LodE, 4=HidE, 5=LHdE) | ||
| 108 | Ab1 => 0x281A | ||
| 109 | , # Alarm AL1 functioning (0=no function, 1=alarm hidden at startup, 2=alarm delayed, 4=alarm stored, 8=alarm acknowledged | ||
| 110 | AL1 => 0x281B, # Alarm AL1 threshold (with dP, -1999..9999) | ||
| 111 | AL1L => 0x281C | ||
| 112 | , # Low threshold band alarm AL1 or Minimum set alarm AL1 for high or low alarm (with dP, -1999..9999) | ||
| 113 | AL1H => 0x281D | ||
| 114 | , # High threshold band alarm AL1 or Maximum set alarm AL1 for high or low alarm (with dP, -1999..9999) | ||
| 115 | HAL1 => 0x281E, # Alarm AL1 hysteresis (with dP, 0=OFF..9999) | ||
| 116 | AL1d => | ||
| 117 | 0x281F, # Activation delay of alarm AL1 (with dP, 9=OFF..9999sec) | ||
| 118 | AL1i => 0x2820 | ||
| 119 | , # Alarm AL1 activation in case of measuring error (0=no, 1=yes) | ||
| 120 | |||
| 121 | # rEG group (parameters relative to controller | ||
| 122 | Cont => 0x283B, # Control type (0=PID, 1=On.Fa, 2=On.FS, 3=nr, 4=3Pt) | ||
| 123 | Func => 0x283C, # functioning mode output 1rEg (0=Heat, 1=Cool) | ||
| 124 | Auto => 0x283D, # Autotuning Fast enable | ||
| 125 | SELF => 0x283E, # Selftuning enable (0=No, 1=Yes) | ||
| 126 | HSEt => 0x283F, # Hysteresis of ON/OFF Control (9999 ... -1999) | ||
| 127 | Pb => 0x2840, # Proportional band (0...9999) | ||
| 128 | Int => 0x2841, # Integral time (0=OFF...9999sec) | ||
| 129 | dEr => 0x2842, # Derivative time (0=OFF...9999sec) | ||
| 130 | FuOc => 0x2843, # Fuzzy overshoot control (0.00...2.00) | ||
| 131 | tcr1 => 0x2833, # Cycle time of output 1rEg (0.1...130sec) | ||
| 132 | Prat => 0x2845, # Power ration 2rEg/1rEg (0.1...999.9) | ||
| 133 | tcr2 => 0x2846, # Cycle time of 2rEg (0.1...130sec) | ||
| 134 | rS => 0x2847, # Manual reset (-100%...100%) | ||
| 135 | tcor => 0x2866, # Time for motorised actuator run (4...1000sec) | ||
| 136 | SHrl => | ||
| 137 | 0x2867, # Minimum value for motorised actuator control (0.1...10%) | ||
| 138 | PoSI => 0x2868 | ||
| 139 | , # Switch on position for motorised actuator (0=No, 1=close, 2=open) | ||
| 140 | SLor => 0x2849, # Gradient of rise ramp (0.00...99.99) | ||
| 141 | durt => 0x284A, # Duration time | ||
| 142 | SLoF => 0x284B, # Gradient of fall ramp | ||
| 143 | ro1L => 0x2869, # Minimum power in ouput from 1rEG (0...100%) | ||
| 144 | ro1H => 0x286A, # Maximum power ... (ro1L...100%) | ||
| 145 | ro2L => 0x286B, # Minimum power in output from 2rEG (0...100%) | ||
| 146 | ro2H => 0x286C, # Maximum power... (ro2L...100%) | ||
| 147 | tHr1 => 0x286D, # Split Range Power threshold of output 1rEG | ||
| 148 | tHr2 => 0x286E, # ... of output 2rEG | ||
| 149 | OPS1 => | ||
| 150 | 0x286F, # Power variation speed in output from 1rEG (0...50%/sec) | ||
| 151 | OPS2 => 0x2870, # ... from 2rEG | ||
| 152 | StP => 0x284C, # Soft-start power (-100, -101=OFF, 100) | ||
| 153 | SSt => 0x284D, # Soft-start time (0=OFF...7.59 h.min) | ||
| 154 | |||
| 155 | # to be continued | ||
| 156 | |||
| 157 | }, | ||
| 158 | |||
| 159 | MemCache => | ||
| 160 | { # used by read_int_cached and write_int_cached to cache 16bit values | ||
| 161 | }, | ||
| 162 | ); | ||
| 163 | |||
| 164 | sub new { | ||
| 165 | my $proto = shift; | ||
| 166 | my $class = ref($proto) || $proto; | ||
| 167 | my $self = $class->SUPER::new(@_); # sets $self->config | ||
| 168 | $self->_construct( __PACKAGE__, \%fields ) | ||
| 169 | ; # this sets up all the object fields out of the inheritance tree. | ||
| 170 | # also, it does generic connection setup. | ||
| 171 | |||
| 172 | return $self; | ||
| 173 | } | ||
| 174 | |||
| 175 | sub read_temperature { | ||
| 176 | my $self = shift; | ||
| 177 | my @Result = (); | ||
| 178 | my $Temp = undef; | ||
| 179 | my $dP = 0; | ||
| 180 | |||
| 181 | #return undef unless defined($dP = $self->read_int_cached({ mem_address => 'dP' })); | ||
| 182 | if ( !defined( $dP = $self->read_int_cached( { mem_address => 'dP' } ) ) ) | ||
| 183 | { | ||
| 184 | print "Error in cached read of dP\n"; | ||
| 185 | return undef; | ||
| 186 | } | ||
| 187 | |||
| 188 | return undef | ||
| 189 | unless defined( $Temp | ||
| 190 | = $self->read_address_int( $self->MemTable()->{'Measurement'} ) ); | ||
| 191 | |||
| 192 | $Temp == 10001 | ||
| 193 | ? warn( | ||
| 194 | "Warning: Measurement exception $Temp received. Sensor disconnected.\n" | ||
| 195 | ) | ||
| 196 | : $Temp == 10000 ? warn( | ||
| 197 | "Warning: Measurement exception $Temp received. Measuring value underrange.\n" | ||
| 198 | ) | ||
| 199 | : $Temp == -10000 ? warn( | ||
| 200 | "Warning: Measurement exception $Temp received. Measuring value overrange.\n" | ||
| 201 | ) | ||
| 202 | : $Temp == 10003 ? warn( | ||
| 203 | "Warning: Measurement exception $Temp received. Measured variable not available.\n" | ||
| 204 | ) | ||
| 205 | : return $Temp / 10**$dP; | ||
| 206 | |||
| 207 | return undef; | ||
| 208 | } | ||
| 209 | |||
| 210 | sub read_int_cached { # { mem_address => $mem_address, ForceRead => (1,0) } | ||
| 211 | my $self = shift; | ||
| 212 | my $args = shift; | ||
| 213 | my $mem_address = $args->{'mem_address'} || undef; | ||
| 214 | my $ForceRead = $args->{'ForceRead'}; | ||
| 215 | if ( $mem_address !~ /^[0-9]*$/ ) { | ||
| 216 | $mem_address = $self->MemTable()->{$mem_address} || undef; | ||
| 217 | } | ||
| 218 | |||
| 219 | if ( !$ForceRead | ||
| 220 | && exists( $self->MemCache()->{$mem_address} ) | ||
| 221 | && defined( $self->MemCache()->{$mem_address} ) ) { | ||
| 222 | return $self->MemCache()->{$mem_address}; | ||
| 223 | } | ||
| 224 | else { | ||
| 225 | return undef | ||
| 226 | unless defined( $self->MemCache()->{$mem_address} | ||
| 227 | = $self->read_address_int($mem_address) ); | ||
| 228 | return $self->MemCache()->{$mem_address}; | ||
| 229 | } | ||
| 230 | } | ||
| 231 | |||
| 232 | sub write_int_cached | ||
| 233 | { # { mem_address => $mem_address, mem_value => $Value } stores mem_value as number (int) | ||
| 234 | my $self = shift; | ||
| 235 | my $args = shift; | ||
| 236 | my $mem_address = $args->{mem_address} || undef; | ||
| 237 | my $mem_value = int( $args->{mem_value} ) || undef; | ||
| 238 | if ( $mem_address !~ /^[0-9]*$/ ) { | ||
| 239 | $mem_address = $self->MemTable()->{$mem_address} || undef; | ||
| 240 | } | ||
| 241 | |||
| 242 | return undef | ||
| 243 | unless $self->write_address( | ||
| 244 | { mem_address => $mem_address, mem_value => $mem_value } ); | ||
| 245 | return ( ( $self->MemCache()->{$mem_address} = $mem_value ) ); | ||
| 246 | } | ||
| 247 | |||
| 248 | sub set_setpoint { # { Slot => (1..4), Value => Int } | ||
| 249 | my $self = shift; | ||
| 250 | my $args = shift; | ||
| 251 | my $TargetTemp = $args->{'Value'}; | ||
| 252 | my $Slot = $args->{'Slot'}; | ||
| 253 | my $nSP = 1; | ||
| 254 | my $dP = 0; | ||
| 255 | |||
| 256 | return undef unless defined( $nSP = $self->read_int_cached('nSP') ); | ||
| 257 | return undef unless defined( $dP = $self->read_int_cached('dP') ); | ||
| 258 | |||
| 259 | if ( $Slot > $nSP || $Slot < 1 ) { | ||
| 260 | return undef; | ||
| 261 | } | ||
| 262 | else { | ||
| 263 | $TargetTemp = sprintf( "%.${dP}f", $TargetTemp ) | ||
| 264 | * 10**$dP; # rounding, shifting decimal places | ||
| 265 | return undef | ||
| 266 | if ( $TargetTemp > 32767 || $TargetTemp < -32768 ) | ||
| 267 | ; # still fitting in a signed 16bit int? | ||
| 268 | #$TargetTemp = ( $TargetTemp + 2**16 ) if $TargetTemp < 0; | ||
| 269 | return $self->write_address( | ||
| 270 | { | ||
| 271 | mem_address => $self->MemTable()->{'Setpoint'} + $Slot - 1, | ||
| 272 | mem_value => $TargetTemp | ||
| 273 | } | ||
| 274 | ); | ||
| 275 | } | ||
| 276 | } | ||
| 277 | |||
| 278 | sub set_active_setpoint { # $value | ||
| 279 | my $self = shift; | ||
| 280 | my $TargetTemp = shift; | ||
| 281 | my $Slot = 1; | ||
| 282 | my $dP = 0; | ||
| 283 | return undef | ||
| 284 | unless defined( $Slot | ||
| 285 | = $self->read_int_cached( { mem_address => 'SPAt' } ) ); | ||
| 286 | return undef | ||
| 287 | unless | ||
| 288 | defined( $dP = $self->read_int_cached( { mem_address => 'dP' } ) ); | ||
| 289 | |||
| 290 | $TargetTemp = sprintf( "%.${dP}f", $TargetTemp ) | ||
| 291 | * 10**$dP; # rounding, shifting decimal places | ||
| 292 | return undef | ||
| 293 | if ( $TargetTemp > 32767 || $TargetTemp < -32768 ) | ||
| 294 | ; # still fitting in a signed 16bit int? | ||
| 295 | #$TargetTemp = ( $TargetTemp + 2**16 ) if $TargetTemp < 0; | ||
| 296 | return $self->write_address( | ||
| 297 | { | ||
| 298 | mem_address => $self->MemTable()->{'SP1'} + $Slot - 1, | ||
| 299 | mem_value => $TargetTemp | ||
| 300 | } | ||
| 301 | ); | ||
| 302 | } | ||
| 303 | |||
| 304 | sub set_setpoint_slot { # { Slot => (1..4) } | ||
| 305 | my $self = shift; | ||
| 306 | my $args = shift; | ||
| 307 | my $Slot = int( $args->{'Slot'} ) || return undef; | ||
| 308 | my $nSP = undef; | ||
| 309 | return undef unless defined( $nSP = $self->read_int_cached('nSP') ); | ||
| 310 | |||
| 311 | if ( $Slot > $nSP || $Slot < 1 ) { | ||
| 312 | return undef; | ||
| 313 | } | ||
| 314 | else { | ||
| 315 | return $self->write_address( | ||
| 316 | { | ||
| 317 | mem_address => $self->MemTable()->{'SPAt'}, | ||
| 318 | mem_value => $Slot | ||
| 319 | } | ||
| 320 | ); | ||
| 321 | } | ||
| 322 | } | ||
| 323 | |||
| 324 | sub set_Precision { # $Precision | ||
| 325 | my $self = shift; | ||
| 326 | my $precision = int(shift); | ||
| 327 | |||
| 328 | return undef if ( $precision < 0 || $precision > 3 ); | ||
| 329 | return $self->write_address( | ||
| 330 | { mem_address => $self->MemTable()->{'sP'}, mem_value => $precision } | ||
| 331 | ); | ||
| 332 | } | ||
| 333 | |||
| 334 | sub set_speed | ||
| 335 | { # set speed of temperature increase and decrease, in deg/minute. set "off" to disable (infinite speed) | ||
| 336 | my $self = shift; | ||
| 337 | my $speed = shift; | ||
| 338 | |||
| 339 | $speed = 100 if ( $speed =~ /off/i ); | ||
| 340 | $speed = sprintf( "%.2f", $speed ) | ||
| 341 | * 100; # 2 decimal places hardwired, transferred as int | ||
| 342 | |||
| 343 | $self->write_address( | ||
| 344 | { mem_address => $self->MemTable()->{'SLoF'}, mem_value => $speed } ); | ||
| 345 | $self->write_address( | ||
| 346 | { mem_address => $self->MemTable()->{'SLor'}, mem_value => $speed } ); | ||
| 347 | return 1; | ||
| 348 | } | ||
| 349 | |||
| 350 | sub set_speed_rising | ||
| 351 | { # set speed of temperature increase, in deg/minute. set "off" to disable (infinite speed) | ||
| 352 | my $self = shift; | ||
| 353 | my $speed = shift; | ||
| 354 | |||
| 355 | $speed = 100 if ( $speed =~ /off/i ); | ||
| 356 | $speed = sprintf( "%.2f", $speed ) | ||
| 357 | * 100; # 2 decimal places hardwired, transferred as int | ||
| 358 | |||
| 359 | return $self->write_address( | ||
| 360 | { mem_address => $self->MemTable()->{'SLor'}, mem_value => $speed } ); | ||
| 361 | } | ||
| 362 | |||
| 363 | sub set_speed_falling | ||
| 364 | { # set speed of temperature decrease, in deg/minute. set "off" to disable (infinite speed) | ||
| 365 | my $self = shift; | ||
| 366 | my $speed = shift; | ||
| 367 | |||
| 368 | $speed = 100 if ( $speed =~ /off/i ); | ||
| 369 | $speed = sprintf( "%.2f", $speed ) | ||
| 370 | * 100; # 2 decimal places hardwired, transferred as int | ||
| 371 | |||
| 372 | return $self->write_address( | ||
| 373 | { mem_address => $self->MemTable()->{'SLoF'}, mem_value => $speed } ); | ||
| 374 | } | ||
| 375 | |||
| 376 | sub read_range | ||
| 377 | { # { mem_address => Address (16bit), MemCount => Count (8bit, (1..4), default 1) | ||
| 378 | my $self = shift; | ||
| 379 | my $args = shift; | ||
| 380 | my $mem_address = $args->{mem_address} || undef; | ||
| 381 | my $MemCount = $args->{MemCount} || 1; | ||
| 382 | $MemCount = int($MemCount); | ||
| 383 | if ( $mem_address !~ /^[0-9]*$/ ) { | ||
| 384 | $mem_address = $self->MemTable()->{$mem_address} || undef; | ||
| 385 | } | ||
| 386 | |||
| 387 | if ( !$mem_address | ||
| 388 | || !$MemCount | ||
| 389 | || $mem_address > 0xFFFF | ||
| 390 | || $mem_address < 0x0200 | ||
| 391 | || $MemCount > 4 | ||
| 392 | || $MemCount <= 0 ) { | ||
| 393 | return undef; | ||
| 394 | } | ||
| 395 | else { | ||
| 396 | return $self->connection()->Read( | ||
| 397 | function => 3, | ||
| 398 | mem_address => $mem_address, | ||
| 399 | MemCount => $MemCount | ||
| 400 | ); | ||
| 401 | } | ||
| 402 | } | ||
| 403 | |||
| 404 | sub read_address_int { # $Address | ||
| 405 | my $self = shift; | ||
| 406 | my @Result = (); | ||
| 407 | my $SignedValue = 0; | ||
| 408 | my $mem_address = shift || undef; | ||
| 409 | if ( $mem_address !~ /^[0-9]*$/ ) { | ||
| 410 | $mem_address = $self->MemTable()->{$mem_address} || undef; | ||
| 411 | } | ||
| 412 | |||
| 413 | if ( !$mem_address || $mem_address > 0xFFFF || $mem_address < 0x0200 ) { | ||
| 414 | print "Address invalid\n"; | ||
| 415 | return undef; | ||
| 416 | } | ||
| 417 | else { | ||
| 418 | @Result = $self->connection()->Read( | ||
| 419 | function => 3, | ||
| 420 | mem_address => $mem_address, | ||
| 421 | MemCount => 1 | ||
| 422 | ); | ||
| 423 | if ( scalar(@Result) == 2 ) | ||
| 424 | { # correct answer has to be two bytes long | ||
| 425 | $SignedValue = unpack( 'n!', join( '', @Result ) ); | ||
| 426 | } | ||
| 427 | else { | ||
| 428 | warn "Error on bus level\n"; | ||
| 429 | return undef; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | } | ||
| 433 | |||
| 434 | sub write_address | ||
| 435 | { # { mem_address => Address (16bit), mem_value => Value (16 bit word) } | ||
| 436 | my $self = shift; | ||
| 437 | my $args = shift; | ||
| 438 | my $mem_address = $args->{mem_address} || undef; | ||
| 439 | my $mem_value = int( $args->{mem_value} ) || undef; | ||
| 440 | |||
| 441 | if ( $mem_address !~ /^[0-9]*$/ ) { | ||
| 442 | $mem_address = $self->MemTable()->{$mem_address} || undef; | ||
| 443 | } | ||
| 444 | |||
| 445 | if ( !$mem_address | ||
| 446 | || ( !$mem_value && $mem_value != 0 ) | ||
| 447 | || $mem_address > 0xFFFF | ||
| 448 | || $mem_address < 0x0200 | ||
| 449 | || $mem_value > 0xFFFF | ||
| 450 | || $mem_value < 0 ) { | ||
| 451 | return undef; | ||
| 452 | } | ||
| 453 | else { | ||
| 454 | return $self->connection()->Write( | ||
| 455 | function => 6, | ||
| 456 | mem_address => $mem_address, | ||
| 457 | mem_value => $mem_value | ||
| 458 | ); | ||
| 459 | } | ||
| 460 | } | ||
| 461 | |||
| 462 | 1; | ||
| 463 | |||
| 464 | __END__ |