C / C++

The TiJet C SDK provides device connection, parameter access, printing, print control, upgrade, event, log, and version APIs.

Quick Start

#include <tijet/tijet.h>

ti_client_t *cli = ti_create();
if (cli == NULL) {
    return 1;
}

if (ti_connect(cli, NULL) != TI_OK) {
    fprintf(stderr, "%s\n", ti_last_error(cli));
    ti_destroy(cli);
    return 1;
}

ti_set_int(cli, TI_PARAM_PRINT_SPEED_TIMER, 10000);

ti_disconnect(cli);
ti_destroy(cli);

C++ Compatibility

C++ applications use the same <tijet/tijet.h> header, the same TI_PARAM_* constants, and the same function calls shown in the Quick Start. No separate C++ SDK or header is required.

Types

ti_client_t

Opaque client handle. Create it with ti_create() and release it with ti_destroy().

ti_event_callback_t

typedef void (*ti_event_callback_t)(const char *event_json, void *user_data);
  • event_json: Event data. The pointer is valid only during the callback.
  • user_data: Value registered with ti_set_event_callback().

ti_log_callback_t

typedef void (*ti_log_callback_t)(const char *log_line, void *user_data);
  • log_line: Log text. The pointer is valid only during the callback.
  • user_data: Value registered with ti_set_log_callback().

Lifecycle

ti_create

ti_client_t *ti_create(void);

Creates a client handle.

  • Parameters: None.
  • Returns: A non-NULL handle on success, or NULL if the client cannot be allocated.
  • Notes: The returned handle must be released with ti_destroy().

ti_destroy

void ti_destroy(ti_client_t *client);

Stops event and log subscriptions, disconnects, and releases the client.

ParameterTypeDirectionDescription
clientti_client_t *inputClient handle. NULL is allowed and ignored.
  • Returns: Nothing.

Connection

ti_connect

int ti_connect(ti_client_t *client, const char *address);

Connects to a device.

ParameterTypeDirectionDescription
clientti_client_t *inputClient handle created by ti_create().
addressconst char *inputDevice address. NULL or an empty string uses the default local device. host:port selects TCP; other non-empty values select a local device path.
  • Returns:
    • TI_OK: Connection is ready.
    • TI_ERR_INVALID_ARG: client is NULL.
    • TI_ERR_TIMEOUT: Connection was not ready before the timeout.
  • Notes: Calling this function on an existing connection disconnects it first.

ti_disconnect

int ti_disconnect(ti_client_t *client);

Stops subscriptions and disconnects the client.

ParameterTypeDirectionDescription
clientti_client_t *inputClient handle.
  • Returns:
    • TI_OK: Disconnected, or the client was already disconnected.
    • TI_ERR_INVALID_ARG: client is NULL.

ti_is_connected

int ti_is_connected(const ti_client_t *client);

Checks whether the connection is currently usable.

ParameterTypeDirectionDescription
clientconst ti_client_t *inputClient handle.
  • Returns: 1 when connected and usable; 0 when disconnected or client is NULL.

ti_network_config

int ti_network_config(ti_client_t *client,
                      const char *ip,
                      const char *ip_mask,
                      const char *gateway);

Configures device network settings.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
ipconst char *inputIPv4 address, or NULL / empty to leave unchanged.
ip_maskconst char *inputSubnet mask, or NULL / empty to leave unchanged.
gatewayconst char *inputDefault gateway, or NULL / empty to leave unchanged.
  • Returns:
    • TI_OK: Settings accepted.
    • TI_ERR_INVALID_ARG: client is NULL or all three settings are empty.
    • TI_ERR_NOT_CONNECTED: Client is not connected.
    • TI_ERR_SERVER: Device rejected the settings.

Parameters

ti_set_parameter

int ti_set_parameter(ti_client_t *client,
                     const char *key,
                     const char *value);

Sets a parameter using its string representation.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
keyconst char *inputCase-sensitive parameter key from the parameter reference.
valueconst char *inputString value. Booleans use "true" or "false".
  • Returns:
    • TI_OK: Parameter accepted.
    • TI_ERR_INVALID_ARG: Any argument is NULL.
    • TI_ERR_NOT_CONNECTED: Client is not connected.
    • TI_ERR_SERVER: Device rejected the key or value.

ti_get_parameter

int ti_get_parameter(const ti_client_t *client,
                     const char *key,
                     char *value_buf,
                     size_t buf_size);

Reads a parameter into a caller-owned buffer.

