Class: Plc::Emulator::EmuDevice
- Inherits:
-
PlcDevice
- Object
- PlcDevice
- Plc::Emulator::EmuDevice
- Defined in:
- lib/plc/emulator/emu_device.rb
Instance Attribute Summary collapse
-
#in_value ⇒ Object
readonly
Returns the value of attribute in_value.
-
#out_value ⇒ Object
readonly
Returns the value of attribute out_value.
Instance Method Summary collapse
- #bool(kind = nil) ⇒ Object
- #bool=(value) ⇒ Object
-
#initialize(a, b = nil) ⇒ EmuDevice
constructor
A new instance of EmuDevice.
- #reset ⇒ Object
- #set_value(value, kind = nil) ⇒ Object
- #sync_input ⇒ Object
- #sync_output ⇒ Object
- #value(kind = nil) ⇒ Object
- #value=(value) ⇒ Object
- #word(kind = nil) ⇒ Object
- #word=(value) ⇒ Object
Constructor Details
#initialize(a, b = nil) ⇒ EmuDevice
Returns a new instance of EmuDevice.
34 35 36 37 38 39 |
# File 'lib/plc/emulator/emu_device.rb', line 34 def initialize a, b = nil super @lock = Mutex.new @in_value = 0 @out_value = 0 end |
Instance Attribute Details
#in_value ⇒ Object (readonly)
Returns the value of attribute in_value.
32 33 34 |
# File 'lib/plc/emulator/emu_device.rb', line 32 def in_value @in_value end |
#out_value ⇒ Object (readonly)
Returns the value of attribute out_value.
32 33 34 |
# File 'lib/plc/emulator/emu_device.rb', line 32 def out_value @out_value end |
Instance Method Details
#bool(kind = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/plc/emulator/emu_device.rb', line 53 def bool kind=nil v = value kind case v when nil, false, 0 false else true end end |
#bool=(value) ⇒ Object
63 64 65 |
# File 'lib/plc/emulator/emu_device.rb', line 63 def bool= value @lock.synchronize { super } end |
#reset ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/plc/emulator/emu_device.rb', line 41 def reset @lock.synchronize { super @in_value = nil @out_value = 0 } end |
#set_value(value, kind = nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/plc/emulator/emu_device.rb', line 90 def set_value value, kind=nil @lock.synchronize { case kind when :in @in_value = value when :out @out_value = value else @value = value end } end |
#sync_input ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/plc/emulator/emu_device.rb', line 103 def sync_input @lock.synchronize { unless @in_value.nil? @value = @in_value @in_value = nil end } end |
#sync_output ⇒ Object
112 113 114 115 116 |
# File 'lib/plc/emulator/emu_device.rb', line 112 def sync_output @lock.synchronize { @out_value = @value } end |
#value(kind = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/plc/emulator/emu_device.rb', line 77 def value kind=nil @lock.synchronize { case kind when :in @in_value when :out @out_value else @value end } end |
#value=(value) ⇒ Object
49 50 51 |
# File 'lib/plc/emulator/emu_device.rb', line 49 def value= value set_value value end |
#word(kind = nil) ⇒ Object
67 68 69 |
# File 'lib/plc/emulator/emu_device.rb', line 67 def word kind=nil value kind end |
#word=(value) ⇒ Object
71 72 73 74 75 |
# File 'lib/plc/emulator/emu_device.rb', line 71 def word= value @lock.synchronize { super } end |