Class: Snap7::Client
- Inherits:
-
Object
- Object
- Snap7::Client
- Defined in:
- lib/ffi-snap7/client/client.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connect(address, rack, slot) ⇒ Object
- #connected? ⇒ Boolean
- #db_read(db_number, start, size) ⇒ Object
- #db_write(db_number, start, size, data) ⇒ Object
- #disconnect ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #plc_status ⇒ Object
- #remote_port ⇒ Integer
- #remote_port=(port) ⇒ Object
- #set_session_password(password) ⇒ Object
-
#to_ptr ⇒ FFI::MemoryPointer
Pointer to the native object.
Constructor Details
Class Method Details
.finalizer(ptr) ⇒ Proc
10 11 12 13 14 15 16 |
# File 'lib/ffi-snap7/client/client.rb', line 10 def self.finalizer(ptr) proc do ptrptr = FFI::MemoryPointer.new :pointer ptrptr.write_pointer ptr Snap7.cli_destroy ptrptr end end |
Instance Method Details
#connect(address, rack, slot) ⇒ Object
33 34 35 36 |
# File 'lib/ffi-snap7/client/client.rb', line 33 def connect(address, rack, slot) check_rc Snap7.cli_connect_to(@cli, address, rack, slot) @connected = true end |
#connected? ⇒ Boolean
45 46 47 |
# File 'lib/ffi-snap7/client/client.rb', line 45 def connected? @connected end |
#db_read(db_number, start, size) ⇒ Object
63 64 65 66 67 |
# File 'lib/ffi-snap7/client/client.rb', line 63 def db_read(db_number, start, size) p_usr_data = FFI::MemoryPointer.new :uchar, size check_rc Snap7.cli_db_read(@cli, db_number, start, size, p_usr_data) p_usr_data.get_array_of_uint8 0, size end |
#db_write(db_number, start, size, data) ⇒ Object
70 71 72 73 74 |
# File 'lib/ffi-snap7/client/client.rb', line 70 def db_write(db_number, start, size, data) p_usr_data = FFI::MemoryPointer.new :uchar, size p_usr_data.put_array_of_uint8 0, data check_rc Snap7.cli_db_write(@cli, db_number, start, size, p_usr_data) end |
#disconnect ⇒ Object
39 40 41 42 |
# File 'lib/ffi-snap7/client/client.rb', line 39 def disconnect Snap7.cli_disconnect @cli @connected = false end |
#plc_status ⇒ Object
55 56 57 58 59 60 |
# File 'lib/ffi-snap7/client/client.rb', line 55 def plc_status p_status = FFI::MemoryPointer.new :uchar, 1 check_rc Snap7.cli_get_plc_status(@cli, p_status) result = p_status.get_array_of_uint8 0, 1 { 0 => 'unknown', 4 => 'stopped', 8 => 'running'}[result.first] end |
#remote_port ⇒ Integer
86 87 88 89 90 |
# File 'lib/ffi-snap7/client/client.rb', line 86 def remote_port p_port = FFI::MemoryPointer.new(:uint16) check_rc Snap7.cli_get_param(@cli, P_u16_RemotePort, p_port) p_port.read_uint16 end |
#remote_port=(port) ⇒ Object
78 79 80 81 82 |
# File 'lib/ffi-snap7/client/client.rb', line 78 def remote_port=(port) p_value = FFI::MemoryPointer.new(:uint16) p_value.write_uint16 port check_rc Snap7.cli_set_param(@cli, P_u16_RemotePort, p_value) end |
#set_session_password(password) ⇒ Object
50 51 52 |
# File 'lib/ffi-snap7/client/client.rb', line 50 def set_session_password(password) check_rc Snap7.cli_set_session_password(@cli, password) end |
#to_ptr ⇒ FFI::MemoryPointer
Returns pointer to the native object.
28 29 30 |
# File 'lib/ffi-snap7/client/client.rb', line 28 def to_ptr @cli end |