Skip to content

hamslices/LarkAPI

Repository files navigation

Lark C++ API

Version: 01.00.56
Author: HamSlices
License: GNU General Public License v3.0

The Lark C++ API is a powerful, thread-safe, and comprehensive library for controlling the Lark Print Engine from your own Windows applications. It provides a high-level, object-oriented interface to manage every aspect of the device, from simple printing to advanced diagnostics and firmware updates.

alt text

Building from Source

Prerequisites

  • Windows OS
  • Git
  • Visual Studio 2022 with the C++ Desktop Development workload.

Build Steps

1. Clone the Repository

Clone the repository using the --recurse-submodules flag to automatically download the required vcpkg dependency manager.

git clone --recurse-submodules https://github.com/hamslices/LarkAPI.git
cd LarkAPI

2. Bootstrap vcpkg

Run the bootstrap script to prepare vcpkg. This only needs to be done once per clone.

.\vcpkg\bootstrap-vcpkg.bat

3. Install Dependencies

This project uses vcpkg to manage all external libraries. The manifest file (vcpkg.json) will handle this automatically. Simply build the project in Visual Studio, and it will install all necessary dependencies.

4. Build the Solution

Open the Visual Studio solution (Lark.sln) and build the project in the desired configuration (e.g., Release). The output library (Lark.lib) and DLL (Lark.dll) will be generated.

Key Features

  • Instance-Based Thread Safety: Control multiple Lark printers from different threads simultaneously without any global state interference.
  • Synchronous & Asynchronous Operations: Choose between simple blocking calls for scripts or non-blocking async functions for responsive user interfaces.
  • Event-Driven Callbacks: Register callback functions for real-time events like print progress, job completion, and device faults.
  • Comprehensive Printing & Text Rendering:
    • Render from image files (JPG, PNG), multi-page PDFs, and raw in-memory grayscale buffers.
    • Full Unicode Text Support with automatic encoding detection, tab-stop handling, and optional line numbering.
  • On-the-Fly Image Processing: Programmatically control a full pipeline of image transformations, including dithering, scaling, rotation, brightness/contrast, and padding.
  • Full Device Configuration: Programmatically get and set all device parameters using high-level units (IPS/MMPS) or low-level hardware settings.
  • Complete Diagnostics Suite: Query real-time status, temperature, firmware version, a persistent fault log, and lifetime usage statistics.
  • Robust Firmware Updates: A single, non-blocking update_firmware_async function handles the entire DFU process.
  • Integrated Logging: Redirect the API's detailed internal logs to your application's own logging framework via a simple callback.

How to Use

To use the Lark API, you must link against Lark.lib and ensure Lark.dll and its dependencies (like freetype.dll, poppler.dll, etc.) are available at runtime.

Basic Connection Example

This example connects to the device and retrieves its firmware version.

#include <iostream>
#include "lark.h"
#include "larkDefs.h" // For FIRMWARE_VERSION_SIZE

// Define your device's USB properties
#define VENDOR_ID    0x1209
#define PRODUCT_ID   0xABD1

int main() {
    Lark printer;

    std::cout << "Attempting to connect to device..." << std::endl;
    LarkResult result = printer.open(VENDOR_ID, PRODUCT_ID);

    if (result != LARK_SUCCESS) {
        std::cerr << "Failed to open device. Reason: " << lark_error_to_string(result) << std::endl;
        return -1;
    }

    std::cout << "Device connection successful." << std::endl;

    char version_buffer[FIRMWARE_VERSION_SIZE];
    result = printer.get_firmware_version(version_buffer, FIRMWARE_VERSION_SIZE);

    if (result == LARK_SUCCESS) {
        std::cout << "Firmware Version: " << version_buffer << std::endl;
        std::cout << "API Version: " << Lark::get_api_version() << std::endl;
    } else {
        std::cerr << "Failed to get firmware version. Reason: " << lark_error_to_string(result) << std::endl;
    }

    return 0;
}

Integrating the Logging System

Redirect the API's detailed internal logs to your application's console, log file, or UI by providing a callback function.

#include "lark.h"
#include <iostream>

// 1. Define your logging function.
void my_logger(LogLevel level, const char* message, void* user_data) {
    // ... (implementation from your original README)
    std::cout << "API Log -> " << message << std::endl;
}

int main() {
    Lark printer;
    // 2. Register your logging function.
    printer.set_log_callback(my_logger, nullptr);

    // Now, all internal operations will produce logs through your function.
    printer.open(VENDOR_ID, PRODUCT_ID);
    // ...
    return 0;
}

API Reference

Initialization & Connection

  • open(): Connect to the Lark device via USB.
  • is_connected(): Check if the connection is currently active.
  • set_log_callback(): Redirect internal API logs.
  • set_event_callbacks(): Register functions for real-time events.
  • get_api_version(): Get the version of the Lark API library.

Device Status & Diagnostics

  • is_job_active(): Check if an async job is running.
  • get_status(), get_realtime_status(): Get PrintStatus bitmask.
  • get_temperature(), get_firmware_version(), get_serial(), get_UID().
  • get_fault_log_count(), get_fault_log_entries().
  • get_lifetime_stats().

Printing & Rendering

  • send_image(), send_pdf(), send_text(), send_text_doc().
  • send_from_memory(): Print from a raw grayscale pixel buffer.
  • send_head_test_pattern().
  • send_image_async(), send_pdf_async(), send_text_async(), etc.

Configuration

  • get_bulk_config() / set_bulk_config().
  • set_IPS() / get_IPS(), set_MMPS() / get_MMPS().
  • set_motor_current(), set_step_resolution(), set_darkness().

Motion & System Control

  • move_media(), move_inches(), move_mm().
  • reset_system(), bootloader(), purge_buffers(), self_test().
  • clear_faults(), clear_all_faults().

Non-Volatile Memory

  • save_to_flash(), load_from_flash(), erase_flash().

Firmware & DFU

  • update_firmware() / update_firmware_async().
  • dfu_erase_bank_one(), dfu_program_firmware(), dfu_reboot().

Lark Print Engine Windows API © HamSlices 2025

The Lark Project

About

Lark API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages