Class: Simatic::Types::S7String
- Inherits:
-
SimaticType
- Object
- SimaticType
- Simatic::Types::S7String
- Defined in:
- lib/simatic/types/s7_string.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value, size = nil) ⇒ S7String
constructor
A new instance of S7String.
- #serialize ⇒ Object
Methods inherited from SimaticType
Constructor Details
#initialize(value, size = nil) ⇒ S7String
Returns a new instance of S7String.
6 7 8 9 |
# File 'lib/simatic/types/s7_string.rb', line 6 def initialize value, size = nil @size = size @value = value end |
Class Method Details
.parse_one(raw_value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/simatic/types/s7_string.rb', line 25 def self.parse_one raw_value res = raw_value.unpack('CCa*') buf_size = res[0] string_size = res[1] string = res[2] raise "S7String is broken, cant parse" if buf_size.nil? || string_size.nil? || string.nil? || buf_size < string_size string[0, string_size] end |
.serialize(value, size) ⇒ Object
11 12 13 14 15 |
# File 'lib/simatic/types/s7_string.rb', line 11 def self.serialize value, size raise "Value must be String class" unless value.kind_of? String size = size || value.length [size, value.length, value].pack("CCa#{size}x") end |
Instance Method Details
#serialize ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/simatic/types/s7_string.rb', line 17 def serialize if @value.kind_of? Array @value.map { |single_val| self.class.serialize single_val, @size } else self.class.serialize @value, @size end end |