rbzk 0.1.3 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15c22b690a9f4468b2cd2a819f0d98002c7127ca05a60d32900ffbb93b1785c1
4
- data.tar.gz: 6bdccf44dc137c44fa32502a33b5e22331535c628413b99049186c84ef38ab2e
3
+ metadata.gz: dc6b7b78fa88e4e3cbea5a63aff9a333e1dea98a796de0cc2ab1a8d875f10a64
4
+ data.tar.gz: ab1527c24665247a5de3393fdf83a9aa0f4c74fe9fe933554ed105968584b56e
5
5
  SHA512:
6
- metadata.gz: 00710ea8cd440e358a368179472ed0e3663368c93b9c73b3eb4247da44a2bfb8d4890b5a1d228373f2414fa24af330388bbc5095aca027a97cc0acdd0d293387
7
- data.tar.gz: ebfee036a5b801a0186e5bf59afedce2e5ef9cd4301fce3c02000b1601198d3a6acf6eb6a59fb531061540a26973ddb1e673894263b6df68b777e1d04138d836
6
+ metadata.gz: ee91215cdd36830c39e259ab1e42384c8f155d896cb52254105aaf6d36b4167fc7becbd9b4cb632631e32ef23ce2ac57c2de3ecc32990857a56b74a25e26b2d2
7
+ data.tar.gz: 9bad7c48f98845263d7183362ae7d19a453035747100605e05f6523a0dafd5d9ce9e264dcbfdf2950c297dcff448027716f9edc1a41c18196d89acf4e5942e8e
data/README.md CHANGED
@@ -24,7 +24,9 @@ Or install it yourself as:
24
24
  $ gem install rbzk
25
25
  ```
26
26
 
27
- ## Usage
27
+ ## Library Usage
28
+
29
+ The `rbzk` gem provides a `RBZK::ZK` class to interact with ZKTeco devices.
28
30
 
29
31
  ### Basic Connection
30
32
 
@@ -32,7 +34,8 @@ $ gem install rbzk
32
34
  require 'rbzk'
33
35
 
34
36
  # Create a new ZK instance
35
- zk = RBZK::ZK.new('192.168.1.201', port: 4370)
37
+ # Replace with your device's IP address
38
+ zk = RBZK::ZK.new('192.168.1.201', port: 4370, timeout: 60, password: 0)
36
39
 
37
40
  # Connect to the device
38
41
  begin
@@ -46,329 +49,376 @@ begin
46
49
  exit 1
47
50
  end
48
51
 
49
- # Disable the device to ensure exclusive access
52
+ # Disable the device to ensure exclusive access for sensitive operations
50
53
  puts 'Disabling device...'
51
54
  conn.disable_device
52
55
 
53
- # Your operations here...
56
+ # --- Your operations here ---
57
+ puts "Device Firmware Version: #{conn.get_firmware_version}"
58
+ puts "Serial Number: #{conn.get_serialnumber}"
59
+ # --- End of operations ---
54
60
 
55
61
  # Re-enable the device when done
56
62
  puts 'Enabling device...'
57
63
  conn.enable_device
58
- rescue => e
59
- puts "Error: #{e.message}"
64
+ rescue RBZK::ZKError => e # Catch specific RBZK errors
65
+ puts "ZK Error: #{e.message}"
66
+ rescue => e # Catch other potential errors
67
+ puts "Generic Error: #{e.message}"
60
68
  ensure
61
69
  # Always disconnect when done
62
70
  conn.disconnect if conn && conn.connected?
71
+ puts "Disconnected."
63
72
  end
64
73
  ```
65
74
 
66
- ### Getting Users
75
+ ### Device Information
67
76
 
