Skip to content

CLI

Command-line interface for interacting with the OSECHI detector. Use commands like kazunoko query, kazunoko read, and kazunoko status to send commands and receive responses directly from the terminal.


measure

kazunoko.cli.measure(value=typer.Argument(..., help="Threshold value (e.g., '1:300;2:300;3:300')"), events_or_secs=typer.Argument(..., help='Number of events (--use-event) or duration in seconds (--use-sec)'), poll_count=Options.poll_count(), port=Options.port(), timeout=Options.timeout(), event_timeout=Options.event_timeout(), verbose=Options.verbose(), format=Options.format('jsonl'), use_flat=Options.use_flat(True), use_event=Options.use_event(), mock=MockOptions.mock())

Measure device response at specific threshold and collect events

Sets detection thresholds on specified channels and reads detection events with flexible collection modes: count-based (default) or time-based.

The threshold argument uses format: "channel:value;channel:value" (e.g., "1:300;2:300;3:300"). Even if you specify only some channels (e.g., "1:300;3:330"), all three threshold values (threshold1, threshold2, threshold3) will be included in each event, with unmodified channels retaining their previous values.

Example
# Count-based: Measure 1000 events at 300 ADC on all channels (default)
kazunoko measure "1:300;2:300;3:300" 1000

# Count-based: Different channels with different thresholds
kazunoko measure "1:500;2:300;3:300" 500 --port /dev/ttyUSB0

# Time-based: Measure for 60 seconds
kazunoko measure "1:300;2:300;3:300" 60 --use-sec

# Time-based: Collect for 30 seconds with different thresholds
kazunoko measure "1:500;2:300;3:300" 30 --use-sec -v

# Output in JSON format for processing
kazunoko measure "1:300;2:300;3:300" 100 --format json | jq '.threshold1'

# Adjust polling and communication timeouts
kazunoko measure "1:300;2:300;3:300" 1000 --poll-count 25000 --timeout 0.5