ParameterTypeDirectionDescription
clientconst ti_client_t *inputConnected client handle.
keyconst char *inputCase-sensitive parameter key.
value_bufchar *outputDestination buffer.
buf_sizesize_tinputBuffer capacity in bytes, including space for the terminating null character. Must be greater than zero.
  • Returns:
    • TI_OK: Value copied successfully.
    • TI_ERR_INVALID_ARG: client, key, or value_buf is NULL.
    • TI_ERR_NOT_CONNECTED: Client is not connected.
    • TI_ERR_BUFFER_TOO_SMALL: Output was truncated because the buffer was too small.
    • TI_ERR_SERVER: Device does not provide the key.

ti_set_int

int ti_set_int(ti_client_t *client, const char *key, int32_t value);

Sets an int32 parameter.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
keyconst char *inputParameter key.
valueint32_tinputInteger value.
  • Returns: Same status values as ti_set_parameter().

ti_get_int

int ti_get_int(const ti_client_t *client, const char *key, int32_t *out);

Reads an int32 parameter.

ParameterTypeDirectionDescription
clientconst ti_client_t *inputConnected client handle.
keyconst char *inputParameter key.
outint32_t *outputReceives the parsed integer. Must not be NULL.
  • Returns: Same status values as ti_get_parameter().

ti_set_double

int ti_set_double(ti_client_t *client, const char *key, double value);

Sets a double parameter.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
keyconst char *inputParameter key.
valuedoubleinputDouble value.
  • Returns: Same status values as ti_set_parameter().

ti_get_double

int ti_get_double(const ti_client_t *client, const char *key, double *out);

Reads a double parameter.

ParameterTypeDirectionDescription
clientconst ti_client_t *inputConnected client handle.
keyconst char *inputParameter key.
outdouble *outputReceives the parsed value. Must not be NULL.
  • Returns: Same status values as ti_get_parameter().

ti_set_bool

int ti_set_bool(ti_client_t *client, const char *key, int value);

Sets a boolean parameter.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
keyconst char *inputParameter key.
valueintinputNon-zero stores "true"; zero stores "false".
  • Returns: Same status values as ti_set_parameter().

ti_get_bool

int ti_get_bool(const ti_client_t *client, const char *key, int *out);

Reads a boolean parameter.

ParameterTypeDirectionDescription
clientconst ti_client_t *inputConnected client handle.
keyconst char *inputParameter key.
outint *outputReceives 1 for "true" / "1", otherwise 0. Must not be NULL.
  • Returns: Same status values as ti_get_parameter().

C _X Key Macros

Parameters containing _X use function-like macros. Pass a literal number:

ti_get_double(cli, TI_PARAM_INK_CARD_INK_TOTAL(1), &ink_total);

The argument is converted to text by the preprocessor. A runtime variable is stringified as the variable name. For dynamic numbers, construct the key explicitly:

char key[64];
snprintf(key, sizeof(key), "INK_CARD_INK_TOTAL_%u", head_no);
ti_get_double(cli, key, &ink_total);

Printing

ti_set_print_data

int ti_set_print_data(ti_client_t *client,
                      const uint8_t *data,
                      size_t data_len,
                      uint32_t index);

Uploads one set of print data.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
dataconst uint8_t *inputPrint-data bytes. Must not be NULL.
data_lensize_tinputNumber of bytes. Must be greater than zero.
indexuint32_tinputApplication-defined print-data sequence number.
  • Returns:
    • TI_OK: Upload completed.
    • TI_ERR_INVALID_ARG: A required argument is invalid.
    • TI_ERR_NOT_CONNECTED: Client is not connected.
    • TI_ERR_SERVER: Device rejected the data or communication failed.
  • Notes: TI_OK does not mean the device is ready to print. Use the print-start result notification as the final startup result.

ti_print_control

int ti_print_control(ti_client_t *client, const char *key);

Executes a print-control command.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
keyconst char *inputUppercase command key: "START_PRINT", "STOP_PRINT", "PAUSE_PRINT", "RESUME_PRINT", or "ANALOG_TRIGGER".
  • Returns:
    • TI_OK: Command accepted.
    • TI_ERR_INVALID_ARG: client / key is NULL, or the key is unsupported.
    • TI_ERR_NOT_CONNECTED: Client is not connected.
    • TI_ERR_SERVER: Device rejected or failed the command.

Upgrade

ti_upgrade

int ti_upgrade(ti_client_t *client,
               const char *key,
               const char *file_path);