68
77
  ```ruby
69
- require 'rbzk'
70
-
71
- zk = RBZK::ZK.new('192.168.1.201')
72
- begin
73
- conn = zk.connect
74
- conn.disable_device
75
-
76
- puts '--- Get Users ---'
77
- users = conn.get_users
78
- users.each do |user|
79
- privilege = 'User'
80
- privilege = 'Admin' if user.privilege == RBZK::Constants::USER_ADMIN
81
-
82
- puts "UID: #{user.uid}"
83
- puts "Name: #{user.name}"
84
- puts "Privilege: #{privilege}"
85
- puts "Password: #{user.password}"
86
- puts "Group ID: #{user.group_id}"
87
- puts "User ID: #{user.user_id}"
88
- puts "---"
89
- end
90
-
91
- conn.enable_device
92
- rescue => e
93
- puts "Error: #{e.message}"
94
- ensure
95
- conn.disconnect if conn && conn.connected?
96
- end
78
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
79
+ # (See Basic Connection example)
80
+
81
+ puts "--- Device Information ---"
82
+ puts "Firmware Version: #{conn.get_firmware_version}"
83
+ puts "Serial Number: #{conn.get_serialnumber}"
84
+ puts "MAC Address: #{conn.get_mac}"
85
+ puts "Device Name: #{conn.get_device_name}"
86
+ puts "Platform: #{conn.get_platform}"
87
+ puts "Fingerprint Algorithm Version: #{conn.get_fp_version}"
88
+ # puts "Face Algorithm Version: #{conn.get_face_version}" # If applicable
89
+ puts "Device Time: #{conn.get_time}"
90
+
91
+ # Get user, fingerprint, and record counts/capacities
92
+ conn.read_sizes # Updates internal counts
93
+ puts "User Count: #{conn.instance_variable_get(:@users)}"
94
+ puts "Fingerprint Count: #{conn.instance_variable_get(:@fingers)}"
95
+ puts "Attendance Record Count: #{conn.instance_variable_get(:@records)}"
96
+ puts "User Capacity: #{conn.instance_variable_get(:@users_cap)}"
97
+ puts "Fingerprint Capacity: #{conn.instance_variable_get(:@fingers_cap)}"
98
+ puts "Record Capacity: #{conn.instance_variable_get(:@rec_cap)}"
97
99
  ```
98
100
 
99
- ### Getting Attendance Logs
101
+ ### Device Control
100
102
 
101
103
  ```ruby
102
- require 'rbzk'
104
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
103
105
 
104
- zk = RBZK::ZK.new('192.168.1.201')
105
- begin
106
- conn = zk.connect
107
- conn.disable_device
106
+ # Restart the device
107
+ # conn.restart
108
+ # puts "Device restarting..."
108
109
 
109
- puts '--- Get Attendance Logs ---'
110
- logs = conn.get_attendance_logs
111
- logs.each do |log|
112
- puts "User ID: #{log.user_id}"
113
- puts "Timestamp: #{log.timestamp}"
114
- puts "Status: #{log.status}"
115
- puts "Punch: #{log.punch}"
116
- puts "UID: #{log.uid}"
117
- puts "---"
118
- end
119
-
120
- conn.enable_device
121
- rescue => e
122
- puts "Error: #{e.message}"
123
- ensure
124
- conn.disconnect if conn && conn.connected?
125
- end
126
- ```
110
+ # Power off the device (use with caution)
111
+ # conn.poweroff
112
+ # puts "Device powering off..."
127
113
 
128
- ### Device Operations
114
+ # Test a voice prompt (e.g., "Thank you")
115
+ # conn.test_voice(RBZK::Constants::EF_THANKYOU) # Check Constants for available voice enums
116
+ # puts "Tested voice prompt."
129
117
 
130
- ```ruby
131
- require 'rbzk'
118
+ # Unlock the door for 5 seconds
119
+ conn.unlock(5)
120
+ puts "Door unlocked for 5 seconds."
132
121
 
133
- zk = RBZK::ZK.new('192.168.1.201')
134
- begin
135
- conn = zk.connect
122
+ # Get door lock state
123
+ state = conn.get_lock_state
124
+ puts "Door is #{state ? 'Open' : 'Closed'}."
125
+ ```
136
126
 
137
- # Get device time
138
- time = conn.get_time
139
- puts "Device time: #{time}"
127
+ ### LCD Operations
140
128
 
