Module: FANUC::Ekg
- Defined in:
- lib/fanuc-ekg.rb
Defined Under Namespace
Constant Summary collapse
- LIBPATH =
:stopdoc:
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
- PARSER =
FasterCSV
Class Method Summary collapse
-
.libpath(*args, &block) ⇒ Object
Returns the library path for the module.
- .parse(file) ⇒ Object
-
.path(*args, &block) ⇒ Object
Returns the lpath for the module.
-
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in.
- .split(string) ⇒ Object
-
.version ⇒ Object
Returns the version string for the library.
Class Method Details
.libpath(*args, &block) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fanuc-ekg.rb', line 19 def self.libpath( *args, &block ) rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) if block begin $LOAD_PATH.unshift LIBPATH rv = block.call ensure $LOAD_PATH.shift end end return rv end |
.parse(file) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/fanuc-ekg.rb', line 184 def parse(file) @ekg_data = FANUC::Ekg::EkgData.new f = open(file).read output = split(f) # split the output into 3 usable CSV sections # parse bins PARSER.parse(output[:bins],:headers=>"Group,Bin0,BinV1T1,BinV2T1,BinV1T2,BinV2T2") do |line| @ekg_data.bins[:zero].collision_counts << line['Bin0'].to_i @ekg_data.bins[:v1t1].collision_counts << line['BinV1T1'].to_i @ekg_data.bins[:v2t1].collision_counts << line['BinV2T1'].to_i @ekg_data.bins[:v1t2].collision_counts << line['BinV1T2'].to_i @ekg_data.bins[:v2t2].collision_counts << line['BinV2T2'].to_i end # parse recent alarms PARSER.parse(output[:recent],:headers => "MRA_Num,DateTime,ErrorText,Safety I/O,Vel J1\[%\],Vel J2\[%\],Vel J3\[%\],Vel J4\[%\],Vel J5\[%\],Vel J6\[%\],Vel J7\[%\],Vel J8\[%\],Torq J1\[%\],Torq J2\[%\],Torq J3\[%\],Torq J4\[%\],Torq J5\[%\],Torq J6\[%\],Torq J7\[%\],Torq J8\[%\],Angle J1\[rad\],Angle J2\[rad\],Angle J3\[rad\],Angle J4\[rad\],Angle J5\[rad\],Angle J6\[rad\],Angle J7\[rad\],Angle J8\[rad\],DistTorq J1\[%\],DistTorq J2\[%\],DistTorq J3\[%\],DistTorq J4\[%\],DistTorq J5\[%\],DistTorq J6\[%\],DistTorq J7\[%\],DistTorq J8\[%\]") do |line| @ekg_data.alarms[:recent] << Ekg::Alarm.new(line.to_hash) end # parse worst disturbances PARSER.parse(output[:worst],:headers=>"Num,DateTime,ErrorText,Safety I/O,Vel J1\[%\],Vel J2\[%\],Vel J3\[%\],Vel J4\[%\],Vel J5\[%\],Vel J6\[%\],Vel J7\[%\],Vel J8\[%\],Torq J1\[%\],Torq J2\[%\],Torq J3\[%\],Torq J4\[%\],Torq J5\[%\],Torq J6\[%\],Torq J7\[%\],Torq J8\[%\],Angle J1\[rad\],Angle J2\[rad\],Angle J3\[rad\],Angle J4\[rad\],Angle J5\[rad\],Angle J6\[rad\],Angle J7\[rad\],Angle J8\[rad\],DistTorq J1\[%\],DistTorq J2\[%\],DistTorq J3\[%\],DistTorq J4\[%\],DistTorq J5\[%\],DistTorq J6\[%\],DistTorq J7\[%\],DistTorq J8\[%\]") do |line| @ekg_data.alarms[:worst] << Ekg::Alarm.new(line.to_hash) end @ekg_data end |
.path(*args, &block) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fanuc-ekg.rb', line 36 def self.path( *args, &block ) rv = args.empty? ? PATH : ::File.join(PATH, args.flatten) if block begin $LOAD_PATH.unshift PATH rv = block.call ensure $LOAD_PATH.shift end end return rv end |
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.
54 55 56 57 58 59 60 |
# File 'lib/fanuc-ekg.rb', line 54 def self.require_all_libs_relative_to( fname, dir = nil ) dir ||= ::File.basename(fname, '.*') search_me = ::File.( ::File.join(::File.dirname(fname), dir, '**', '*.rb')) Dir.glob(search_me).sort.each {|rb| require rb} end |
.split(string) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/fanuc-ekg.rb', line 159 def split(string) @output = {} @str = "" string.each_line do |line| next if line =~ /Severity(\r)?\n/ next if line =~ /Group,Bin0,BinV1T1,BinV2T1,BinV1T2,BinV2T2(\r)?\n/ next if line =~ /MRA_Num,DateTime,ErrorText,Safety I\/O,Vel J1\[%\],Vel J2\[%\],Vel J3\[%\],Vel J4\[%\],Vel J5\[%\],Vel J6\[%\],Vel J7\[%\],Vel J8\[%\],Torq J1\[%\],Torq J2\[%\],Torq J3\[%\],Torq J4\[%\],Torq J5\[%\],Torq J6\[%\],Torq J7\[%\],Torq J8\[%\],Angle J1\[rad\],Angle J2\[rad\],Angle J3\[rad\],Angle J4\[rad\],Angle J5\[rad\],Angle J6\[rad\],Angle J7\[rad\],Angle J8\[rad\],DistTorq J1\[%\],DistTorq J2\[%\],DistTorq J3\[%\],DistTorq J4\[%\],DistTorq J5\[%\],DistTorq J6\[%\],DistTorq J7\[%\],DistTorq J8\[%\](\r)?\n/ next if line =~ /Num,DateTime,ErrorText,Safety I\/O,Vel J1\[%\],Vel J2\[%\],Vel J3\[%\],Vel J4\[%\],Vel J5\[%\],Vel J6\[%\],Vel J7\[%\],Vel J8\[%\],Torq J1\[%\],Torq J2\[%\],Torq J3\[%\],Torq J4\[%\],Torq J5\[%\],Torq J6\[%\],Torq J7\[%\],Torq J8\[%\],Angle J1\[rad\],Angle J2\[rad\],Angle J3\[rad\],Angle J4\[rad\],Angle J5\[rad\],Angle J6\[rad\],Angle J7\[rad\],Angle J8\[rad\],DistTorq J1\[%\],DistTorq J2\[%\],DistTorq J3\[%\],DistTorq J4\[%\],DistTorq J5\[%\],DistTorq J6\[%\],DistTorq J7\[%\],DistTorq J8\[%\](\r)?\n/ if line =~ /Most Recent Alarms\(MRA\) for Group 1(\r)?\n/ @output[:bins] = @str @str = "" next end if line =~ /Worst Disturbance Alarms for Group 1(\r)?\n/ @output[:recent] = @str @str = "" next end @str += line end @output[:worst] = @str return @output end |
.version ⇒ Object
Returns the version string for the library.
11 12 13 |
# File 'lib/fanuc-ekg.rb', line 11 def self.version @version ||= File.read(path('version.txt')).strip end |