#!/usr/bin/ruby system "stty 19200 raw -crtscts cs7 -echo < /dev/com1" rs232c = open("/dev/com1", "r") def hoge(x) printf "%x %x %x %x %x\n", x[0], x[1], x[2], x[3], x[4] end def hoge2(x) x[0, 127].each {|y| z = y + 64 print z.chr } print "\n" end c = Array.new loop { IO.select([rs232c], nil, nil, 5) or raise("Timeout occurred."); x = rs232c.getc c.push(x) if(x > 0x6f) if(c.length == 1) c.clear elsif(c.length == 5) hoge(c[0, 4]) c.clear elsif(c.length == 134) hoge2(c[0, 133]) c.clear elsif(c.length == 138) hoge(c[0, 4]) hoge2(c[4, 133]) c.clear else print "====protocol error====\n" c.clear end end }