141
- # Set device time to current time
142
- conn.set_time
129
+ ```ruby
130
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
131
+
132
+ # Write text to LCD (line number, text)
133
+ conn.write_lcd(1, "Hello from RBZK!")
134
+ puts "Text written to LCD line 1."
135
+ conn.write_lcd(2, Time.now.strftime("%H:%M:%S"))
136
+ puts "Text written to LCD line 2."
137
+
138
+ # Clear the LCD display
139
+ # sleep 5 # Keep text for 5 seconds
140
+ # conn.clear_lcd
141
+ # puts "LCD cleared."
142
+ ```
143
143
 
144
- # Get device info
145
- info = conn.get_free_sizes
146
- puts "Users: #{info[:users]}"
147
- puts "Fingers: #{info[:fingers]}"
148
- puts "Capacity: #{info[:capacity]}"
149
- puts "Logs: #{info[:logs]}"
150
- puts "Passwords: #{info[:passwords]}"
144
+ ### User Management
151
145
 
152
- # Test the device voice
153
- conn.test_voice
146
+ #### Getting Users
154
147
 
155
- rescue => e
156
- puts "Error: #{e.message}"
157
- ensure
158
- conn.disconnect if conn && conn.connected?
148
+ ```ruby
149
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
150
+
151
+ puts '--- Get Users ---'
152
+ users = conn.get_users
153
+ users.each do |user|
154
+ privilege = 'User'
155
+ privilege = 'Admin' if user.privilege == RBZK::Constants::USER_ADMIN
156
+
157
+ puts "UID: #{user.uid}"
158
+ puts "Name: #{user.name}"
159
+ puts "Privilege: #{privilege}"
160
+ puts "Password: #{user.password}" # Be mindful of displaying passwords
161
+ puts "Group ID: #{user.group_id}"
162
+ puts "User ID (PIN2): #{user.user_id}"
163
+ puts "Card: #{user.card}"
164
+ puts "---"
159
165
  end
160
166
  ```
161
167
 
162
- ### Getting Fingerprint Templates
168
+ #### Add/Update User
163
169
 
164
170
  ```ruby
165
- require 'rbzk'
166
-
167
- zk = RBZK::ZK.new('192.168.1.201')
168
- begin
169
- conn = zk.connect
170
- conn.disable_device
171
-
172
- puts '--- Get Fingerprint Templates ---'
173
- templates = conn.get_templates
174
- templates.each do |template|
175
- puts "UID: #{template.uid}"
176
- puts "Finger ID: #{template.fid}"
177
- puts "Valid: #{template.valid == 1 ? 'Yes' : 'No'}"
178
- puts "Template size: #{template.template.size} bytes"
179
- puts "---"
180
- end
181
-
182
- # Get a specific user's template
183
- if templates.any?
184
- user_template = conn.get_user_template(templates.first.uid, templates.first.fid)
185
- puts "Got specific template for user #{user_template.uid}, finger #{user_template.fid}"
186
- end
187
-
188
- conn.enable_device
189
- rescue => e
190
- puts "Error: #{e.message}"
191
- ensure
192
- conn.disconnect if conn && conn.connected?
171
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
172
+
173
+ puts '--- Add/Update User ---'
174
+ # For a new user, UID can often be omitted if the device assigns it.
175
+ # To update an existing user, provide their UID.
176
+ # conn.read_sizes # Ensure @next_uid is populated if device assigns UIDs
177
+ # new_uid = conn.instance_variable_get(:@next_uid) # Example for new user
178
+
179
+ user_attributes = {
180
+ uid: 123, # Specify UID to update, or omit for device to assign (check device behavior)
181
+ name: 'John Doe',
182
+ privilege: RBZK::Constants::USER_DEFAULT,
183
+ password: '1234',
184
+ group_id: '1',
185
+ user_id: 'JD123', # Custom User ID / PIN2
186
+ card: 7890
187
+ }
188
+
189
+ if conn.set_user(**user_attributes)
190
+ puts "User #{user_attributes[:name]} (UID: #{user_attributes[:uid] || 'auto'}) added/updated successfully."
191
+ conn.refresh_data # Good practice to refresh data after modifications
192
+ else
193
+ puts "Failed to add/update user."
193
194
  end
194
195
  ```
