Created
April 21, 2014 18:04
-
-
Save adkron/11150928 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Scada | |
class Connection | |
attr_accessor :environment | |
private :environment, :environment= | |
def self.open(&block) | |
env = new | |
env.connect | |
block.call(env) | |
ensure | |
env.disconnect | |
end | |
def initialize | |
self.environment = Scada.NdaGetEnv | |
end | |
def connect | |
Scada.NdaConnect(environment, host_string, buffer_size = 1024) | |
end | |
def disconnect | |
Scada.NdaDisconnect(environment) | |
end | |
def get_point_from_name(point_name) | |
result_size = 1 | |
global_error_code = FFI::MemoryPointer.new(:ulong, size = 1) | |
ids = FFI::MemoryPointer.new(:ulong, result_size) | |
errors = FFI::MemoryPointer.new(:ulong, result_size) | |
type_codes = FFI::MemoryPointer.new(:ulong, result_size) | |
point_name_ptrs = FFI::MemoryPointer.new(:pointer, result_size) | |
point_name_ptrs.write_array_of_pointer([FFI::MemoryPointer.from_string(point_name)]) | |
Scada.NdaGetipn(environment, result_size, point_name_ptrs, global_error_code, ids, errors, type_codes) | |
analog_point_value_function_code = 41 | |
get_global_error_code = FFI::MemoryPointer.new(:ulong, size = 1) | |
values = FFI::MemoryPointer.new(:double, result_size) | |
conditions = FFI::MemoryPointer.new(:uchar, result_size) | |
get_errors = FFI::MemoryPointer.new(:ulong, result_size) | |
Scada.NdaGet(environment, result_size, analog_point_value_function_code, get_global_error_code, ids, values, conditions, errors).to_s(16) | |
values.read_array_of_double(result_size) | |
end | |
private | |
def host_string | |
"host_a;host_b" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment