class Net::PNS
Constants
- KEYS
command keys: :red, :yellow, :green, :blue, :white, :buzzer command values (colors): :off, :on, :blink1, :blink2, :keep (default) command values (buzzer): :off, :buzz1, :buzz2, :buzz3, :buzz4, :keep (default)
- PATTERN
- VALUES
- VERSION
Public Class Methods
new(host, port = 10000, type = 'XX') { |self| ... }
click to toggle source
# File lib/net/pns.rb, line 9 def initialize(host, port = 10000, type = 'XX') @socket = TCPSocket.new(host, port) @type = type.unpack('CC') if block_given? begin yield self ensure close end end end
Public Instance Methods
clear()
click to toggle source
# File lib/net/pns.rb, line 49 def clear send('C', [], 1) end
close()
click to toggle source
# File lib/net/pns.rb, line 53 def close @socket.close @socket = nil end
light(command)
click to toggle source
# File lib/net/pns.rb, line 33 def light(command) cmd = KEYS.map{|c| [c, VALUES[command[c]] || 9]}.to_h.values ret = send('S', cmd, 1).ord raise LightError.new("code 0x#{ret.to_s(16).rjust(2, '0')}") unless ret == 0x06 end
play_sound(ch, pattern = :play, repeat = 0)
click to toggle source
# File lib/net/pns.rb, line 44 def play_sound(ch, pattern = :play, repeat = 0) ret = send('V', [PATTERN[pattern] || 1, repeat, 0, ch], 1).ord raise PlayError.new("code 0x#{ret.to_s(16).rjust(2, '0')}") unless ret == 0x06 end
stat()
click to toggle source
# File lib/net/pns.rb, line 39 def stat return send('G', [], 6).unpack('C*') end
Private Instance Methods
send(symbol, command, receive_size)
click to toggle source
# File lib/net/pns.rb, line 59 def send(symbol, command, receive_size) packet = @type + symbol.unpack('C') packet << 0 packet << command.size packet += command @socket.write packet.pack('CCCCnC*') return @socket.read(receive_size) end