195
196
 
196
- ## Command Line Interface
197
-
198
- RBZK provides a powerful command-line interface for interacting with ZKTeco devices. The CLI is built using Thor, which provides a clean, intuitive interface similar to Git and other modern command-line tools.
197
+ #### Delete User
199
198
 
200
- ### Installation
201
-
202
- After installing the gem, you can use the `rbzk` command directly:
203
-
204
- ```bash
205
- # Install the gem
206
- gem install rbzk
207
-
208
- # Use the command
209
- bin/rbzk info 192.168.100.201
210
- ```
199
+ ```ruby
200
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
211
201
 
212
- If you're using Bundler, you can run the command through `bundle exec`:
202
+ puts '--- Delete User ---'
203
+ uid_to_delete = 123 # UID of the user to delete
213
204
 
214
- ```bash
215
- bundle exec rbzk info 192.168.100.201
205
+ if conn.delete_user(uid: uid_to_delete)
206
+ puts "User with UID #{uid_to_delete} deleted successfully."
207
+ conn.refresh_data
208
+ else
209
+ puts "Failed to delete user with UID #{uid_to_delete} (may not exist)."
210
+ end
216
211
  ```
217
212
 
218
- ### Available Commands
219
-
220
- ```bash
221
- # Get help
222
- bin/rbzk help
223
-
224
- # Get help for a specific command
225
- bin/rbzk help logs
226
- ```
213
+ ### Attendance Log Management
227
214
 
228
- #### Device Information
215
+ #### Getting Attendance Logs
229
216
 
230
- ```bash
231
- # Get device information
232
- bin/rbzk info 192.168.100.201 [options]
217
+ ```ruby
218
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
219
+
220
+ puts '--- Get Attendance Logs ---'
221
+ logs = conn.get_attendance_logs
222
+ if logs.empty?
223
+ puts "No attendance logs found."
224
+ else
225
+ logs.each_with_index do |log, index|
226
+ puts "Log ##{index + 1}:"
227
+ puts " Device UID: #{log.uid}" # Internal device UID for the record
228
+ puts " User ID (PIN2): #{log.user_id}"
229
+ # Status: Check-in, Check-out, etc. (Refer to ZK documentation for specific status codes)
230
+ puts " Status: #{log.status}"
231
+ # Punch: Fingerprint, Password, Card, etc. (Refer to ZK documentation)
232
+ puts " Punch Type: #{log.punch}"
233
+ puts " Timestamp: #{log.timestamp.strftime('%Y-%m-%d %H:%M:%S')}"
234
+ puts "---"
235
+ end
236
+ end
233
237
  ```
234
238
 
235
- #### Users
239
+ #### Clear Attendance Logs
236
240
 
237
- ```bash
238
- # Get users from the device
239
- bin/rbzk users 192.168.100.201 [options]
241
+ ```ruby
242
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
243
+
244
+ # puts '--- Clear Attendance Logs ---'
245
+ # puts "WARNING: This will delete all attendance logs from the device."
246
+ # print "Are you sure? (yes/N): "
247
+ # confirmation = gets.chomp
248
+ # if confirmation.downcase == 'yes'
249
+ # if conn.clear_attendance
250
+ # puts "Attendance logs cleared successfully."
251
+ # conn.refresh_data
252
+ # else
253
+ # puts "Failed to clear attendance logs."
254
+ # end
255
+ # else
256
+ # puts "Operation cancelled."
257
+ # end
240
258
  ```
241
259
 
242
- #### Attendance Logs
243
-
244
- ```bash
245
- # Get all attendance logs
246
- bin/rbzk logs 192.168.100.201 [options]
260
+ ### Fingerprint Template Management
247
261
 
248
- # Get today's logs
249
- bin/rbzk logs 192.168.100.201 --today [options]
262
+ *(Note: Fingerprint template data is binary and device-specific. Handling it requires careful understanding of the ZK protocol and template formats.)*
250
263
 