# Use mock device for testing
kazunoko measure "1:300;2:300;3:300" 100 --mock
Source code in src/kazunoko/cli.py
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
@app.command()
def measure(
    value: str = typer.Argument(..., help="Threshold value (e.g., '1:300;2:300;3:300')"),
    events_or_secs: int = typer.Argument(
        ..., help="Number of events (--use-event) or duration in seconds (--use-sec)"
    ),
    poll_count: int = Options.poll_count(),
    port: str = Options.port(),
    timeout: float = Options.timeout(),
    event_timeout: float = Options.event_timeout(),
    verbose: bool = Options.verbose(),
    format: Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"] = Options.format("jsonl"),
    use_flat: bool = Options.use_flat(True),
    use_event: bool = Options.use_event(),
    mock: bool = MockOptions.mock(),
) -> None:
    """
    Measure device response at specific threshold and collect events

    Sets detection thresholds on specified channels and reads detection events with
    flexible collection modes: count-based (default) or time-based.

    The threshold argument uses format: "channel:value;channel:value" (e.g., "1:300;2:300;3:300").
    Even if you specify only some channels (e.g., "1:300;3:330"), all three threshold values
    (threshold1, threshold2, threshold3) will be included in each event, with unmodified
    channels retaining their previous values.

    Example:
        ```bash
        # Count-based: Measure 1000 events at 300 ADC on all channels (default)
        kazunoko measure "1:300;2:300;3:300" 1000

        # Count-based: Different channels with different thresholds
        kazunoko measure "1:500;2:300;3:300" 500 --port /dev/ttyUSB0

        # Time-based: Measure for 60 seconds
        kazunoko measure "1:300;2:300;3:300" 60 --use-sec

        # Time-based: Collect for 30 seconds with different thresholds
        kazunoko measure "1:500;2:300;3:300" 30 --use-sec -v

        # Output in JSON format for processing
        kazunoko measure "1:300;2:300;3:300" 100 --format json | jq '.threshold1'

        # Adjust polling and communication timeouts
        kazunoko measure "1:300;2:300;3:300" 1000 --poll-count 25000 --timeout 0.5

        # Use mock device for testing
        kazunoko measure "1:300;2:300;3:300" 100 --mock
        ```
    """
    try:
        thresholds = parse_thresholds(value)
    except ValueError as e:
        stderr.print(f"[red]✗ Invalid threshold format: {e}[/red]")
        logger.error(f"Invalid threshold format: {e}")
        raise typer.Exit(code=1)

    try:
        if verbose:
            port_display = port if port != "auto" else "auto-detected port"
            stderr.print(f"[blue]Connecting to {port_display}...[/blue]")

        # Connect to device
        dev = device(port=port, mock=mock, timeout=timeout)

        with dev:
            if verbose:
                stderr.print(f"[green]✓ Connected to {dev.port}[/green]")
                stderr.print(f"[blue]Setting thresholds: {thresholds}[/blue]")

            logger.info(
                "Starting measurement session",
                extra={
                    "device": dev.port,
                    "thresholds": str(thresholds),
                    "poll_count": poll_count,
                }
            )

            # Create measurement session
            config = MeasureConfig(
                thresholds=thresholds,
                poll_count=poll_count,
                event_timeout=event_timeout,
            )
            measure = Measure(dev, config)

            # Setup measurement
            measure.setup()
            logger.info("Thresholds set successfully")

            if verbose:
                stderr.print("[green]✓ Thresholds set[/green]")
                if use_event:
                    stderr.print(
                        f"[blue]Streaming {events_or_secs} events "
                        "(Ctrl+C to stop)...[/blue]\n"
                    )
                else:
                    stderr.print(
                        f"[blue]Streaming for {events_or_secs} seconds "
                        "(Ctrl+C to stop)...[/blue]\n"
                    )

            # Set device time to current PC time
            measure.set_rtc_time()
            logger.info("Device time synchronized")

            # Stream detection events with metadata automatically merged
            logger.info(
                "Starting event streaming",
                extra={
                    "mode": "count" if use_event else "duration",
                    "value": events_or_secs,
                }
            )
            if use_event:
                # Count-based streaming with progress bar
                with Progress(console=stderr) as progress:
                    task = progress.add_task("[cyan]Collecting events...", total=events_or_secs)
                    for measured_event in measure.stream_by_count(events_or_secs):
                        _display_response(measured_event, format, use_flat)
                        progress.update(task, advance=1)
            else:
                # Time-based streaming
                for measured_event in measure.stream_by_time(float(events_or_secs)):
                    _display_response(measured_event, format, use_flat)

            # Get streaming statistics
            stats = measure.stats
            logger.info(
                "Measurement completed",
                extra={
                    "total_yielded": stats.total_yielded,
                    "total_skipped": stats.total_skipped,
                    "skipped_timeout": stats.skipped_timeout,
                    "skipped_protocol": stats.skipped_protocol,
                    "skipped_response": stats.skipped_response,
                    "success_rate": stats.success_rate,
                }
            )
            if verbose:
                stderr.print(
                    f"\n[green]✓ Total events received: {stats.total_yielded}[/green]"
                )
                if stats.total_skipped > 0:
                    pct = stats.success_rate
                    skipped_msg = (
                        f"[yellow]⚠ Skipped events: {stats.total_skipped} "
                        f"({pct:.1f}% success)[/yellow]"
                    )
                    stderr.print(skipped_msg)
                    stderr.print(f"[cyan]  - Timeout: {stats.skipped_timeout}[/cyan]")
                    stderr.print(f"[cyan]  - Protocol errors: {stats.skipped_protocol}[/cyan]")
                    stderr.print(f"[cyan]  - Response errors: {stats.skipped_response}[/cyan]")

    except KeyboardInterrupt:
        stderr.print("\n[yellow]Interrupted by user[/yellow]")
        logger.info("Measurement interrupted by user")
        raise typer.Exit(code=0)

    except CommandTimeout:
        stderr.print("[red]✗ Command timeout: device did not respond[/red]")
        logger.error("Command timeout: device did not respond", exc_info=True)
        raise typer.Exit(code=1)

    except KazunokoError as e:
        stderr.print(f"[red]✗ Error: {e}[/red]")
        logger.error(f"Measurement failed: {e}", exc_info=True)
        raise typer.Exit(code=1)

