lib/rubyserial/posix.rb in rubyserial-0.0.1 vs lib/rubyserial/posix.rb in rubyserial-0.1.0

- old
+ new

@@ -62,9 +62,23 @@ raise RubySerial::Exception, RubySerial::Posix::ERROR_CODES[FFI.errno] end buff.get_bytes(0, i) end + def getbyte + buff = FFI::MemoryPointer.new :char, 1 + i = RubySerial::Posix.read(@fd, buff, 1) + if i == -1 + raise RubySerial::Exception, RubySerial::Posix::ERROR_CODES[FFI.errno] + end + + if i == 0 + nil + else + buff.read_string.unpack('C').first + end + end + private def build_config(baude_rate, data_bits) config = RubySerial::Posix::Termios.new \ No newline at end of file