251
- # Get yesterday's logs
252
- bin/rbzk logs 192.168.100.201 --yesterday [options]
264
+ #### Get All Fingerprint Templates
253
265
 
254
- # Get this week's logs
255
- bin/rbzk logs 192.168.100.201 --week [options]
256
-
257
- # Get this month's logs
258
- bin/rbzk logs 192.168.100.201 --month [options]
259
-
260
- # Get logs for a custom date range
261
- bin/rbzk logs 192.168.100.201 --start-date=2023-01-01 --end-date=2023-01-31 [options]
262
- ```
263
-
264
- #### Clear Logs
265
-
266
- ```bash
267
- # Clear attendance logs (will prompt for confirmation)
268
- bin/rbzk clear_logs 192.168.100.201 [options]
266
+ ```ruby
267
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
268
+
269
+ puts '--- Get All Fingerprint Templates ---'
270
+ templates = conn.get_templates
271
+ if templates.empty?
272
+ puts "No fingerprint templates found."
273
+ else
274
+ templates.each do |fp_template|
275
+ puts "UID: #{fp_template.uid}, Finger ID: #{fp_template.fid}, Valid: #{fp_template.valid}, Size: #{fp_template.size}"
276
+ end
277
+ end
269
278
  ```
270
279
 
271
- #### Test Voice
280
+ #### Get a Specific User's Fingerprint Template
272
281
 
273
- ```bash
274
- # Test the device voice
275
- bin/rbzk test_voice 192.168.100.201 [options]
276
- ```
277
-
278
- ### Global Options
282
+ ```ruby
283
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
279
284
 
280
- These options can be used with any command:
285
+ user_uid = '123' # The user's main UID (often a string from device)
286
+ finger_id = 0 # Finger index (0-9)
281
287
 
288
+ begin
289
+ fp_template = conn.get_user_template(user_uid, finger_id)
290
+ if fp_template
291
+ puts "Template for UID #{user_uid}, Finger ID #{finger_id}: Size #{fp_template.size}, Valid: #{fp_template.valid}"
292
+ # fp_template.template contains the binary data
293
+ else
294
+ puts "Template not found for UID #{user_uid}, Finger ID #{finger_id}."
295
+ end
296
+ rescue RBZK::ZKErrorResponse => e
297
+ puts "Error getting template: #{e.message}"
298
+ end
282
299
  ```
283
- --ip=IP # Device IP address (default: from config or 192.168.100.201)
284
- --port=PORT # Device port (default: from config or 4370)
285
- --timeout=SECONDS # Connection timeout in seconds (default: from config or 30)
286
- --password=PASSWORD # Device password (default: from config or 0)
287
- --verbose # Enable verbose output (default: from config or false)
288
- --force-udp # Use UDP instead of TCP (default: from config or false)
289
- --no-ping # Skip ping check (default: from config or true)
290
- --encoding=ENCODING # Character encoding (default: from config or UTF-8)
291
- ```
292
-
293
- ### Configuration
294
-
295
- RBZK supports persistent configuration through a configuration file. This allows you to set default values for IP address and other options without having to specify them every time.
296
-
297
- #### Configuration File Location
298
300
 
299
- The configuration file is stored in one of the following locations (in order of precedence):
301
+ #### Set a User's Fingerprint Template
300
302
 
301
- 1. `$XDG_CONFIG_HOME/rbzk/config.yml` (if `$XDG_CONFIG_HOME` is set)
302
- 2. `$HOME/.config/rbzk/config.yml` (on most systems)
303
- 3. `.rbzk.yml` in the current directory (fallback)
304
-
305
- #### Configuration Commands
306
-
307
- ```bash
308
- # Show current configuration
309
- bin/rbzk config
310
-
311
- # Set a configuration value
312
- bin/rbzk config-set ip 192.168.1.201
313
- bin/rbzk config-set port 4371
314
- bin/rbzk config-set password 12345
315
- bin/rbzk config-set verbose true
316
-
317
- # Reset configuration to defaults
318
- bin/rbzk config-reset
303
+ *(This is an advanced operation. You need valid template data.)*
304
+ ```ruby
305
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
306
+ # And `valid_template_data` is a binary string of a valid fingerprint template
307
+
308
+ # user_uid = '123'
309
+ # finger_id = 0
310
+ # valid_flag = 1 # 1 for valid, 0 for invalid/duplicate
311
+ # valid_template_data = "BINARY_TEMPLATE_DATA_HERE" # Replace with actual binary data
312
+
313
+ # begin
314
+ # if conn.set_user_template(valid_template_data, user_uid, finger_id, valid_flag)
315
+ # puts "Fingerprint template set successfully for UID #{user_uid}, Finger ID #{finger_id}."
316
+ # conn.refresh_data
317
+ # else
318
+ # puts "Failed to set fingerprint template."
319
+ # end
320
+ # rescue RBZK::ZKErrorResponse => e
321
+ # puts "Error setting template: #{e.message}"
322
+ # end
319
323
  ```