read

kazunoko.cli.read(events_or_secs=typer.Argument(..., help='Number of events (--use-event) or duration in seconds (--use-sec)'), port=Options.port(), timeout=Options.timeout(), event_timeout=Options.event_timeout(), verbose=Options.verbose(), format=Options.format('jsonl'), use_flat=Options.use_flat(True), use_event=Options.use_event(), mock=MockOptions.mock())

Read detection events from device (data stream)

Continuously receive and display detection data events. Supports two collection modes: count-based (default) or time-based via option toggle.

Count-based mode (default): Reads exactly N events. Each event waits up to event_timeout seconds. If no event is received within event_timeout, tries next event.

Time-based mode (--use-sec): Reads events continuously for T seconds. Each event waits up to event_timeout seconds to arrive.

Supports multiple output formats (JSONL, table, JSON, CSV). By default uses flattened structure for compact output. Press Ctrl+C to stop.

Example
# Count-based (default): Read exactly 10 events
kazunoko read 10

# Count-based: Read 100 events with custom timeout
kazunoko read 100 --event-timeout 3.0

# Time-based: Read for 60 seconds
kazunoko read 60 --use-sec

# Time-based: Read for 30 seconds with verbose output
kazunoko read 30 --use-sec -v

# Output in CSV format
kazunoko read 10 --format csv > events.csv

# Read for 120 seconds with custom serial timeout
kazunoko read 120 --use-sec --timeout 0.5

# Use mock device for testing without hardware
kazunoko read 10 --mock

