module Zklib::DeviceManagement

Constants

DEVICE_NAME_KEYWORD
DISABLE_DEVICE_KEYWORD

Public Instance Methods

disable_device() click to toggle source

Disable attendance machine

# File lib/zklib/device_management.rb, line 7
def disable_device
  execute_cmd(
    command:        CMD_DISABLEDEVICE,
    command_string: DISABLE_DEVICE_KEYWORD
  ) do |opts|
    return puts "ERROR: #{options[:error]}" unless opts[:valid]

    data = opts[:data]
    if data.length > 7
      data.split("\u0000").pop
    else
      puts 'ERROR: Invalid disable device response'
    end
  end
end
enable_device() click to toggle source

Enable attendance machine

# File lib/zklib/device_management.rb, line 24
def enable_device
  execute_cmd(
    command:        CMD_ENABLEDEVICE,
    command_string: ''
  ) do |opts|
    return puts "ERROR: #{options[:error]}" unless opts[:valid]

    data = opts[:data]
    if data.length > 7
      data.split("\u0000").pop
    else
      puts 'ERROR: Invalid enable device response'
    end
  end
end
get_device_name() click to toggle source

Get device name

# File lib/zklib/device_management.rb, line 41
def get_device_name
  execute_cmd(
    command:        CMD_DEVICE,
    command_string: DEVICE_NAME_KEYWORD
  ) do |opts|
    return puts "ERROR: #{options[:error]}" unless opts[:valid]

    data = opts[:data]
    if data.length > 8
      data.split("\u0000").pop.tr("#{DEVICE_NAME_KEYWORD}=", '')
    else
      puts 'ERROR: Invalid device name response'
    end
  end
end
power_off_device() click to toggle source

Turn off attendance machine

# File lib/zklib/device_management.rb, line 58
def power_off_device
  execute_cmd(
    command:        CMD_POWEROFF,
    command_string: ''
  ) do |opts|
    return puts "ERROR: #{options[:error]}" unless opts[:valid]

    data = opts[:data]
    if data.length > 7
      data.split("\u0000").pop
    else
      puts 'ERROR: Invalid power off device response'
    end
  end
end
restart_device() click to toggle source

Restart attendance machine

# File lib/zklib/device_management.rb, line 75
def restart_device
  execute_cmd(
    command:        CMD_RESTART,
    command_string: ''
  ) do |opts|
    return puts "ERROR: #{options[:error]}" unless opts[:valid]

    data = opts[:data]
    if data.length > 7
      data.split("\u0000").pop
    else
      puts 'ERROR: Invalid restart device response'
    end
  end
end