320
324
 
321
- When you run commands, the CLI will use values from the configuration file as defaults. Command-line options will override the configuration file values.
322
-
323
- ### Examples
325
+ #### Delete/Clear Fingerprint Templates
324
326
 
325
- ```bash
326
- # Get device information
327
- bin/rbzk info 192.168.100.201
328
-
329
- # Get users with custom port and password
330
- bin/rbzk users 192.168.100.201 --port=4371 --password=12345
331
-
332
- # Get today's attendance logs with verbose output
333
- bin/rbzk logs 192.168.100.201 --today --verbose
334
-
335
- # Get logs for a custom date range (two ways)
336
- bin/rbzk logs-custom 2023-01-01 2023-01-31 192.168.100.201
337
- bin/rbzk logs 192.168.100.201 --start-date=2023-01-01 --end-date=2023-01-31
338
-
339
- # Get logs from a specific date to today
340
- bin/rbzk logs 192.168.100.201 --start-date=2023-01-01
341
-
342
- # Get logs from 30 days before to a specific date
343
- bin/rbzk logs 192.168.100.201 --end-date=2023-01-31
344
-
345
- # Test voice with UDP connection
346
- bin/rbzk test_voice 192.168.100.201 --force-udp
327
+ ```ruby
328
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
329
+
330
+ # Delete a specific fingerprint for a user
331
+ # user_uid_for_fp_delete = '123'
332
+ # finger_id_to_delete = 0
333
+ # if conn.delete_user_template(user_uid_for_fp_delete, finger_id_to_delete)
334
+ # puts "Template for UID #{user_uid_for_fp_delete}, FID #{finger_id_to_delete} deleted."
335
+ # conn.refresh_data
336
+ # else
337
+ # puts "Failed to delete template."
338
+ # end
339
+
340
+ # Clear all fingerprint templates for a specific user
341
+ # user_uid_to_clear_fps = '123'
342
+ # if conn.clear_user_template(user_uid_to_clear_fps) # Method name might vary, e.g., delete_user_fingerprints
343
+ # puts "All templates for UID #{user_uid_to_clear_fps} cleared."
344
+ # conn.refresh_data
345
+ # else
346
+ # puts "Failed to clear user templates."
347
+ # end
348
+
349
+ # Clear ALL fingerprint templates on the device (Use with extreme caution!)
350
+ # puts "WARNING: This will delete ALL fingerprint templates from the device."
351
+ # print "Are you sure? (yes/N): "
352
+ # confirmation_clear_all_fp = gets.chomp
353
+ # if confirmation_clear_all_fp.downcase == 'yes'
354
+ # if conn.clear_templates # Or clear_fingerprints
355
+ # puts "All fingerprint templates cleared from device."
356
+ # conn.refresh_data
357
+ # else
358
+ # puts "Failed to clear all fingerprint templates."
359
+ # end
360
+ # else
361
+ # puts "Operation cancelled."
362
+ # end
347
363
  ```
348
364
 
349
- ### Pretty Output
350
-
351
- The command line interface uses the `terminal-table` gem for prettier output if it's available. To enable this feature, install the gem:
365
+ ### Device Time
352
366
 
353
- ```bash
354
- gem install terminal-table
367
+ ```ruby
368
+ # Assuming 'conn' is an active and connected RBZK::ZK instance
369
+
370
+ # Get device time
371
+ current_device_time = conn.get_time
372
+ puts "Current device time: #{current_device_time}"
373
+
374
+ # Set device time (to current system time)
375
+ # new_time = Time.now
376
+ # if conn.set_time(new_time)
377
+ # puts "Device time set to #{new_time} successfully."
378
+ # else
379
+ # puts "Failed to set device time."
380
+ # end
355
381
  ```
