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 withti_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 withti_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
NULLif 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Client 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Client handle created by ti_create(). |
address | const char * | input | Device 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:clientisNULL.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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Client handle. |
- Returns:
TI_OK: Disconnected, or the client was already disconnected.TI_ERR_INVALID_ARG:clientisNULL.
ti_is_connected
int ti_is_connected(const ti_client_t *client);
Checks whether the connection is currently usable.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | const ti_client_t * | input | Client handle. |
- Returns:
1when connected and usable;0when disconnected orclientisNULL.
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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
ip | const char * | input | IPv4 address, or NULL / empty to leave unchanged. |
ip_mask | const char * | input | Subnet mask, or NULL / empty to leave unchanged. |
gateway | const char * | input | Default gateway, or NULL / empty to leave unchanged. |
- Returns:
TI_OK: Settings accepted.TI_ERR_INVALID_ARG:clientisNULLor 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
key | const char * | input | Case-sensitive parameter key from the parameter reference. |
value | const char * | input | String value. Booleans use "true" or "false". |
- Returns:
TI_OK: Parameter accepted.TI_ERR_INVALID_ARG: Any argument isNULL.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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | const ti_client_t * | input | Connected client handle. |
key | const char * | input | Case-sensitive parameter key. |
value_buf | char * | output | Destination buffer. |
buf_size | size_t | input | Buffer 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, orvalue_bufisNULL.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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
key | const char * | input | Parameter key. |
value | int32_t | input | Integer 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | const ti_client_t * | input | Connected client handle. |
key | const char * | input | Parameter key. |
out | int32_t * | output | Receives 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
key | const char * | input | Parameter key. |
value | double | input | Double 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | const ti_client_t * | input | Connected client handle. |
key | const char * | input | Parameter key. |
out | double * | output | Receives 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
key | const char * | input | Parameter key. |
value | int | input | Non-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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | const ti_client_t * | input | Connected client handle. |
key | const char * | input | Parameter key. |
out | int * | output | Receives 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
data | const uint8_t * | input | Print-data bytes. Must not be NULL. |
data_len | size_t | input | Number of bytes. Must be greater than zero. |
index | uint32_t | input | Application-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_OKdoes 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
key | const char * | input | Uppercase command key: "START_PRINT", "STOP_PRINT", "PAUSE_PRINT", "RESUME_PRINT", or "ANALOG_TRIGGER". |
- Returns:
TI_OK: Command accepted.TI_ERR_INVALID_ARG:client/keyisNULL, 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
key | const char * | input | Upgrade target. Use TI_UPGRADE_TARGET_SYSTEM for a full-system upgrade. Must not be empty. |
file_path | const char * | input | Path 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_OKdoes 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Client handle. NULL is ignored. |
callback | ti_event_callback_t | input | Callback function, or NULL to clear it. |
user_data | void * | input | Opaque 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
- Returns:
TI_OK: Subscription started.TI_ERR_INVALID_ARG:clientisNULL.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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Client handle. |
- Returns:
TI_OK: Stopped, or no subscription was running.TI_ERR_INVALID_ARG:clientisNULL.
- 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Client handle. NULL is ignored. |
callback | ti_log_callback_t | input | Callback function, or NULL to discard logs. |
user_data | void * | input | Opaque 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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Connected client handle. |
- Returns:
TI_OK: Subscription started.TI_ERR_INVALID_ARG:clientisNULL.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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | ti_client_t * | input | Client handle. |
- Returns:
TI_OK: Stopped, or no subscription was running.TI_ERR_INVALID_ARG:clientisNULL.
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.
| Parameter | Type | Direction | Description |
|---|---|---|---|
client | const ti_client_t * | input | Client handle. |
- Returns: A readable error string. If
clientisNULL, 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.patchform. - Notes: Do not free the returned string.
Status Codes
| Value | Meaning |
|---|---|
TI_OK | Success |
TI_ERR_INVALID_ARG | Invalid argument |
TI_ERR_NOT_CONNECTED | Not connected |
TI_ERR_TIMEOUT | Operation timed out |
TI_ERR_BUFFER_TOO_SMALL | Output buffer is too small |
TI_ERR_SERVER | Device rejected the operation |
TI_ERR_INTERNAL | SDK could not complete the operation |
See the parameter reference for all parameter keys.