# Mock device with time-based collection
kazunoko read 30 --mock --use-sec
Source code in src/kazunoko/cli.py
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
@app.command()
def read(
    events_or_secs: int = typer.Argument(
        ..., help="Number of events (--use-event) or duration in seconds (--use-sec)"
    ),
    port: str = Options.port(),
    timeout: float = Options.timeout(),
    event_timeout: float = Options.event_timeout(),
    verbose: bool = Options.verbose(),
    format: Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"] = Options.format("jsonl"),
    use_flat: bool = Options.use_flat(True),
    use_event: bool = Options.use_event(),
    mock: bool = MockOptions.mock(),
) -> None:
    """
    Read detection events from device (data stream)

    Continuously receive and display detection data events.
    Supports two collection modes: count-based (default) or time-based via option toggle.

    Count-based mode (default):
        Reads exactly N events. Each event waits up to event_timeout seconds.
        If no event is received within event_timeout, tries next event.

    Time-based mode (--use-sec):
        Reads events continuously for T seconds.
        Each event waits up to event_timeout seconds to arrive.

    Supports multiple output formats (JSONL, table, JSON, CSV).
    By default uses flattened structure for compact output.
    Press Ctrl+C to stop.

    Example:
        ```bash
        # Count-based (default): Read exactly 10 events
        kazunoko read 10

        # Count-based: Read 100 events with custom timeout
        kazunoko read 100 --event-timeout 3.0

        # Time-based: Read for 60 seconds
        kazunoko read 60 --use-sec

        # Time-based: Read for 30 seconds with verbose output
        kazunoko read 30 --use-sec -v

        # Output in CSV format
        kazunoko read 10 --format csv > events.csv

        # Read for 120 seconds with custom serial timeout
        kazunoko read 120 --use-sec --timeout 0.5

        # Use mock device for testing without hardware
        kazunoko read 10 --mock

        # Mock device with time-based collection
        kazunoko read 30 --mock --use-sec
        ```
    """
    try:
        if verbose:
            port_display = port if port != "auto" else "auto-detected port"
            stderr.print(f"[blue]Connecting to {port_display}...[/blue]")

        dev = device(port=port, mock=mock, timeout=timeout)

        with dev:
            if verbose:
                stderr.print(f"[green]✓ Connected to {dev.port}[/green]")
                if use_event:
                    stderr.print(
                        f"[blue]Reading {events_or_secs} events "
                        "(Ctrl+C to stop)...[/blue]\n"
                    )
                else:
                    stderr.print(
                        f"[blue]Reading for {events_or_secs} seconds "
                        "(Ctrl+C to stop)...[/blue]\n"
                    )

            # Create reader and set device time
            reader = Reader(dev, event_timeout=event_timeout)
            try:
                reader.set_rtc_time()
                if verbose:
                    stderr.print("[blue]Device time synchronized[/blue]")
                logger.info("Device time synchronized")
            except (CommandTimeout, ResponseTimeout, KazunokoError):
                if verbose:
                    msg = "[yellow]⚠ Failed to set device time[/yellow]"
                    stderr.print(msg)
                logger.warning("Failed to set device time")

            # Stream detection events with metadata automatically merged
            logger.info(
                "Starting event collection",
                extra={
                    "mode": "count" if use_event else "duration",
                    "value": events_or_secs,
                    "device": dev.port,
                }
            )
            if use_event:
                # Count-based streaming with progress bar
                with Progress(console=stderr) as progress:
                    task = progress.add_task("[cyan]Reading events...", total=events_or_secs)
                    for event_data in reader.stream_by_count(events_or_secs):
                        _display_response(event_data, format, use_flat)
                        progress.update(task, advance=1)
            else:
                # Time-based streaming
                for event_data in reader.stream_by_time(float(events_or_secs)):
                    _display_response(event_data, format, use_flat)

            # Get streaming statistics
            stats = reader.stats
            logger.info(
                "Event collection completed",
                extra={
                    "total_yielded": stats.total_yielded,
                    "total_skipped": stats.total_skipped,
                    "skipped_timeout": stats.skipped_timeout,
                    "skipped_protocol": stats.skipped_protocol,
                    "skipped_response": stats.skipped_response,
                    "success_rate": stats.success_rate,
                }
            )
            if verbose:
                stderr.print(
                    f"\n[green]✓ Total events received: {stats.total_yielded}[/green]"
                )
                if stats.total_skipped > 0:
                    pct = stats.success_rate
                    skipped_msg = (
                        f"[yellow]⚠ Skipped events: {stats.total_skipped} "
                        f"({pct:.1f}% success)[/yellow]"
                    )
                    stderr.print(skipped_msg)
                    stderr.print(f"[cyan]  - Timeout: {stats.skipped_timeout}[/cyan]")
                    stderr.print(f"[cyan]  - Protocol errors: {stats.skipped_protocol}[/cyan]")
                    stderr.print(f"[cyan]  - Response errors: {stats.skipped_response}[/cyan]")

    except KeyboardInterrupt:
        stderr.print("\n[yellow]Interrupted by user[/yellow]")
        logger.info("Event collection interrupted by user")
        raise typer.Exit(code=0)

    except KazunokoError as e:
        stderr.print(f"[red]✗ Error: {e}[/red]")
        logger.error(f"Event collection failed: {e}", exc_info=True)
        raise typer.Exit(code=1)

threshold

kazunoko.cli.threshold(value=typer.Argument(..., help="Threshold value (e.g., '1:300;2:300;3:300')"), port=Options.port(), timeout=Options.timeout(), verbose=Options.verbose(), format=Options.format('jsonl'), use_flat=Options.use_flat(True), mock=MockOptions.mock())

Set device threshold values

Configure detection threshold values for the device.