356
382
 
357
- If the gem is not available, the CLI will fall back to plain text output.
383
+ ## Command Line Interface (CLI)
358
384
 
359
- ## Development
385
+ The `rbzk` gem also provides a command-line tool named `rbzk` for quick interactions with your ZKTeco devices.
360
386
 
361
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
362
- also run `bin/console` for an interactive prompt that will allow you to experiment.
363
-
364
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
365
- version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
366
- push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
387
+ ### Global Options
367
388
 
368
- ## Contributing
389
+ These options can be used with most commands:
369
390
 
370
- Bug reports and pull requests are welcome on GitHub at https://github.com/shqear93/rbzk.
391
+ * `--ip <IP_ADDRESS>`: IP address of the device.
392
+ * `--port <PORT>`: Port number (default: 4370).
393
+ * `--timeout <SECONDS>`: Connection timeout in seconds (default: 30 or 60).
394
+ * `--password <PASSWORD>`: Device communication password (default: 0).
395
+ * `--verbose`: Enable verbose output.
396
+ * `--force-udp`: Force UDP mode for communication.
397
+ * `--no-ping`: Skip the initial ping check.
398
+ * `--encoding <ENCODING>`: String encoding (default: UTF-8).
371
399
 
372
- ## License
400
+ ### Available Commands
373
401
 
374
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
402
+ Here are some of the primary commands available:
403
+
404
+ * `rbzk info [--ip IP]`: Get detailed device information.
405
+ * `rbzk refresh [--ip IP]`: Refresh the device's internal data (useful after making changes).
406
+ * `rbzk users [--ip IP]`: List all users on the device.
407
+ * `rbzk logs [--ip IP] [options]`: Get attendance logs.
408
+ * `--today`: Get today's logs.
409
+ * `--yesterday`: Get yesterday's logs.
410
+ * `--week`: Get logs for the current week.
411
+ * `--month`: Get logs for the current month.
412
+ * `--start-date YYYY-MM-DD`: Filter logs from a specific start date.
413
+ * `--end-date YYYY-MM-DD`: Filter logs up to a specific end date.
414
+ * `--limit N`: Limit the number of logs displayed (0 for all).
415
+ * Aliases: `rbzk logs-today`, `rbzk logs-yesterday`, `rbzk logs-week`, `rbzk logs-month`.
416
+ * `rbzk logs-all [--ip IP]`: Get all attendance logs without any limit.
417
+ * `rbzk logs-custom <START_DATE> <END_DATE> [--ip IP]`: Get logs for a custom date range (YYYY-MM-DD).
418
+ * `rbzk clear-logs [--ip IP]`: Clear all attendance logs from the device (prompts for confirmation).
419
+ * `rbzk unlock [--ip IP] [--time SECONDS]`: Unlock the connected door (default 3 seconds).
420
+ * `rbzk door-state [--ip IP]`: Get the current state of the door lock (Open/Closed).
421
+ * `rbzk write-lcd <LINE_NUMBER> <TEXT> [--ip IP]`: Write text to the device's LCD screen.
422
+ * `rbzk clear-lcd [--ip IP]`: Clear the device's LCD screen.
423
+ * `rbzk add-user [--ip IP] [options]`: Add or update a user.
424
+ * `--uid <UID