Class: Snap7::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-snap7/server/server.rb

Constant Summary collapse

S7AreaPE =
0
S7AreaPA =
1
S7AreaMK =
2
S7AreaCT =
3
S7AreaTM =
4
S7AreaDB =
5

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



27
28
29
30
31
# File 'lib/ffi-snap7/server/server.rb', line 27

def initialize
  @srv = Snap7.srv_create

  ObjectSpace.define_finalizer self, self.class.finalizer(@srv)
end

Class Method Details

.finalizer(ptr) ⇒ Proc



18
19
20
21
22
23
24
# File 'lib/ffi-snap7/server/server.rb', line 18

def self.finalizer(ptr)
  proc do
    ptrptr = FFI::MemoryPointer.new :pointer
    ptrptr.write_pointer ptr
    Snap7.srv_destroy ptrptr
  end
end

Instance Method Details

#local_portInteger

Returns:

  • (Integer)


70
71
72
73
74
# File 'lib/ffi-snap7/server/server.rb', line 70

def local_port
  p_port = FFI::MemoryPointer.new(:uint16)
  check_rc Snap7.srv_get_param(@srv, P_u16_LocalPort, p_port)
  p_port.read_uint16
end

#local_port=(port) ⇒ Object

Parameters:

  • port (Integer)

    local port to bind to



62
63
64
65
66
# File 'lib/ffi-snap7/server/server.rb', line 62

def local_port=(port)
  p_port = FFI::MemoryPointer.new(:uint16)
  p_port.write_uint16 port
  check_rc Snap7.srv_set_param(@srv, P_u16_LocalPort, p_port)
end

#register_area(area_code, index, size) ⇒ Object



50
51
52
53
# File 'lib/ffi-snap7/server/server.rb', line 50

def register_area(area_code, index, size)
  p_usr_data = FFI::MemoryPointer.new :uchar, size
  check_rc Snap7.srv_register_area @srv, area_code, index, p_usr_data, size
end

#register_db(index, size) ⇒ Object



56
57
58
# File 'lib/ffi-snap7/server/server.rb', line 56

def register_db(index, size)
  register_area S7AreaDB, index, size
end

#startObject



40
41
42
# File 'lib/ffi-snap7/server/server.rb', line 40

def start
  check_rc Snap7.srv_start(@srv)
end

#stopObject



45
46
47
# File 'lib/ffi-snap7/server/server.rb', line 45

def stop
  check_rc Snap7.srv_stop(@srv)
end

#to_ptrFFI::MemoryPointer

Returns pointer to the native object.

Returns:

  • (FFI::MemoryPointer)

    pointer to the native object



35
36
37
# File 'lib/ffi-snap7/server/server.rb', line 35

def to_ptr
  @srv
end