#!/usr/bin/ruby

require "socket"
require "./cgi-bin/implementation"
require "./cgi-bin/activetem"

class SetTem

  def initialize(activetem)
	@@tem = activetem
	#get TEM_Instrument info
	@@host = $tem["#{activetem}"]["host"]
	@@port = $tem["#{activetem}"]["port"]

	#set TEM_instrument info
	tem = File.open("./cgi-bin/activetem.rb","w")
	tem.write "$activehost = '#{@@host}'\n$activeport = '#{@@port}'\n"

	tem.close

  end

  def connect

	log = File.open("./File/log.txt","a")
	socket = TCPSocket.open($activehost,$activeport)
	control={"Command"=>"Connect","Parameter"=>@@tem}
	controlj=control.to_json
	socket.puts controlj
	puts controlj
	socket.flush

	output = socket.gets
	log.write output

	log.close
	socket.close

	return output

  end

end

