Module: Adept::LowLevel::EnhancedParallel

Extended by:
Connection, Library
Defined in:
lib/adept/low_level/enhanced_parallel.rb

Overview

Low-Level Enhanced Parallel Port (EPP) Connection

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Library

runtime_version

Methods included from Connection

extended, port_count, supported?

Class Method Details

.get_register_value(handle, address, overlap = false) ⇒ Object

Returns the value of a single EPP register.



53
54
55
# File 'lib/adept/low_level/enhanced_parallel.rb', line 53

def self.get_register_value(handle, address, overlap=false)
  receive_out_arguments(:uint8) { |receive_buffer| GetReg(handle, address, receive_buffer, overlap) }
end

.get_register_values(handle, addresses, overlap = false) ⇒ Object

Gets the value of mulitple registers at once.

handle: The handle of the affected adept device. addresses: A list of register values to get. Must support to_a. overlap: True to make the operation non-blocking.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/adept/low_level/enhanced_parallel.rb', line 95

def self.get_register_values(handle, addresses, overlap=false)

  #Create a buffer containing each of the addresses to query.
  address_buffer = to_buffer(addresses)
 
  #And perform the query itself, returning 
  out_args = receive_out_arguments(addresses.count) do 
    |data_buffer| GetRegSet(handle, address_buffer, data_buffer, addresses.count, overlap)
  end

  #Pair each of the addresses with the corresponding data value received.
  pairs = addresses.zip(out_args.unpack("C*"))

  #Convert that response to a hash, and return it.
  Hash[pairs]

end

.set_register_value(handle, address, value, overlap = false) ⇒ Object

Sets the value of a given EPP register. This function exists for symettry with get_register_value.

handle: The handle to the target device. address:

The address of the register to be set, may by from [0..255], though
not all EPP devices will provide all 256 registers.

value:

The value to be placed into the register. Should be within the range 
[0..255].

overlap: True to make the operation non-blocking.



46
47
48
# File 'lib/adept/low_level/enhanced_parallel.rb', line 46

def self.set_register_value(handle, address, value, overlap=false)
  PutReg(handle, address, value, false)
end

.set_register_values(handle, mapping, overlap = false) ⇒ Object

Sets the value of multiple registers at once.

handle: The handle of the affected adept device. mapping: A hash mapping addresses to values.

For example { 3 => 4, 9 => 5} would place 4 in register 3, and 5 in register 9.

overlap: True to make the operation non-blocking.



77
78
79
80
81
82
83
84
85
# File 'lib/adept/low_level/enhanced_parallel.rb', line 77

def self.set_register_values(handle, mapping, overlap=false)

  #Create a buffer, which contains each of the register => value pairs.
  value_buffer = to_buffer(mapping.flatten)

  #And set each of the register values.
  PutRegSet(handle, value_buffer, mapping.size, overlap)

end

Instance Method Details

#send_to_register(handle, address, data, overlap = false) ⇒ Object

Sends a “stream” of data to a single register, by repeatedly writing to that register. Some hardware targets may be able to interpret these repeated writes as a data-stream.

handle: The handle of the affected adept device. address: The address of the register to target; should be within [0..255]. data: An array (or array-like object) containing the data to be sent. Index

0 is sent first, followed by 1, and etc.

overlap: True to make the operation non-blocking.



136
137
138
139
140
141
142
143
144
# File 'lib/adept/low_level/enhanced_parallel.rb', line 136

def send_to_register(handle, address, data, overlap=false)

  #Create a buffer containing the data to be sent.
  data_buffer = to_buffer(data)

  #And send the relevant data.
  PutRegRepeat(handle, address, data_buffer, data.size, overlap)

end