2015년 11월 25일 수요일

Simple Example Socket Code for Lua (Linux)

TIME = {}
DATA = {}
ETX_CHAR = "\r\n\r\n"
COMMAND = "*IDN?" .. ETX_CHAR
local socket = require("socket")
SMU = socket.connect("192.168.0.21", 5025)
SMU:send(COMMAND)
packet = ""
while true do
  recv  = SMU:receive(1)
  if recv == "\n" then
    break
  end
  packet = packet .. recv
end
print(packet)
COMMAND = "smua.measure.delayfactor = 0.1" .. ETX_CHAR
SMU:send(COMMAND)
COMMAND = "smua.source.output = 1" .. ETX_CHAR
SMU:send(COMMAND)
for i = 1, 100, 1 do
  t1 = socket.gettime()
  COMMAND = "print(smua.measure.i())" .. ETX_CHAR
  SMU:send(COMMAND)
  packet = ""
  while true do
    recv = SMU:receive(1)
    if recv == "\n" then
      break
    end
    packet = packet .. recv
  end
  t2 = socket.gettime()
  TIME[i] = t2 - t1
  DATA[i] = packet
end
COMMAND = "smua.source.output = 0" .. ETX_CHAR
SMU:send(COMMAND)
for i = 1, 100, 1 do
  print("TIME : " .. TIME[i] .. " , " .. "CURRENT : " .. DATA[i])
end

SMU:close()

댓글 없음:

댓글 쓰기

네티켓 아시져 -ㅁ-?