Example
kazunoko threshold "1:300;2:300;3:300"
kazunoko threshold "1:300;2:300;3:300" --port /dev/ttyUSB0
kazunoko threshold "1:300;2:300;3:300" -v
kazunoko threshold "1:300;2:300;3:300" --mock
kazunoko threshold "1:300;2:300;3:300" --timeout 0.5
Source code in src/kazunoko/cli.py
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
@app.command()
@handle_kazunoko_errors
def threshold(
    value: str = typer.Argument(..., help="Threshold value (e.g., '1:300;2:300;3:300')"),
    port: str = Options.port(),
    timeout: float = Options.timeout(),
    verbose: bool = Options.verbose(),
    format: Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"] = Options.format("jsonl"),
    use_flat: bool = Options.use_flat(True),
    mock: bool = MockOptions.mock(),
) -> None:
    """
    Set device threshold values

    Configure detection threshold values for the device.

    Example:
        ```bash
        kazunoko threshold "1:300;2:300;3:300"
        kazunoko threshold "1:300;2:300;3:300" --port /dev/ttyUSB0
        kazunoko threshold "1:300;2:300;3:300" -v
        kazunoko threshold "1:300;2:300;3:300" --mock
        kazunoko threshold "1:300;2:300;3:300" --timeout 0.5
        ```
    """
    try:
        thresholds = parse_thresholds(value)
    except ValueError as e:
        stderr.print(f"[red]✗ Invalid threshold format: {e}[/red]")
        raise typer.Exit(code=1)

    if verbose:
        if mock:
            device_info = "mock device"
        else:
            device_info = port if port else "auto-detected port"
        stderr.print(f"[blue]Connecting to {device_info}...[/blue]")

    with device(port, mock, timeout) as detector:
        if verbose:
            stderr.print(f"[green]✓ Connected to {detector.port}[/green]")
            stderr.print(f"[blue]Sending: SET_THRESHOLD {thresholds}[/blue]")

        cmd = Command(detector)
        responses = cmd.thresholds(thresholds)

        if verbose:
            stderr.print("[green]✓ Response received[/green]\n")

        # Display responses with specified format
        for response in responses:
            _display_response(response, format, use_flat)

status

kazunoko.cli.status(port=Options.port(), timeout=Options.timeout(), verbose=Options.verbose(), format=Options.format('jsonl'), use_flat=Options.use_flat(True), mock=MockOptions.mock())

Display diagnostic information

Collects and displays comprehensive diagnostic information including:

  • Library versions (kazunoko and dependencies)
  • Python environment (version, virtual environment)
  • Platform information (OS, architecture)
  • Serial port information (available ports, accessibility)
  • Device information (firmware, MAC address, status, uptime) - only if --mock is not used

Use --mock to collect only environment information without connecting to device. Supports multiple output formats (table, JSONL, JSON, CSV).