Uploads an upgrade file.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
keyconst char *inputUpgrade target. Use TI_UPGRADE_TARGET_SYSTEM for a full-system upgrade. Must not be empty.
file_pathconst char *inputPath to an existing non-empty file. Maximum size is 256 MiB.
  • Returns:
    • TI_OK: Upload completed; the device started processing the file.
    • TI_ERR_INVALID_ARG: Arguments are invalid or the file cannot be used.
    • TI_ERR_NOT_CONNECTED: Client is not connected.
    • TI_ERR_TIMEOUT: Upload timed out.
    • TI_ERR_SERVER: Device rejected the file or communication failed.
  • Notes: This is a blocking call with an upload timeout of up to 300 seconds. Do not call it from a UI thread. TI_OK does not mean the upgrade file is ready; use upgrade-status notifications.

Events

ti_set_event_callback

void ti_set_event_callback(ti_client_t *client,
                           ti_event_callback_t callback,
                           void *user_data);

Registers or clears the event callback.

ParameterTypeDirectionDescription
clientti_client_t *inputClient handle. NULL is ignored.
callbackti_event_callback_tinputCallback function, or NULL to clear it.
user_datavoid *inputOpaque pointer passed to the callback. May be NULL.
  • Returns: Nothing.
  • Notes: Call before ti_start_event_subscription(). Do not block for long periods inside the callback.

ti_start_event_subscription

int ti_start_event_subscription(ti_client_t *client);

Starts event notifications.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
  • Returns:
    • TI_OK: Subscription started.
    • TI_ERR_INVALID_ARG: client is NULL.
    • TI_ERR_NOT_CONNECTED: Client is not connected.
    • TI_ERR_INTERNAL: SDK could not start the subscription.
  • Notes: Repeating the call restarts the subscription. A short delay may exist before the first event arrives.

ti_stop_event_subscription

int ti_stop_event_subscription(ti_client_t *client);

Stops event notifications.

ParameterTypeDirectionDescription
clientti_client_t *inputClient handle.
  • Returns:
    • TI_OK: Stopped, or no subscription was running.
    • TI_ERR_INVALID_ARG: client is NULL.
  • Notes: Waits until the subscription has stopped.

Logs

ti_set_log_callback

void ti_set_log_callback(ti_client_t *client,
                         ti_log_callback_t callback,
                         void *user_data);

Registers or clears the log callback.

ParameterTypeDirectionDescription
clientti_client_t *inputClient handle. NULL is ignored.
callbackti_log_callback_tinputCallback function, or NULL to discard logs.
user_datavoid *inputOpaque pointer passed to the callback. May be NULL.
  • Returns: Nothing.
  • Notes: Call before ti_start_log_subscription(). Do not block for long periods inside the callback.

ti_start_log_subscription

int ti_start_log_subscription(ti_client_t *client);

Starts log notifications.

ParameterTypeDirectionDescription
clientti_client_t *inputConnected client handle.
  • Returns:
    • TI_OK: Subscription started.
    • TI_ERR_INVALID_ARG: client is NULL.
    • TI_ERR_NOT_CONNECTED: Client is not connected.
    • TI_ERR_INTERNAL: SDK could not start the subscription.

ti_stop_log_subscription

int ti_stop_log_subscription(ti_client_t *client);

Stops log notifications.

ParameterTypeDirectionDescription
clientti_client_t *inputClient handle.
  • Returns:
    • TI_OK: Stopped, or no subscription was running.
    • TI_ERR_INVALID_ARG: client is NULL.

Error and Version

ti_last_error

const char *ti_last_error(const ti_client_t *client);

Returns the most recent error text for a client.

ParameterTypeDirectionDescription
clientconst ti_client_t *inputClient handle.
  • Returns: A readable error string. If client is NULL, returns an invalid-handle message.
  • Notes: Do not free the returned string. It remains valid until the next operation on the same client.

ti_version

const char *ti_version(void);

Returns the SDK version.

  • Parameters: None.
  • Returns: A static string in major.minor.patch form.
  • Notes: Do not free the returned string.

Status Codes

ValueMeaning
TI_OKSuccess
TI_ERR_INVALID_ARGInvalid argument
TI_ERR_NOT_CONNECTEDNot connected
TI_ERR_TIMEOUTOperation timed out
TI_ERR_BUFFER_TOO_SMALLOutput buffer is too small
TI_ERR_SERVERDevice rejected the operation
TI_ERR_INTERNALSDK could not complete the operation

See the parameter reference for all parameter keys.