Class: SerialPort
- Inherits:
-
IO
- Object
- IO
- SerialPort
- Defined in:
- lib/serialport.rb,
ext/serialport.c
Constant Summary collapse
- NONE =
INT2FIX(NONE)
- HARD =
INT2FIX(HARD)
- SOFT =
INT2FIX(SOFT)
- SPACE =
INT2FIX(SPACE)
- MARK =
INT2FIX(MARK)
- EVEN =
INT2FIX(EVEN)
- ODD =
INT2FIX(ODD)
- VERSION =
the package’s version as a string “X.Y.Z”, beeing major, minor and patch level
rb_str_new2(RUBY_SERIAL_PORT_VERSION)
Class Method Summary collapse
-
.create ⇒ Object
:nodoc: This method is privat and will be called by SerialPort#new or SerialPort#open.
-
.new(port, *params) ⇒ Object
Creates a serial port object.
-
.open(port, *params) ⇒ Object
This behaves like SerialPort#new, except that you can pass a block to which the new serial port object will be passed.
Instance Method Summary collapse
-
#baud ⇒ Object
Get the current baud rate, see SerialPort#get_modem_params for details.
-
#baud= ⇒ Object
Set the baud rate, see SerialPort#set_modem_params for details.
-
#break ⇒ Object
Send a break for the given time.
-
#cts ⇒ Object
Get the state (0 or 1) of the CTS line.
-
#data_bits ⇒ Object
Get the current data bits, see SerialPort#get_modem_params for details.
-
#data_bits= ⇒ Object
Set the data bits, see SerialPort#set_modem_params for details.
-
#dcd ⇒ Object
Get the state (0 or 1) of the DCD line.
-
#dsr ⇒ Object
Get the state (0 or 1) of the DSR line.
-
#dtr ⇒ Object
Get the state (0 or 1) of the DTR line (not available on Windows).
- #dtr=() ⇒ Object
-
#flow_control ⇒ Object
Get the flow control.
- #flow_control=() ⇒ Object
-
#get_modem_params ⇒ Object
Get the configure of the serial port.
-
#get_signals ⇒ Object
Return a hash with the state of each line status bit.
-
#modem_params ⇒ Object
Get the configure of the serial port.
-
#modem_params= ⇒ Object
Configure the serial port.
-
#parity ⇒ Object
Get the current parity, see SerialPort#get_modem_params for details.
-
#parity= ⇒ Object
Set the parity, see SerialPort#set_modem_params for details.
-
#read_timeout ⇒ Object
Get the timeout value (in milliseconds) for reading.
- #read_timeout=() ⇒ Object
-
#ri ⇒ Object
Get the state (0 or 1) of the RI line.
-
#rts ⇒ Object
Get the state (0 or 1) of the RTS line (not available on Windows).
- #rts=() ⇒ Object
-
#set_modem_params ⇒ Object
Configure the serial port.
-
#signals ⇒ Object
Return a hash with the state of each line status bit.
-
#stop_bits ⇒ Object
Get the current stop bits, see SerialPort#get_modem_params for details.
-
#stop_bits= ⇒ Object
Set the stop bits, see SerialPort#set_modem_params for details.
-
#write_timeout ⇒ Object
Get the write timeout (in milliseconds).
- #write_timeout=() ⇒ Object
Class Method Details
.create ⇒ Object
:nodoc: This method is privat and will be called by SerialPort#new or SerialPort#open.
34 35 |
# File 'ext/serialport.c', line 34
static VALUE sp_create(class, _port)
VALUE class, _port;
|
.new(port, *params) ⇒ Object
Creates a serial port object.
port
may be a port number or the file name of a defice. The number is portable; so 0 is mapped to “COM1” on Windows, “/dev/ttyS0” on Linux, “/dev/cuaa0” on Mac OS X, etc.
params
can be used to configure the serial port. See SerialPort#set_modem_params for details
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/serialport.rb', line 15 def SerialPort::new(port, *params) sp = create(port) begin sp.set_modem_params(*params) rescue sp.close raise end return sp end |
.open(port, *params) ⇒ Object
This behaves like SerialPort#new, except that you can pass a block to which the new serial port object will be passed. In this case the connection is automaticaly closed when the block has finished.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/serialport.rb', line 29 def SerialPort::open(port, *params) sp = create(port) begin sp.set_modem_params(*params) if (block_given?) yield sp sp.close return nil end rescue sp.close raise end return sp end |
Instance Method Details
#baud ⇒ Object
Get the current baud rate, see SerialPort#get_modem_params for details.
248 249 |
# File 'ext/serialport.c', line 248 static VALUE sp_get_data_rate(self) VALUE self; |
#baud= ⇒ Object
Set the baud rate, see SerialPort#set_modem_params for details.
188 189 |
# File 'ext/serialport.c', line 188 static VALUE sp_set_data_rate(self, data_rate) VALUE self, data_rate; |
#break ⇒ Object
Send a break for the given time.
time
is an integer of tenths-of-a-second for the break.
Note: Under Posix, this value is very approximate.
71 72 |
# File 'ext/serialport.c', line 71 static VALUE sp_break(self, time) VALUE self, time; |
#cts ⇒ Object
Get the state (0 or 1) of the CTS line
328 329 |
# File 'ext/serialport.c', line 328 static VALUE sp_get_cts(self) VALUE self; |
#data_bits ⇒ Object
Get the current data bits, see SerialPort#get_modem_params for details.
261 262 |
# File 'ext/serialport.c', line 261 static VALUE sp_get_data_bits(self) VALUE self; |
#data_bits= ⇒ Object
Set the data bits, see SerialPort#set_modem_params for details.
203 204 |
# File 'ext/serialport.c', line 203 static VALUE sp_set_data_bits(self, data_bits) VALUE self, data_bits; |
#dcd ⇒ Object
Get the state (0 or 1) of the DCD line
354 355 |
# File 'ext/serialport.c', line 354 static VALUE sp_get_dcd(self) VALUE self; |
#dsr ⇒ Object
Get the state (0 or 1) of the DSR line
341 342 |
# File 'ext/serialport.c', line 341 static VALUE sp_get_dsr(self) VALUE self; |
#dtr ⇒ Object
Get the state (0 or 1) of the DTR line (not available on Windows)
80 81 |
# File 'ext/serialport.c', line 80 static VALUE sp_get_dtr(self) VALUE self; |
#dtr=() ⇒ Object
128 129 130 131 |
# File 'ext/serialport.c', line 128
static VALUE sp_set_dtr(self, val)
{
return sp_set_dtr_impl(self, val);
}
|
#flow_control ⇒ Object
Get the flow control. The result is either NONE, HARD, SOFT or (HARD | SOFT)
89 90 |
# File 'ext/serialport.c', line 89 static VALUE sp_get_flow_control(self) VALUE self; |
#flow_control=() ⇒ Object
140 141 142 143 |
# File 'ext/serialport.c', line 140
static VALUE sp_set_flow_control(self, val)
{
return sp_set_flow_control_impl(self, val);
}
|
#get_modem_params ⇒ Object
Get the configure of the serial port.
Returned is a hash with the following keys:
- “baud”
-
Integer with the baud rate
- “data_bits”
-
Integer from 5 to 8 (4 is possible on Windows too)
- “stop_bits”
-
Integer, 1 or 2 (1.5 is not supported)
- “parity”
-
One of the constants NONE, EVEN or ODD (on Windows may also MARK or SPACE)
307 308 |
# File 'ext/serialport.c', line 307 static VALUE sp_get_modem_params(self) VALUE self; |
#get_signals ⇒ Object
Return a hash with the state of each line status bit. Keys are “rts”, “dtr”, “cts”, “dsr”, “dcd”, and “ri”.
Note: Under Windows, the rts and dtr values are not included.
383 384 |
# File 'ext/serialport.c', line 383 static VALUE sp_signals(self) VALUE self; |
#modem_params ⇒ Object
Get the configure of the serial port.
Returned is a hash with the following keys:
- “baud”
-
Integer with the baud rate
- “data_bits”
-
Integer from 5 to 8 (4 is possible on Windows too)
- “stop_bits”
-
Integer, 1 or 2 (1.5 is not supported)
- “parity”
-
One of the constants NONE, EVEN or ODD (on Windows may also MARK or SPACE)
307 308 |
# File 'ext/serialport.c', line 307 static VALUE sp_get_modem_params(self) VALUE self; |
#modem_params= ⇒ Object
Configure the serial port. You can pass a hash or multiple values as separate arguments. Invalid or unsupported values will raise an ArgumentError.
When using a hash the following keys are recognized:
- “baud”
-
Integer from 50 to 256000, depends on platform
- “data_bits”
-
Integer from 5 to 8 (4 is allowed on Windows too)
- “stop_bits”
-
An integer, only allowed values are 1 or 2 (1.5 is not supported)
- “parity”
-
One of the constants NONE, EVEN or ODD (Windows allows also MARK and SPACE)
When using separate arguments, they are interpreted as: (baud, data_bits = 8, stop_bits = 1, parity = (previous_databits==8 ? NONE : EVEN))
Nota: A baudrate of nil will keep the old value. The default parity depends on the number of databits configured before this function call.
57 58 |
# File 'ext/serialport.c', line 57 static VALUE sp_set_modem_params(argc, argv, self) int argc; |
#parity ⇒ Object
Get the current parity, see SerialPort#get_modem_params for details.
287 288 |
# File 'ext/serialport.c', line 287 static VALUE sp_get_parity(self) VALUE self; |
#parity= ⇒ Object
Set the parity, see SerialPort#set_modem_params for details.
233 234 |
# File 'ext/serialport.c', line 233 static VALUE sp_set_parity(self, parity) VALUE self, parity; |
#read_timeout ⇒ Object
Get the timeout value (in milliseconds) for reading. See SerialPort#set_read_timeout for details.
99 100 |
# File 'ext/serialport.c', line 99 static VALUE sp_get_read_timeout(self) VALUE self; |
#read_timeout=() ⇒ Object
155 156 157 158 |
# File 'ext/serialport.c', line 155
static VALUE sp_set_read_timeout(self, val)
{
return sp_set_read_timeout_impl(self, val);
}
|
#ri ⇒ Object
Get the state (0 or 1) of the RI line
367 368 |
# File 'ext/serialport.c', line 367 static VALUE sp_get_ri(self) VALUE self; |
#rts ⇒ Object
Get the state (0 or 1) of the RTS line (not available on Windows)
108 109 |
# File 'ext/serialport.c', line 108 static VALUE sp_get_rts(self) VALUE self; |
#rts=() ⇒ Object
163 164 165 166 |
# File 'ext/serialport.c', line 163
static VALUE sp_set_rts(self, val)
{
return sp_set_rts_impl(self, val);
}
|
#set_modem_params ⇒ Object
Configure the serial port. You can pass a hash or multiple values as separate arguments. Invalid or unsupported values will raise an ArgumentError.
When using a hash the following keys are recognized:
- “baud”
-
Integer from 50 to 256000, depends on platform
- “data_bits”
-
Integer from 5 to 8 (4 is allowed on Windows too)
- “stop_bits”
-
An integer, only allowed values are 1 or 2 (1.5 is not supported)
- “parity”
-
One of the constants NONE, EVEN or ODD (Windows allows also MARK and SPACE)
When using separate arguments, they are interpreted as: (baud, data_bits = 8, stop_bits = 1, parity = (previous_databits==8 ? NONE : EVEN))
Nota: A baudrate of nil will keep the old value. The default parity depends on the number of databits configured before this function call.
57 58 |
# File 'ext/serialport.c', line 57 static VALUE sp_set_modem_params(argc, argv, self) int argc; |
#signals ⇒ Object
Return a hash with the state of each line status bit. Keys are “rts”, “dtr”, “cts”, “dsr”, “dcd”, and “ri”.
Note: Under Windows, the rts and dtr values are not included.
383 384 |
# File 'ext/serialport.c', line 383 static VALUE sp_signals(self) VALUE self; |
#stop_bits ⇒ Object
Get the current stop bits, see SerialPort#get_modem_params for details.
274 275 |
# File 'ext/serialport.c', line 274 static VALUE sp_get_stop_bits(self) VALUE self; |
#stop_bits= ⇒ Object
Set the stop bits, see SerialPort#set_modem_params for details.
218 219 |
# File 'ext/serialport.c', line 218 static VALUE sp_set_stop_bits(self, stop_bits) VALUE self, stop_bits; |
#write_timeout ⇒ Object
Get the write timeout (in milliseconds)
Note: Under Posix, write timeouts are not implemented.
119 120 |
# File 'ext/serialport.c', line 119 static VALUE sp_get_write_timeout(self) VALUE self; |
#write_timeout=() ⇒ Object
173 174 175 176 |
# File 'ext/serialport.c', line 173
static VALUE sp_set_write_timeout(self, val)
{
return sp_set_write_timeout_impl(self, val);
}
|