Example
kazunoko status
kazunoko status --mock
kazunoko status --port /dev/ttyUSB0
kazunoko status -v
kazunoko status --format table
kazunoko status --format json | jq .kazunoko_version
kazunoko status --timeout 0.5
Source code in src/kazunoko/cli.py
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
@app.command()
@handle_kazunoko_errors
def status(
    port: str = Options.port(),
    timeout: float = Options.timeout(),
    verbose: bool = Options.verbose(),
    format: Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"] = Options.format("jsonl"),
    use_flat: bool = Options.use_flat(True),
    mock: bool = MockOptions.mock(),
) -> None:
    """
    Display diagnostic information

    Collects and displays comprehensive diagnostic information including:

    - Library versions (kazunoko and dependencies)
    - Python environment (version, virtual environment)
    - Platform information (OS, architecture)
    - Serial port information (available ports, accessibility)
    - Device information (firmware, MAC address, status, uptime) - only if --mock is not used

    Use --mock to collect only environment information without connecting to device.
    Supports multiple output formats (table, JSONL, JSON, CSV).

    Example:
        ```bash
        kazunoko status
        kazunoko status --mock
        kazunoko status --port /dev/ttyUSB0
        kazunoko status -v
        kazunoko status --format table
        kazunoko status --format json | jq .kazunoko_version
        kazunoko status --timeout 0.5
        ```
    """
    from dataclasses import asdict

    from .doctor import DiagnosticInfo
    from .parser import DeviceResponse

    if verbose:
        if mock:
            stderr.print("[blue]Collecting diagnostic information (mock device)...[/blue]")
        else:
            device_info = port if port else "auto-detected port"
            stderr.print(f"[blue]Collecting diagnostic information from {device_info}...[/blue]")

    # Collect diagnostics with device (mock or real)
    with device(port, mock, timeout) as detector:
        if verbose:
            stderr.print(f"[green]✓ Connected to {detector.port}[/green]")

        logger.info("Collecting diagnostic information", extra={"device": detector.port, "mock": mock})
        diagnostics = DiagnosticInfo.collect(detector)

    logger.info("Diagnostic information collected")
    if verbose:
        stderr.print("[green]✓ Diagnostic information collected[/green]\n")

    # Convert DiagnosticInfo to nested dict for ResponseFormatter
    diag_dict = asdict(diagnostics)

    response = DeviceResponse(type="response", status="ok", **diag_dict)

    _display_response(response, format, use_flat)

query

kazunoko.cli.query(command=typer.Argument(..., help='Command to send (e.g., STATUS, GET_VERSION)'), port=Options.port(), timeout=Options.timeout(), verbose=Options.verbose(), format=Options.format('jsonl'), use_flat=Options.use_flat(True), mock=MockOptions.mock())

Query device and display response

Supports multiple output formats (table, JSONL, JSON, CSV). Use --use-flat to output flattened keys for scripting/data pipelines.

Example
kazunoko query STATUS
kazunoko query "SET_POLL_COUNT 200" --port /dev/ttyUSB0
kazunoko query GET_VERSION -v
kazunoko query STATUS --mock
kazunoko query STATUS --format jsonl
kazunoko query STATUS --format table --use-flat
kazunoko query STATUS --format json | jq .timestamp
kazunoko query STATUS --timeout 0.5
Source code in src/kazunoko/cli.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@app.command()
@handle_kazunoko_errors
def query(
    command: str = typer.Argument(..., help="Command to send (e.g., STATUS, GET_VERSION)"),
    port: str = Options.port(),
    timeout: float = Options.timeout(),
    verbose: bool = Options.verbose(),
    format: Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"] = Options.format("jsonl"),
    use_flat: bool = Options.use_flat(True),
    mock: bool = MockOptions.mock(),
) -> None:
    """
    Query device and display response

    Supports multiple output formats (table, JSONL, JSON, CSV).
    Use --use-flat to output flattened keys for scripting/data pipelines.

    Example:
        ```bash
        kazunoko query STATUS
        kazunoko query "SET_POLL_COUNT 200" --port /dev/ttyUSB0
        kazunoko query GET_VERSION -v
        kazunoko query STATUS --mock
        kazunoko query STATUS --format jsonl
        kazunoko query STATUS --format table --use-flat
        kazunoko query STATUS --format json | jq .timestamp
        kazunoko query STATUS --timeout 0.5
        ```
    """
    if verbose:
        if mock:
            device_info = "mock device"
        else:
            device_info = port if port else "auto-detected port"
        stderr.print(f"[blue]Connecting to {device_info}...[/blue]")

    with device(port, mock, timeout) as detector:
        if verbose:
            stderr.print(f"[green]✓ Connected to {detector.port}[/green]")
            stderr.print(f"[blue]Sending: {command}[/blue]")

        logger.info("Executing command", extra={"command": command, "device": detector.port})
        response = detector.query(command)
        logger.info("Command succeeded", extra={"command": command, "device": detector.port})

        if verbose:
            stderr.print("[green]✓ Response received[/green]\n")

        _display_response(response, format, use_flat)

reset

