Class: NetLinx::System
- Inherits:
-
Object
- Object
- NetLinx::System
- Defined in:
- lib/netlinx/workspace/system.rb
Overview
A collection of resources loaded onto a NetLinx master. Workspace -> Project -> System
Instance Attribute Summary collapse
-
#active ⇒ Object
Returns the value of attribute active.
-
#baud_rate ⇒ Object
Returns the value of attribute baud_rate.
-
#com_port ⇒ Object
Returns the value of attribute com_port.
-
#data_bits ⇒ Object
Returns the value of attribute data_bits.
-
#description ⇒ Object
Returns the value of attribute description.
-
#ensure_availability ⇒ Object
Returns the value of attribute ensure_availability.
-
#files ⇒ Object
Returns the value of attribute files.
-
#flow_control ⇒ Object
Returns the value of attribute flow_control.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#ip_port ⇒ Object
Returns the value of attribute ip_port.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parity ⇒ Object
Returns the value of attribute parity.
-
#project ⇒ Object
A reference to the system's parent project.
-
#stop_bits ⇒ Object
Returns the value of attribute stop_bits.
Instance Method Summary collapse
-
#<<(file) ⇒ Object
Alias to add a file.
-
#compile ⇒ Object
Compile this system.
- #compiler_include_paths ⇒ Object
- #compiler_library_paths ⇒ Object
- #compiler_module_paths ⇒ Object
- #compiler_target_files ⇒ Object
-
#include?(file) ⇒ Boolean
True if the project contains the specified file.
-
#initialize(**kwargs) ⇒ System
constructor
A new instance of System.
-
#to_s ⇒ Object
The system name.
-
#to_xml_element ⇒ REXML::Element
An XML element representing this system.
Constructor Details
#initialize(**kwargs) ⇒ System
Returns a new instance of System
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/netlinx/workspace/system.rb', line 49 def initialize **kwargs @project = kwargs.fetch :project, nil @name = kwargs.fetch :name, '' @id = kwargs.fetch :id, 0 @active = kwargs.fetch :active, false @description = kwargs.fetch :description, '' @ip_address = kwargs.fetch :ip_address, '0.0.0.0' @ip_port = kwargs.fetch :ip_port, 1319 @ensure_availability = kwargs.fetch :ensure_availability, true @com_port = kwargs.fetch :com_port, :com1 @baud_rate = kwargs.fetch :baud_rate, 38400 @data_bits = kwargs.fetch :data_bits, 8 @parity = kwargs.fetch :parity, :none @stop_bits = kwargs.fetch :stop_bits, 1 @flow_control = kwargs.fetch :flow_control, :none @files = [] @compiler_target_files = [] @compiler_include_paths = [] @compiler_module_paths = [] @compiler_library_paths = [] system_element = kwargs.fetch :element, nil parse_xml_element system_element if system_element end |
Instance Attribute Details
#active ⇒ Object
Returns the value of attribute active
13 14 15 |
# File 'lib/netlinx/workspace/system.rb', line 13 def active @active end |
#baud_rate ⇒ Object
Returns the value of attribute baud_rate
22 23 24 |
# File 'lib/netlinx/workspace/system.rb', line 22 def baud_rate @baud_rate end |
#com_port ⇒ Object
Returns the value of attribute com_port
21 22 23 |
# File 'lib/netlinx/workspace/system.rb', line 21 def com_port @com_port end |
#data_bits ⇒ Object
Returns the value of attribute data_bits
23 24 25 |
# File 'lib/netlinx/workspace/system.rb', line 23 def data_bits @data_bits end |
#description ⇒ Object
Returns the value of attribute description
15 16 17 |
# File 'lib/netlinx/workspace/system.rb', line 15 def description @description end |
#ensure_availability ⇒ Object
Returns the value of attribute ensure_availability
19 20 21 |
# File 'lib/netlinx/workspace/system.rb', line 19 def ensure_availability @ensure_availability end |
#files ⇒ Object
Returns the value of attribute files
10 11 12 |
# File 'lib/netlinx/workspace/system.rb', line 10 def files @files end |
#flow_control ⇒ Object
Returns the value of attribute flow_control
26 27 28 |
# File 'lib/netlinx/workspace/system.rb', line 26 def flow_control @flow_control end |
#id ⇒ Object
Returns the value of attribute id
14 15 16 |
# File 'lib/netlinx/workspace/system.rb', line 14 def id @id end |
#ip_address ⇒ Object
Returns the value of attribute ip_address
17 18 19 |
# File 'lib/netlinx/workspace/system.rb', line 17 def ip_address @ip_address end |
#ip_port ⇒ Object
Returns the value of attribute ip_port
18 19 20 |
# File 'lib/netlinx/workspace/system.rb', line 18 def ip_port @ip_port end |
#name ⇒ Object
Returns the value of attribute name
12 13 14 |
# File 'lib/netlinx/workspace/system.rb', line 12 def name @name end |
#parity ⇒ Object
Returns the value of attribute parity
24 25 26 |
# File 'lib/netlinx/workspace/system.rb', line 24 def parity @parity end |
#project ⇒ Object
A reference to the system's parent project.
9 10 11 |
# File 'lib/netlinx/workspace/system.rb', line 9 def project @project end |
#stop_bits ⇒ Object
Returns the value of attribute stop_bits
25 26 27 |
# File 'lib/netlinx/workspace/system.rb', line 25 def stop_bits @stop_bits end |
Instance Method Details
#<<(file) ⇒ Object
Alias to add a file.
80 81 82 83 |
# File 'lib/netlinx/workspace/system.rb', line 80 def << file @files << file file.system = self end |
#compile ⇒ Object
Compile this system.
180 181 182 183 184 185 186 |
# File 'lib/netlinx/workspace/system.rb', line 180 def compile # The compiler dependency is only needed if this method is called. require 'netlinx/compiler' compiler = NetLinx::Compiler.new compiler.compile self end |
#compiler_include_paths ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/netlinx/workspace/system.rb', line 137 def compiler_include_paths @files .select {|f| f.type == :include} .map {|f| File. \ File.dirname(f.path.gsub('\\', '/')), f.system.project.workspace.path }.uniq end |
#compiler_library_paths ⇒ Object
157 158 159 |
# File 'lib/netlinx/workspace/system.rb', line 157 def compiler_library_paths [] end |
#compiler_module_paths ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'lib/netlinx/workspace/system.rb', line 147 def compiler_module_paths @files .select {|f| f.type == :module || f.type == :tko || f.type == :duet} .map {|f| File. \ File.dirname(f.path.gsub('\\', '/')), f.system.project.workspace.path }.uniq end |
#compiler_target_files ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'lib/netlinx/workspace/system.rb', line 127 def compiler_target_files @files .select {|f| f.type == :master} .map {|f| File. \ f.path.gsub('\\', '/'), f.system.project.workspace.path }.uniq end |
#include?(file) ⇒ Boolean
Returns true if the project contains the specified file.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/netlinx/workspace/system.rb', line 162 def include? file included = false @files.each do |f| name_included = f.name.downcase.eql? file.downcase # TODO: This should probably be relative to the workspace path, # which can be found by traversing @project, @workspace. path_included = file.gsub(/\\/, '/').include? f.path.gsub(/\\/, '/') included = name_included || path_included break if included end included end |
#to_s ⇒ Object
Returns the system name.
86 87 88 |
# File 'lib/netlinx/workspace/system.rb', line 86 def to_s @name end |
#to_xml_element ⇒ REXML::Element
Returns an XML element representing this system.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/netlinx/workspace/system.rb', line 91 def to_xml_element REXML::Element.new('System').tap do |system| system.attributes['IsActive'] = active system.attributes['Platform'] = 'Netlinx' transport = (ip_address == '0.0.0.0') ? 'Serial' : 'TCPIP' system.attributes['Transport'] = transport system.attributes['TransportEx'] = transport system.add_element('Identifier').tap { |e| e.text = name } system.add_element('SysID').tap { |e| e.text = id } system.add_element('Comments').tap { |e| e.text = description } # These don't seem to change in NetLinx Studio 4.0; possibly 3.x legacy. # The 'Ex' suffixes are used. system.add_element('TransTCPIP').tap { |e| e.text = "#{ip_address},#{ip_port},#{ensure_availability ? 1 : 0},,," } system.add_element('TransSerial').tap { |e| e.text = "#{com_port.upcase},#{baud_rate},#{data_bits},#{parity.capitalize},#{stop_bits},,," } # TODO: Generate communication settings. system.add_element('TransTCPIPEx').tap { |e| e.text = "#{ip_address}|#{ip_port}|#{ensure_availability ? 1 : 0}|||" } system.add_element('TransSerialEx').tap { |e| e.text = "#{com_port.upcase}|#{baud_rate}|#{data_bits}|#{parity.capitalize}|#{stop_bits}|||" } system.add_element('TransUSBEx').tap { |e| e.text = '|||||' } system.add_element('TransVNMEx').tap { |e| e.text = '||' } system.add_element('UserName').tap { |e| e.text = '' } system.add_element('Password').tap { |e| e.text = '' } @files.each { |file| system << file.to_xml_element } end end |