OSDN Git Service

Changes to be committed:
[vem/WITs.git] / tsurutafile / cgi-bin / settem.rb
1 #!/usr/bin/ruby
2
3 require "socket"
4 require "./cgi-bin/implementation"
5 require "./cgi-bin/activetem"
6
7 class SetTem
8
9   def initialize(activetem)
10         @@tem = activetem
11         #get TEM_Instrument info
12         @@host = $tem["#{activetem}"]["host"]
13         @@port = $tem["#{activetem}"]["port"]
14
15         #set TEM_instrument info
16         tem = File.open("./cgi-bin/activetem.rb","w")
17         tem.write "$activehost = '#{@@host}'\n$activeport = '#{@@port}'\n"
18
19         tem.close
20
21   end
22
23   def connect
24
25         log = File.open("./File/log.txt","a")
26         socket = TCPSocket.open($activehost,$activeport)
27         control={"Command"=>"Connect","Parameter"=>@@tem}
28         controlj=control.to_json
29         socket.puts controlj
30         puts controlj
31         socket.flush
32
33         output = socket.gets
34         log.write output
35
36         log.close
37         socket.close
38
39         return output
40
41   end
42
43 end
44