def sendreceive(msg="", opts={})
timeout = opts.fetch(:timeout, 40)
wait_for_null = opts.fetch(:wait_for_null, true)
isRetrying = false
begin
if @connected
send(msg)
reply = receive(opts)
if (reply.index("Connection Timeout.") == 0)
raise "Broken pipe"
end
return reply
else
raise "Not connected to reader."
end
rescue
err = "Error in alienconnection:\nTried to send:\"#{msg}\"\nand got:\n\"" + $! +"\""
if (!isRetrying && $!.to_s == "Broken pipe")
isRetrying = true
openConnection()
retry
else
err = "Tried to send: \"#{msg}\"\nand got: \"#{$!}\""
raise err
end
end
end