kazunoko.cli.reset(port=Options.port(), timeout=Options.timeout(), verbose=Options.verbose(), format=Options.format('jsonl'), use_flat=Options.use_flat(True), mock=MockOptions.mock())

Reset device configuration to defaults

Resets all device settings to their default values and sets all thresholds to 0.

Example
kazunoko reset
kazunoko reset --port /dev/ttyUSB0
kazunoko reset -v
kazunoko reset --mock
kazunoko reset --timeout 0.5
Source code in src/kazunoko/cli.py
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
@app.command()
@handle_kazunoko_errors
def reset(
    port: str = Options.port(),
    timeout: float = Options.timeout(),
    verbose: bool = Options.verbose(),
    format: Literal["table", "jsonl", "json", "csv", "ssv", "tsv", "ltsv"] = Options.format("jsonl"),
    use_flat: bool = Options.use_flat(True),
    mock: bool = MockOptions.mock(),
) -> None:
    """Reset device configuration to defaults

    Resets all device settings to their default values and sets all thresholds to 0.

    Example:
        ```bash
        kazunoko reset
        kazunoko reset --port /dev/ttyUSB0
        kazunoko reset -v
        kazunoko reset --mock
        kazunoko reset --timeout 0.5
        ```
    """
    if verbose:
        if mock:
            device_info = "mock device"
        else:
            device_info = port if port else "auto-detected port"
        stderr.print(f"[blue]Connecting to {device_info}...[/blue]")

    with device(port, mock, timeout) as detector:
        if verbose:
            stderr.print(f"[green]✓ Connected to {detector.port}[/green]")
            stderr.print("[blue]Sending: RESET[/blue]")

        cmd = Command(detector)
        response = cmd.reset()

        if verbose:
            stderr.print("[green]✓ Response received[/green]")
            stderr.print("[blue]Setting thresholds to 0 for all channels...[/blue]")

        # Set all thresholds to 0
        cmd.thresholds({1: 0, 2: 0, 3: 0})

        if verbose:
            stderr.print("[green]✓ Thresholds set[/green]\n")

        _display_response(response, format, use_flat)

version

kazunoko.cli.version(port=typer.Option('auto', '--port', '-p', help="Serial port or 'auto' for auto-detection"), timeout=Options.timeout(), verbose=typer.Option(False, '--verbose', '-v', help='Verbose output'))

Show version information

Displays kazunoko library version and device firmware version (if connected).

Example
kazunoko version
kazunoko version --port /dev/ttyUSB0
kazunoko version -v
kazunoko version --timeout 0.5
Source code in src/kazunoko/cli.py
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
@app.command()
def version(
    port: str = typer.Option(
        "auto", "--port", "-p", help="Serial port or 'auto' for auto-detection"
    ),
    timeout: float = Options.timeout(),
    verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"),
) -> None:
    """Show version information

    Displays kazunoko library version and device firmware version (if connected).

    Example:
        ```bash
        kazunoko version
        kazunoko version --port /dev/ttyUSB0
        kazunoko version -v
        kazunoko version --timeout 0.5
        ```
    """
    stdout.print(f"kazunoko {__version__}")

    try:
        if verbose:
            port_display = port if port != "auto" else "auto-detected port"
            stderr.print(f"[blue]Connecting to {port_display} to get device version...[/blue]")

        with connect(port, timeout=timeout) as device:
            if verbose:
                stderr.print(f"[green]✓ Connected to {device.port}[/green]")
                stderr.print("[blue]Sending: GET_VERSION[/blue]")

            response = device.query("GET_VERSION")

            if verbose:
                stderr.print("[green]✓ Response received[/green]")

            # Display device version
            stdout.print(f"kurikintons {response.version}")

    except (CommandTimeout, ResponseTimeout, KazunokoError):
        # If device connection fails, just show library version
        # No error message unless verbose
        if verbose:
            stderr.print("[yellow]⚠ Could not connect to device[/yellow]")