lib/zklib/helper.rb
# Execute command on attendance machine
#
# param  options
#        |_ command         Command to execute
#        |_ command_string  Command string
Execute command on attendance machine
param  options
|_ command         Command to execute
|_ command_string  Command string
Execute command on attendance machine param options |_ command Command to execute |_ command_string Command string
def execute_cmd(options)
      command = options[:command]
      self.reply_id = USHRT_MAX - 1 if command == CMD_CONNECT
      header = create_header(
        command:        command,
        checksum:       0,
        session_id:     session_id,
        reply_id:       reply_id,
        command_string: options[:command_string]
      )
      socket = UDPSocket.new
      socket.bind('0.0.0.0', inport)
      socket.send(header, 0, ip, port)
      self.data_recv = socket.recvfrom(USHRT_MAX)[0] if IO.select([socket], nil, nil, 10)
      socket.close
      if data_recv && data_recv.length > 0
        self.session_id = BinData::Uint16le.read(data_recv[4..-1]).snapshot
        self.reply_id = BinData::Uint16le.read(data_recv[6..-1]).snapshot
        yield(valid: true, data: data_recv) if block_given?
      else
        yield(valid: false, error: 'Empty response') if block_given?
      end
    end
def execute_cmd ( options ) command = options [ :command ] self . reply_id = USHRT_MAX - 1 if command == CMD_CONNECT header = create_header ( command : command , checksum : 0 , session_id : session_id , reply_id : reply_id , command_string : options [ :command_string ] ) socket = UDPSocket . new socket . bind ( '0.0.0.0' , inport ) socket . send ( header , 0 , ip , port ) self . data_recv = socket . recvfrom ( USHRT_MAX ) [ 0 ] if IO . select ( [ socket ] , nil , nil , 10 ) socket . close if data_recv && data_recv . length > 0 self . session_id = BinData :: Uint16le . read ( data_recv [ 4 .. - 1 ] ) . snapshot self . reply_id = BinData :: Uint16le . read ( data_recv [ 6 .. - 1 ] ) . snapshot yield ( valid : true , data : data_recv ) if block_given? else yield ( valid : false , error : 'Empty response' ) if block_given? end end
Execute command on attendance machine
param  options
|_ command         Command to execute
|_ command_string  Command string
Execute command on attendance machine param options |_ command Command to execute |_ command_string Command string
# Send command # Callback
options