modem_check2.rb

Path: examples/modem_check2.rb
Last Update: Wed Apr 17 05:12:18 +0000 2013

Required files

fcntl   termios  

Methods

Constants

DEVICE = '/dev/modem'
BAUDRATE = Termios::B115200

Public Instance methods

[Source]

    # File examples/modem_check2.rb, line 7
 7: def dev_open(path)
 8:   dev = open(DEVICE, File::RDWR | File::NONBLOCK)
 9:   mode = dev.fcntl(Fcntl::F_GETFL, 0)
10:   dev.fcntl(Fcntl::F_SETFL, mode & ~File::NONBLOCK)
11:   dev
12: end

[Source]

    # File examples/modem_check2.rb, line 14
14: def dump_termios(tio, banner)
15:   puts banner
16:   puts "  ispeed = #{Termios::BAUDS[tio.ispeed]}, ospeed = #{Termios::BAUDS[tio.ospeed]}"
17:   ["iflag", "oflag", "cflag", "lflag"].each do |x|
18:     flag = tio.send(x)
19:     flags = []
20:     eval("Termios::#{x.upcase}S").each do |f, sym|
21:       flags << sym.to_s if flag & f != 0
22:     end
23:     puts "   #{x} = #{flags.sort.join(' | ')}"
24:   end
25:   print "      cc ="
26:   cc = tio.cc
27:   cc.each_with_index do |x, idx|
28:     print " #{Termios::CCINDEX[idx]}=#{x}" if Termios::CCINDEX.include?(idx)
29:   end
30:   puts
31: end

[Validate]