Module: Adept::LowLevel::ErrorHandler

Extended by:
FFI::Library
Defined in:
lib/adept/low_level/error_handler.rb

Overview

Basic low-level error handler.

This class implements the basic error reporting functionality from the Digilent Device Manager API. It is intentionally separate from the low-level DeviceManager wrapper, so error checking works even if the AdeptLibrary class fails during development.

Class Method Summary collapse

Class Method Details

.last_errorObject

Returns a DeviceError which encapsulates the most recent error, in a format which can be easily raised.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/adept/low_level/error_handler.rb', line 37

def self.last_error

  #get the error code most recently seen by the device manager API.
  code = DmgrGetLastError()

  #if no error has occurred, return nil.
  return nil if code.zero?
      
  #Create space for the error name and message...
  error_name = FFI::MemoryPointer.new(ErrorNameMaxLength)
  error_message = FFI::MemoryPointer.new(ErrorMessageMaxLength)

  #... and populate those spaces with the relevant error information.
  DmgrSzFromErc(code, error_name, error_message)

  #Convert the error information into a DeviceError.
  DeviceError.new(error_message.read_string, error_name.read_string, code)

end