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

- old
+ new

@@ -48,9 +48,24 @@ raise RubySerial::Exception, RubySerial::Win32::ERROR_CODES[FFI.errno] end buff.get_bytes(0, count.read_string.unpack('H4').join().to_i(16)) end + def getbyte + buff = FFI::MemoryPointer.new :char, 1 + count = FFI::MemoryPointer.new :uint32, 1 + err = RubySerial::Win32.ReadFile(@fd, buff, size, count, nil) + if err == 0 + raise RubySerial::Exception, RubySerial::Win32::ERROR_CODES[FFI.errno] + end + + if count.read_string.unpack('H4').join().to_i(16) == 0 + nil + else + buff.read_string.unpack('C').first + end + end + def write(data) buff = FFI::MemoryPointer.from_string(data.to_s) count = FFI::MemoryPointer.new :uint32, 1 err = RubySerial::Win32.WriteFile(@fd, buff, buff.size, count, nil) if err == 0