Label printer application opening system
By integrating the Python core package and API interface into the label printer, user-defined scripts can be implemented, solving the flexibility and scalability issues of traditional closed label printer systems and improving the printer's intelligence and stability.
Patent Information
- Application Number
- CN202511110510.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-08
- Publication Date
- 2025-11-21
AI Technical Summary
Traditional label printers' closed systems limit flexibility and scalability, making it difficult to meet personalized and intelligent printing needs. Existing technologies suffer from high development complexity, high cost, slow response speed, and susceptibility to errors.
This invention provides an open system for label printer applications, integrating Python core packages and API interfaces, supporting user-defined scripts, and enabling personalized printing tasks through a touch screen and the system main program, thereby reducing the development threshold and simplifying the system architecture.
It improves the flexibility and scalability of printing tasks, reduces development difficulty and cost, improves operational efficiency and accuracy, and enhances the level of intelligence and system stability.
Smart Images

Figure CN120994189A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of label printing technology, and more particularly to an open system for label printer applications. Background Technology
[0002] Traditional label printers typically employ a closed system architecture, with functions preset by the manufacturer and users operating them only through limited menu options or dedicated software. This model severely restricts the flexibility and scalability of printing tasks, making it difficult to meet the growing demands for personalized and intelligent printing. For customized printing scenarios that require dynamic interaction with external data sources (such as databases, sensors, and network services) or the execution of complex data processing logic, existing technologies often require additional configuration of host computers (such as PCs or servers), development of dedicated middleware software, or reliance on manual data input, resulting in complex system architectures, high deployment costs, slow response times, and susceptibility to errors.
[0003] While some devices attempt to provide script support or API interfaces, they generally suffer from limited language support (e.g., only supporting simple macro commands), complex development environments, and low coupling with the core functions of the device, thus failing to truly achieve open and flexible secondary development. Therefore, there is an urgent need for an open system that can deeply integrate script programming capabilities with the core functions of the printer to lower the development threshold for users and improve the intelligence level and application adaptability of printing devices. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to provide an open application system for label printers, which addresses the above-mentioned deficiencies of the prior art and provides users with an open application platform, thereby reducing the development threshold for users.
[0005] To achieve the above objectives, in a first aspect, the present invention provides an open system for label printer applications, the system comprising a label printer and a supporting software development kit;
[0006] The software development kit includes a pre-installed Python core package in the label printer, and a set of application programming interfaces (APIs) for function calls. The types of APIs include peripheral port data reading / writing, printer settings, label settings, and custom label image / text printing. The peripheral port data reading / writing API is used to read and write data from the label printer's peripheral ports. The label settings API is used to set the label's orientation and size, and the custom label image / text printing API is used to customize the label's layout and style.
[0007] The label printer includes a processor configured to run a system main program and a user-defined script. The user-defined script is an executable program written in Python. The processor has an embedded Python interpreter for parsing and executing the user-defined script.
[0008] The user-defined script integrates a software development kit. The user-defined script communicates with the system main program by calling the application programming interface. The system main program obtains data from the external devices connected to the label printer and performs personalized label printing tasks in conjunction with the label printing template. The label printing template is created using dedicated label template editing software or is a pre-set label printing template within the label printer.
[0009] The system's main program responds to script execution requests by running the user-defined script and monitors the running status of the user-defined script.
[0010] In the label printer application open system provided by this invention, the system main program executes the user-defined script in response to a script execution request, including:
[0011] The system's main program detects whether a user-defined script is running at the current time. If not, it uses a shell command to call the Python interpreter to execute the user-defined script corresponding to the script execution request.
[0012] In the label printer application open system provided by this invention, monitoring the running status of the user-defined script includes:
[0013] The system's main program monitors the running status of the Python interpreter through a separate thread. If the status is abnormal, it kills the process containing the Python interpreter.
[0014] In the label printer application open system provided by the present invention, the label printer further includes a touch screen, and the processor also runs a user interface program.
[0015] In response to a user's script execution request, the user interface program sends the path information of the user-defined script to the system main program, and the system main program executes the corresponding user-defined script according to the user-defined script path information.
[0016] In the label printer application open system provided by this invention, the software open toolkit also includes an application programming interface (API) related to the user interface. When the user-defined script starts, it registers a custom user interface and event handling functions with the system main program through the API related to the user interface, and displays the custom user interface on the touch screen. During the execution of the user-defined script, the system main program calls the event handling functions in response to user operations.
[0017] In the label printer application open system provided by this invention, the specific method by which the system main program responds to user operations by calling the event handling function during the execution of the user-defined script and the display of a custom user interface on the touch screen is as follows:
[0018] The system main program sends the page information of the custom user interface to the user interface program, and the user interface program displays the custom user interface on the touch screen according to the page information;
[0019] During the execution of the user-defined script, after the user interface program captures the user operation, it sends the user operation information to the system main program. The system main program determines whether the user-defined script has registered an event handling function corresponding to the user operation information. If so, it calls the event handling function.
[0020] In the label printer application open system provided by the present invention, the Python script is located in a preset file directory, and its runtime root directory is restricted to the preset file directory through a sandbox.
[0021] The label printer application open system provided by the present invention further includes printer mobile terminal control software, which is used to upload user-defined scripts to the label printer.
[0022] The present invention has the following beneficial effects:
[0023] 1. Enhanced flexibility and scalability: By providing an open software development kit (SDK) and a Python-based scripting environment, users can independently develop printing applications that meet specific needs, breaking through the limitations of traditional printer function presets and achieving a high degree of customization and dynamism in printing tasks.
[0024] 2. Reduced Development Barriers and Costs: Leveraging Python's concise syntax, gentle learning curve, and abundant community resources, the technical difficulty and time cost of application development are significantly reduced. Users can extend functionality without needing complex low-level hardware knowledge or specialized programming languages.
[0025] 3. Simplified system architecture and operation process: Data acquisition, data processing, logical judgment and printing execution are integrated into a single label printer, avoiding dependence on external computing devices and complex middleware, simplifying system deployment, reducing data transmission links, and improving overall operating efficiency and reliability.
[0026] 4. Enhanced automation and intelligence: User scripts can interact directly or indirectly with external devices (such as sensors, databases, and network APIs) via APIs to achieve automatic data collection, processing, and condition judgment, thereby driving the printer to perform corresponding printing tasks and achieving truly intelligent and automated printing.
[0027] 5. Improve efficiency and reduce errors: By replacing manual operations with automated scripts, human intervention is reduced, manual input errors are effectively avoided, the execution speed and accuracy of printing tasks are improved, and operating costs are reduced.
[0028] 6. Ensure system stability: The main system program is responsible for monitoring the running status of user-defined scripts and can intervene or recover when scripts malfunction, ensuring the stable operation of the label printer's core functions. Attached Figure Description
[0029] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:
[0030] Figure 1 This is a block diagram of an open system for label printer applications provided in an embodiment of the present invention. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0032] The embodiments of the present invention will now be described in further detail with reference to the accompanying drawings. It should be understood that the embodiments described herein are for illustrative and explanatory purposes only and are not intended to limit the scope of the invention.
[0033] This invention provides an open system for label printer applications, aiming to build an open platform for personalized printing services for users. This system allows users to independently develop Python scripts based on an open API (Application Programming Interface) to achieve highly customized label printing tasks, thereby significantly improving the flexibility and scalability of printing functions.
[0034] Specifically, the label printer application open system described in this embodiment of the invention includes a label printer and a supporting SDK (Software Development Kit). The SDK includes a pre-installed Python core package and a set of APIs for function calls. This API set covers functional modules such as peripheral port data reading and writing, printer settings, label settings, and custom label graphic printing, providing standardized calling interfaces for user-defined scripts. Through these interfaces, user Python scripts can customize the user interface, obtain data from the label printer's peripheral ports, and perform personalized graphic printing. The peripheral port data reading and writing API allows reading and writing data from the label printer's peripheral ports. The printer settings API allows sending print commands to the label printer. The label settings API allows setting the label's orientation and size. The custom label graphic printing API allows customizing the label layout and style, such as printing text, images, graphics, tables, barcodes, QR codes, and setting the style of elements within the label within a specified coordinate range.
[0035] The label printer includes a processor configured to run a system main program and user-defined scripts. The user-defined scripts are executable programs written in Python, and the processor has an embedded Python interpreter for parsing and executing them.
[0036] During system operation, user-defined scripts communicate with the system main program by calling the API through the integrated SDK. The system main program, as the core control module, is responsible for managing hardware resources, coordinating peripheral communication, and responding to data requests and printing commands from user-defined scripts. Through this mechanism, user-defined scripts can obtain data from external devices or systems connected to the label printer, or from the label printer's local files, process the data, and execute personalized label generation and printing tasks in conjunction with label printing templates. The label printing templates are created using dedicated label template editing software or are pre-installed label printing templates within the label printer. It should be understood that templates are not mandatory; the label layout and style can also be dynamically defined entirely by the user through the API for custom label graphic printing.
[0037] The system's main program is configured to respond to received script execution requests, run corresponding user-defined scripts, and monitor the execution status of user-defined scripts in real time, including running progress, abnormal interruptions, and resource usage, to ensure the stability and security of system operation.
[0038] In embodiments of this invention, by integrating a Python interpreter and providing complete SDK support within the label printer, users can leverage Python's concise syntax, abundant third-party library resources, and robust community ecosystem to efficiently develop customized applications. This design significantly lowers the development threshold for users, reduces development cycles and workload, and greatly enhances users' autonomy in controlling the printing process. Furthermore, this system, through its open API architecture, completely overcomes the technical limitations of traditional label printing equipment, such as closed functionality and poor scalability. Complex application scenarios that previously required external computing devices, manual intervention, or dedicated customized software (such as dynamic data binding, conditional printing, and multi-source data fusion) can now be completed directly by running user-defined scripts locally on the printer. This technical solution effectively simplifies the operation process, improves operational efficiency, reduces labor costs and system complexity, and demonstrates significant technological advancement and practical value.
[0039] In this embodiment of the invention, the processor has a built-in Python interpreter, and the software development kit includes the Python package built into the label printer and multiple application programming interfaces. Since the label printer is an embedded device with limited hardware resources, in order to provide an open platform for user-defined scripts, this embodiment of the invention streamlines the label printer's original operating system, retaining only components related to the label printer, thus reserving more resources for the Python runtime environment and user-defined scripts. Furthermore, a lightweight Python interpreter is selected.
[0040] In some embodiments of this invention, the built-in Python core software packages of the label printer include the following types: encryption / decryption, C language extensions, data processing and encoding, database tools, network communication, and document processing. In some embodiments of this invention, the corresponding Python interpreter version is 3.8, and the built-in Python software packages of the label printer are shown in Table 1 below. Users can write Python scripts in the Python 3.8 development environment on their personal computers. Through these Python software packages, they can interface with the MES / ERP system, database, or local documents on the label printer to obtain the data source required for printing labels and perform encoding and other processing on the data source.
[0041] Table 1 List of Python packages
[0042]
[0043]
[0044] Understandably, if the Python package built into the label printer does not contain a package that the user wants, the required Python package needs to be generated externally to the label printer through methods such as cross-compilation, and then uploaded and installed into the label printer.
[0045] In this embodiment of the invention, the Python script is located in a preset file directory, and its runtime root directory is restricted to this preset file directory through a sandbox. To ensure device security, in some embodiments of the invention, an independent area is allocated in the Flash memory of the label printer and mapped to a preset file directory. The Python script is restricted to this directory, and the root directory is specified as this directory through sandboxing technology, so that the Python script can only access documents within this directory, thereby ensuring the security of files in other directories.
[0046] It should be noted that, in this embodiment of the invention, although the user-defined script can access external systems, databases, or internal documents of the label printer through the label printer's built-in Python package, accessing data from external devices connected to the label printer must be achieved by calling an application programming interface (API). Specifically, the user-defined script calls the API related to peripheral port data read / write. The API sends information to the system main program, which then retrieves the data from the external device and returns it to the user-defined script. In this embodiment, the API communicates with the system main program via nanomsg. This method restricts the access permissions of the user-defined script, allowing it to access data from the label printer's external ports without jeopardizing the label printer's security due to excessive privileges.
[0047] In this embodiment of the invention, the system main program running the user-defined script in response to a script execution request includes:
[0048] The system's main program checks if any user-defined scripts are running at the current time. If not, it uses a shell command to invoke the Python interpreter to execute the user-defined script corresponding to the script execution request. In this way, the system's main program ensures that only one user-defined script is running at a time, avoiding resource access conflicts between different user-defined scripts.
[0049] In this embodiment of the invention, monitoring the running status of the user-defined script includes:
[0050] The system's main program monitors the running status of the Python interpreter through a separate thread. If the status is abnormal, it kills the process containing the Python interpreter.
[0051] In this embodiment of the invention, the system main program refers to the firmware program of the label printer. The firmware program controls the normal operation of all components on the printer, such as the print head and motor. The system main program executes the user's Python script by calling the Python interpreter through shell commands, which is equivalent to creating a Python interpreter process. Then, the system main program creates an independent thread to monitor the running status of the Python interpreter. If the status is abnormal, the process where the Python interpreter resides is killed. The system main program monitors the execution status of the custom script, including running progress, abnormal interruption, resource usage, etc. If an abnormality is detected, in order to avoid affecting the printing task and system security, the process where the Python interpreter resides is killed in time. At the same time, alarm information can be issued through pop-up windows on the touch screen.
[0052] It is understood that users can create one or more child threads in a Python script, and this embodiment of the invention does not limit this. If the process in which the Python interpreter resides is killed, then the threads created in the Python script will also be killed synchronously.
[0053] In this embodiment of the invention, the label printer further includes a touch screen, and the processor also runs a user interface program; the user interface program responds to the user's script execution request by sending the path information of the user-defined script to the system main program, and the system main program runs the corresponding user-defined script according to the user-defined script path information.
[0054] In some embodiments of the present invention, the touchscreen is an LCD touchscreen. The user interface program displays the user interface through the touchscreen, allowing the user to view and change the label printer settings. Specifically, a script management page can be added to the user interface, where the user selects a user-defined script to run. The user interface program then sends the selected script path information to the system main program, which runs the user-selected script based on the script path.
[0055] In some embodiments of the present invention, the software open toolkit further includes an application programming interface (API) for a user interface class. When the user-defined script starts, it registers a custom user interface and event handling functions with the system main program through the API of the user interface class, and displays the custom user interface on the touchscreen. During the execution of the user-defined script, the system main program calls the event handling functions in response to user operations. The specific method for displaying the custom user interface on the touchscreen and for the system main program to call the event handling functions in response to user operations during the execution of the user-defined script is as follows:
[0056] The system main program sends the page information of the custom user interface to the user interface program, and the user interface program displays the custom user interface on the touch screen according to the page information;
[0057] During the execution of the user-defined script, after the user interface program captures the user operation, it sends the user operation information to the system main program. The system main program determines whether the user-defined script has registered an event handling function corresponding to the user operation information. If so, it calls the event handling function.
[0058] In this embodiment of the invention, to enable users to customize the user interface and receive user input from the user interface, application programming interfaces related to the user interface are provided. However, to ensure that the original functions of the label printer are not affected, the user-defined script needs to interact with the page through the system main program. To improve the response speed of the user interface, the user-defined script registers its custom user interface and event handling functions with the system main program when it starts, and displays the user-defined user interface on the touch screen. During script execution, after the user interface program captures the user operation, it sends the user operation information to the system main program. The system main program determines whether the user operation requires calling the event handling function based on the previously registered information. If so, the event handling function is called; otherwise, the main thread handles it automatically. In this way, the user-defined script does not need to pay attention to the user interface control logic, simplifying the user-defined script processing flow and improving the response speed of the user interface.
[0059] In this embodiment of the invention, the system further includes mobile printer control software, which is used to upload user-defined scripts to the label printer. Label printers typically come with their own mobile control software to facilitate user control of the label printer from a mobile device. In this embodiment, a user-defined script management function is added to the existing mobile printer control software, used for uploading, viewing, and deleting user-defined scripts.
[0060] The following examples illustrate the application scenarios of the label printer application open system according to embodiments of the present invention. (one)
[0062] Application scenario description: Connect the barcode scanner to the USB port of the label printer, write a Python script to obtain two consecutive scan values through the USB port, and then print these two scan values onto the label. During the scanning process, the scan values are displayed on the touch screen of the label printer.
[0063] Python script logic: Upon startup, register the user interface through the user interface-related API, obtain the scan data from the label printer's USB port through the peripheral interface-related API, update the values of the input boxes in the user interface, and then call the printing-related API to send the print job to the system main program.
[0064] The following is a Python script snippet:
[0065] #Import SDK package
[0066]
[0067] The code above creates two small input boxes on the touchscreen user interface to display the scanned data in real time.
[0068]
[0069]
[0070] The code above means the following: After the user interface controls are initialized, a loop is entered. Within the loop, data from the label printer's USB port is continuously retrieved via PTK_GetPortData. Each time data is received, the corresponding input field in the user interface is updated. After two data scans, PTK_UpdateAllFormVariables is called to replace the corresponding fields in the label template file with these two data points. Then, PTK_SendCmdToPrinter is called to notify the main program to execute the print task. PTK_GetPortData, PTK_UpdateAllFormVariables, and PTK_SendCmdToPrinter are all application programming interfaces (APIs).
[0071] When PTK_GetPortData is called, the user-defined script sends a nanomsg request to the system main program. Upon receiving the request, the system main program reads data from the corresponding port. If data is found, it returns the data to the user-defined script; otherwise, it returns -1. The controller is the control class for the user interface. Calling PTK_UIInit returns a list of controllers. Each element of the user interface has a corresponding controller. Updates to the user interface content are performed through the corresponding controller. (two)
[0073] Application scenario description: Connect to a database, retrieve new data written after a certain time from one of the data tables, and print one of the fields to a fixed position on a label.
[0074] Python script logic: Connect to the database through the built-in Python package of the label printer, retrieve data from the data table, filter out the fields that meet the requirements, and then send the print job to the system main program by calling the API of the custom label graphic printing class. (three)
[0076] Application scenario description: Printing data from an Excel file offline in a label printer.
[0077] The Python script logic works as follows: It reads the local Excel file from the label printer using the label printer's built-in Python package, performs necessary data processing, and calls the relevant printing APIs to send a print job to the main system program. Both the Excel file and the Python script need to be uploaded to the label printer's default file directory. (Four)
[0079] Application scenario description: Obtain data from MES / ERP / cloud platform, process the data, and then print it onto labels.
[0080] Python script logic: It interfaces with the MES / ERP / cloud platform system through the built-in Python package of the label printer, obtains data from it, processes the data, and calls the printing-related APIs to send the print job to the system main program.
[0081] The above are just a few simple application scenario descriptions and explanations of Python script processing logic. It is understandable that user-defined scripts can also achieve more complex functions, such as using Python packages to implement encrypted communication with external systems and designing more complex user interfaces.
[0082] The above are merely specific embodiments of the present invention and should not be construed as limiting the scope of the present invention. Equivalent variations made by those skilled in the art based on this invention, as well as changes well-known to those skilled in the art, should still fall within the scope of the present invention.
Claims
1. An open system for label printer applications, characterized in that, The system includes a label printer and a supporting software development kit; The software development kit includes a Python core package pre-installed in the label printer, and a set of application programming interfaces oriented towards function calls; The types of application programming interfaces include peripheral port data reading and writing, printer settings, label settings, and custom label graphic printing; The application programming interface for the peripheral port data read / write class is used to read and write data on the peripheral ports of the label printer; the application programming interface for the label settings class is used to set the direction and size of the label; and the application programming interface for the custom label graphic printing class is used to customize the layout and style of the label. The label printer includes a processor configured to run a system main program and a user-defined script. The user-defined script is an executable program written in Python. The processor has an embedded Python interpreter for parsing and executing the user-defined script. The user-defined script integrates a software development kit. The user-defined script communicates with the system main program by calling the application programming interface. It obtains data from the external devices connected to the label printer through the system main program and performs personalized label printing tasks in combination with the label printing template. The label printing template is created using dedicated label template editing software, or it is a pre-installed label printing template in the label printer; The system's main program responds to script execution requests by running the user-defined script and monitors the running status of the user-defined script.
2. The label printer application open system according to claim 1, characterized in that, The system main program responds to a script execution request by running the user-defined script, including: The system's main program detects whether a user-defined script is running at the current time. If not, it uses a shell command to call the Python interpreter to execute the user-defined script corresponding to the script execution request.
3. The label printer application open system according to claim 2, characterized in that, The monitoring of the running status of the user-defined script includes: The system's main program monitors the running status of the Python interpreter through a separate thread. If the status is abnormal, it kills the process containing the Python interpreter.
4. The label printer application open system according to claim 1, characterized in that, The label printer also includes a touch screen, and the processor also runs a user interface program; In response to a user's script execution request, the user interface program sends the path information of the user-defined script to the system main program, and the system main program executes the corresponding user-defined script according to the user-defined script path information.
5. The label printer application open system according to claim 4, characterized in that, The software open toolkit also includes an application programming interface (API) for user interface classes. When the user-defined script starts, it registers the custom user interface and event handling functions with the system main program through the API of the user interface class, and displays the custom user interface on the touch screen. During the execution of the user-defined script, the system main program calls the event handling functions in response to user operations.
6. The label printer application open system according to claim 5, characterized in that, The specific method by which the system main program responds to user operations by calling the event handling function during the execution of the user-defined script and the display of the custom user interface on the touch screen is as follows: The system main program sends the page information of the custom user interface to the user interface program, and the user interface program displays the custom user interface on the touch screen according to the page information; During the execution of the user-defined script, after the user interface program captures the user operation, it sends the user operation information to the system main program. The system main program determines whether the user-defined script has registered an event handling function corresponding to the user operation information. If so, it calls the event handling function.
7. The label printer application open system according to claim 1, characterized in that, The Python script is located in a preset file directory, and its runtime root directory is restricted to the preset file directory through a sandbox.
8. The label printer application open system according to claim 1, characterized in that, The system also includes mobile control software for printers, which is used to upload user-defined scripts to the label printer.