Class: Rpremote::Serial
- Inherits:
-
Object
show all
- Defined in:
- lib/rpremote/serial.rb,
sig/rpremote.rbs
Defined Under Namespace
Classes: ConfigurationError
Constant Summary
collapse
- BAUD_RATE =
115_200
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path, baud: BAUD_RATE) ⇒ Serial
Returns a new instance of Serial.
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/rpremote/serial.rb', line 24
def initialize(path, baud: BAUD_RATE)
@path = path
@baud = Integer(baud)
configure!
@io = File.open(path, File::RDWR)
@io.binmode
@io.sync = true
rescue SystemCallError => e
raise ConfigurationError, "cannot open serial port #{path}: #{e.message}"
end
|
Instance Attribute Details
#baud ⇒ Integer
Returns the value of attribute baud.
22
23
24
|
# File 'lib/rpremote/serial.rb', line 22
def baud
@baud
end
|
#io ⇒ File
Returns the value of attribute io.
22
23
24
|
# File 'lib/rpremote/serial.rb', line 22
def io
@io
end
|
#path ⇒ String
Returns the value of attribute path.
22
23
24
|
# File 'lib/rpremote/serial.rb', line 22
def path
@path
end
|
Class Method Details
.open ⇒ void
.open(path, baud:) ⇒ Serial
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/rpremote/serial.rb', line 11
def self.open(path, baud: BAUD_RATE)
port = new(path, baud: baud)
return port unless block_given?
begin
yield port
ensure
port.close
end
end
|
Instance Method Details
#close ⇒ Object
47
48
49
|
# File 'lib/rpremote/serial.rb', line 47
def close
io.close unless io.closed?
end
|
#closed? ⇒ Boolean
51
52
53
|
# File 'lib/rpremote/serial.rb', line 51
def closed?
io.closed?
end
|
#flush ⇒ Object
43
44
45
|
# File 'lib/rpremote/serial.rb', line 43
def flush
io.flush
end
|
#read_nonblock(length) ⇒ String
35
36
37
|
# File 'lib/rpremote/serial.rb', line 35
def read_nonblock(length)
io.read_nonblock(length)
end
|
#to_io ⇒ File
55
56
57
|
# File 'lib/rpremote/serial.rb', line 55
def to_io
io
end
|
#write(data) ⇒ Integer
39
40
41
|
# File 'lib/rpremote/serial.rb', line 39
def write(data)
io.write(data)
end
|