Class: Pigpio::Serial

Inherits:
Object
  • Object
show all
Defined in:
lib/pigpio/serial.rb

Constant Summary collapse

TTY =
%w[/dev/tty /dev/serial]
Baud =
[50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pi, ser_tty, baud) ⇒ Serial

Returns a new instance of Serial.



6
7
8
9
# File 'lib/pigpio/serial.rb', line 6

def initialize(pi, ser_tty, baud)
  @pi = pi
  @handle = IF.serial_open(pi, ser_tty, baud = 19200, 0)
end

Instance Attribute Details

#handleObject (readonly)

Returns the value of attribute handle.



3
4
5
# File 'lib/pigpio/serial.rb', line 3

def handle
  @handle
end

#piObject (readonly)

Returns the value of attribute pi.



3
4
5
# File 'lib/pigpio/serial.rb', line 3

def pi
  @pi
end

Instance Method Details

#byteObject



19
20
21
# File 'lib/pigpio/serial.rb', line 19

def byte
  IF.serial_read_byte(@pi, @handle)
end

#byte=(bVal) ⇒ Object



15
16
17
# File 'lib/pigpio/serial.rb', line 15

def byte=(bVal)
  IF.serial_write_byte(@pi, @handle, bVal)
end

#closeObject



11
12
13
# File 'lib/pigpio/serial.rb', line 11

def close
  IF.serial_close(@pi, @handle)
end

#read(count) ⇒ Object



27
28
29
# File 'lib/pigpio/serial.rb', line 27

def read(count)
  IF.serial_read(@pi, @handle, count)
end

#sizeObject



31
32
33
# File 'lib/pigpio/serial.rb', line 31

def size
  IF.serial_data_available(@pi, @handle)
end

#write(buf) ⇒ Object



23
24
25
# File 'lib/pigpio/serial.rb', line 23

def write(buf)
  IF.serial_write(@pi, @handle, buf)
end