class UR::Psi
Public Class Methods
new(host, logger=Logger.new(STDOUT,level: :INFO))
click to toggle source
# File lib/psi.rb, line 18 def initialize(host, logger=Logger.new(STDOUT,level: :INFO)) host = '//' + host if host !~ /\/\// uri = URI::parse(host) @logger = logger @hostname = uri.host @port = uri.port.nil? ? 30003 : uri.port @conn_state = ConnectionState::DISCONNECTED @sock = nil end
Public Instance Methods
connect()
click to toggle source
# File lib/psi.rb, line 28 def connect return if @sock @sock = Socket.new Socket::AF_INET, Socket::SOCK_STREAM @sock.setsockopt Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1 @sock = TCPSocket.new(@hostname, @port) @conn_state = ConnectionState::CONNECTED self end
connected?()
click to toggle source
# File lib/psi.rb, line 37 def connected? @conn_state != ConnectionState::DISCONNECTED end
disconnect()
click to toggle source
# File lib/psi.rb, line 41 def disconnect if @sock @sock.close @sock = nil @conn_state = ConnectionState::DISCONNECTED @logger.info 'Connection closed ' + @hostname + ':' + @port.to_s end end
execute_ur_script(str)
click to toggle source
# File lib/psi.rb, line 65 def execute_ur_script(str) @logger.info 'Executing UR Script ...' begin @sock.write(str) line = @sock.gets.strip @logger.debug line rescue => e raise UR::Psi::Reconnect.new('UR Script can not be got. PSI server down or not in Remote Mode') end end
execute_ur_script_file(filename)
click to toggle source
# File lib/psi.rb, line 50 def execute_ur_script_file(filename) @logger.info 'Executing UR Script File: ' + filename begin File.open(filename) do |file| while not file.eof? @sock.write(file.readline) line = @sock.gets.strip @logger.debug line end end rescue => e raise UR::Psi::Reconnect.new('UR Script can not be got. PSI server down or not in Remote Mode') end end