Printing access method capable of automatically adapting to multiple scenes, electronic equipment and readable medium
By establishing a Bluetooth node and a Bluetooth Low Energy channel between the host and the printer, print requests can be directly acquired and transmitted, solving the problem of high maintenance and adaptation costs of the printing SDK and realizing convenient printing functions.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-05
- Publication Date
- 2026-04-07
AI Technical Summary
In existing technologies, printing SDKs require maintenance and updates, resulting in high maintenance costs for both software developers and printing platform vendors. Furthermore, SDKs from different printing vendors require multiple adaptations, increasing the workload for application developers, especially in web applications and hybrid H5 applications where the adaptation costs are extremely high.
By establishing a communication link between the host and the printer, a corresponding Bluetooth node for the printer is generated. A low-power Bluetooth channel is established between the application and the printer to obtain print requests and generate print instructions. This avoids integrating and calling the print SDK on the host and directly implements the printing function through the low-power Bluetooth channel.
It enables convenient access to printing capabilities, reduces maintenance and adaptation costs, and decreases the dependency and adaptation complexity of the printing SDK.
Smart Images

Figure CN121807241A_ABST
Abstract
Description
Technical Field
[0001] This application relates primarily to the field of printing, and in particular to a printing access method, electronic device, and readable medium that automatically adapt to multiple scenarios. Background Technology
[0002] Many application-layer development solutions on the market use cross-platform solutions, such as React Native, H5 hybrid apps, and mini-programs. These cross-platform solutions are convenient for pure logic development at the application layer, but when it comes to calling the hardware capabilities of the device itself, specific technical solutions are needed to connect the hardware capability interfaces to the JavaScript side.
[0003] Taking printing functionality as an example, a common way to provide printing capabilities is through a printing SDK (Software Development Kit), where the application directly integrates and calls the printing SDK. This approach has several drawbacks:
[0004] 1. Printing SDKs require maintenance and updates. For printing vendors, after releasing a printing SDK, it needs to be synchronized with users of the printing capabilities to ensure the entire process runs smoothly. Therefore, using a printing SDK increases maintenance costs for both software developers and printing platform vendors.
[0005] 2. The printing SDKs packaged by different printing manufacturers are highly likely to be different. Because there is no universally accepted standard interface in the industry, the same application needs to be adapted multiple times to run on different printing platforms, which significantly increases the workload for application developers.
[0006] 3. When the client application exists in the form of a web application, hybrid H5 application, etc., connecting the printing SDK to the browser requires the use of communication technologies such as JavaScript Bridge or sockets to convert the native printing interface into a JavaScript interface. Obviously, this will bring extremely high adaptation costs to both printing providers and printing users.
[0007] In summary, there is an urgent need for a printing access method that can conveniently call upon printing capabilities and automatically adapt to multiple scenarios. Summary of the Invention
[0008] The technical problem this application aims to solve is to provide a printing access method, electronic device, and readable medium that automatically adapts to multiple scenarios, enabling convenient access to printing capabilities.
[0009] To address the aforementioned technical issues, this application provides a print access method that automatically adapts to multiple scenarios, applicable to electronic devices. The electronic device includes a host computer adapted to establish a communication link with at least one printer. The host computer includes an application terminal. The print access method includes: in response to the host computer establishing a communication link with at least one printer, generating a Bluetooth node corresponding to at least one printer; establishing a low-power Bluetooth channel between the application terminal and the Bluetooth node corresponding to the printer specified in the print request received by the application terminal; acquiring the print request generated by the application terminal based on the print request through the low-power Bluetooth channel, and generating a corresponding print instruction based on the print request; and sending the print instruction from the host computer to the specified printer through the communication link.
[0010] Optionally, the application may include a web application.
[0011] Optionally, the application side also includes hybrid applications and / or native applications.
[0012] Optionally, the step of establishing a Bluetooth Low Energy channel between the application and the Bluetooth node corresponding to the printer specified in the print request received by the application further includes: registering the Bluetooth node to the host's Bluetooth Low Energy list; generating a connection request by the application based on the print request, the connection request including the connection target address; and establishing a Bluetooth Low Energy channel between the application and the Bluetooth node in response to determining the defined address of the Bluetooth node corresponding to the connection target address.
[0013] Optionally, the step of registering the Bluetooth node to the host's Bluetooth Low Energy list further includes: registering the Bluetooth node to the Bluetooth Low Energy list via the host in response to receiving a broadcast from the Bluetooth node.
[0014] Optionally, the step of establishing a Bluetooth Low Energy channel between the application and the Bluetooth node corresponding to the printer specified in the print request received by the application further includes: obtaining the printing characteristic value of the Bluetooth node, and determining whether the device corresponding to the Bluetooth node has printing capability based on the printing characteristic value.
[0015] Optionally, the print request includes an initial print instruction, which includes an instruction type, including ESC and TSPL instructions. The step of obtaining the print request generated by the application based on the printing needs through the Bluetooth Low Energy channel and generating the corresponding print instruction based on the print request further includes: generating a corresponding print instance based on the print request; sending the initial print instruction to the host's print service process by calling the corresponding interface based on the instruction type through the print instance; and generating the corresponding print instruction through the print service process based on the initial print instruction.
[0016] Optionally, the print request includes a query request, and the print access method further includes: generating a query result through the printer according to the print instruction corresponding to the query request, and sending the query result to the application; and displaying the query result through the application.
[0017] Optionally, the communication link includes a wired communication link.
[0018] To address the aforementioned technical problems, this application provides an electronic device comprising: a host computer, including a BLE printing module and an application terminal, the host computer being adapted to establish a communication link with at least one printer, wherein the BLE printing module includes: a BLE channel unit, the BLE channel unit being adapted to generate a Bluetooth node corresponding to at least one printer in response to the host computer establishing a communication link with at least one printer, the Bluetooth node being adapted to establish a low-power Bluetooth channel with the application terminal; and a request listening unit, the request listening unit being adapted to acquire a print request generated by the application terminal based on the received print requirements through the low-power Bluetooth channel, and to generate a corresponding print instruction based on the print request, the host computer being further adapted to send the print instruction to the printer through the communication link.
[0019] Optionally, the BLE channel unit is adapted to register the Bluetooth node to the host's Bluetooth Low Energy list; the application is adapted to generate a connection request according to printing requirements, wherein the connection request includes a connection target address; the application is also adapted to establish a Bluetooth Low Energy channel with the Bluetooth node in response to determining the defined address of the Bluetooth node corresponding to the connection target address.
[0020] Optionally, the host is also adapted to register the Bluetooth node to a Bluetooth Low Energy list in response to receiving a broadcast from the Bluetooth node.
[0021] Optionally, the application can also acquire the printing characteristic value of the Bluetooth node and determine whether the device corresponding to the Bluetooth node has printing capability based on the printing characteristic value.
[0022] Optionally, the print request includes an initial print instruction, which includes an instruction type, including ESC and TSPL instructions. The request listening unit is adapted to generate a corresponding print instance based on the print request. The print instance is adapted to call the corresponding interface according to the instruction type to send the initial print instruction to the host's print service process. The print service process is adapted to generate a corresponding print instruction based on the initial print instruction.
[0023] Optionally, the print request includes a query request, the printer is adapted to generate query results according to the print instruction corresponding to the query request, and send the query results to the application, the application is adapted to display the query results.
[0024] Optionally, the communication link includes a wired communication link.
[0025] Optionally, the application may include a web application.
[0026] Optionally, the application side also includes hybrid applications and / or native applications.
[0027] To address the aforementioned technical problems, this application provides a computer-readable medium storing computer program code, which, when executed by a processor, implements the aforementioned automatic adaptation method for printing access in multiple scenarios.
[0028] Compared with existing technologies, this application has the following advantages: A communication link is established between the host and the printer, thereby generating a Bluetooth node corresponding to the printer. Based on this, after the application on the host receives a print request, a low-power Bluetooth channel is established between the Bluetooth node and the corresponding printer. The low-power Bluetooth channel then converts the print request from the application into print instructions that the printer can execute. This achieves the printing function while avoiding the need to integrate and call the print SDK on the host, thus enabling convenient printing capabilities and effectively reducing maintenance and adaptation costs. Attached Figure Description
[0029] The accompanying drawings are included to provide a further understanding of this application; they are incorporated into and constitute a part of this application. The drawings illustrate embodiments of this application and, together with this specification, serve to explain the principles of this application. In the drawings:
[0030] Figure 1 This is a flowchart illustrating a printing access method that automatically adapts to multiple scenarios in one embodiment of this application;
[0031] Figure 2 yes Figure 1 A flowchart illustrating the sub-steps of step S2;
[0032] Figure 3 yes Figure 1 A flowchart illustrating the sub-steps of step S3 in the middle section;
[0033] Figure 4 This is a flowchart illustrating a printing access method that automatically adapts to multiple scenarios, as described in another embodiment of this application.
[0034] Figure 5 This is a flowchart illustrating the specific execution steps of a printing access method that automatically adapts to multiple scenarios, as described in one embodiment of this application.
[0035] Figure 6 This is a block diagram of an electronic device according to one embodiment of this application; and
[0036] Figure 7 Is Figure 6 A flowchart illustrating the method for setting up the BLE printing module in the host machine. Detailed Implementation
[0037] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are merely some examples or embodiments of this application. For those skilled in the art, these drawings can be applied to other similar scenarios without creative effort. Unless obvious from the context or otherwise specified, the same reference numerals in the drawings represent the same structures or operations.
[0038] As indicated in this application and claims, unless the context clearly indicates otherwise, the words "a," "an," "an," and / or "the" are not specifically singular and may include plural forms. Generally speaking, the terms "comprising" and "including" only indicate the inclusion of explicitly identified steps and elements, which do not constitute an exclusive list, and the method or apparatus may also include other steps or elements.
[0039] Unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps described in these embodiments do not limit the scope of this application. It should also be understood that, for ease of description, the dimensions of the various parts shown in the drawings are not drawn to actual scale. Techniques, methods, and devices known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and devices should be considered part of the specification. In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values. It should be noted that similar reference numerals and letters in the following drawings denote similar items; therefore, once an item is defined in one drawing, it need not be further discussed in subsequent drawings.
[0040] In the description of this application, it should be understood that the orientation or positional relationship indicated by directional terms such as "front, back, up, down, left, right", "horizontal, vertical, horizontal" and "top, bottom" is usually based on the orientation or positional relationship shown in the accompanying drawings, and is only for the convenience of describing this application and simplifying the description. Unless otherwise stated, these directional terms do not indicate or imply that the device or element referred to must have a specific orientation or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation on the scope of protection of this application; the directional terms "inner" and "outer" refer to the inner and outer contours relative to the outline of each component itself.
[0041] For ease of description, spatial relative terms such as "above," "on top of," "on the upper surface of," "above," etc., are used herein to describe the spatial positional relationship of a device or feature as shown in the figures to other devices or features. It should be understood that spatial relative terms are intended to encompass different orientations in use or operation beyond the orientation of the device as described in the figures. For example, if the device in the figures were inverted, a device described as "above" or "on top of" other devices or structures would subsequently be positioned as "below" or "under" other devices or structures. Thus, the exemplary term "above" can include both "above" and "below." The device may also be positioned in other different ways (rotated 90 degrees or in other orientations), and the spatial relative descriptions used herein will be interpreted accordingly.
[0042] Furthermore, it should be noted that the use of terms such as "first" and "second" to define components is merely for the purpose of distinguishing the corresponding components. Unless otherwise stated, these terms have no special meaning and therefore should not be construed as limiting the scope of protection of this application. In addition, although the terminology used in this application is selected from commonly known and used terms, some terms mentioned in this application's specification may have been chosen by the applicant according to his or her judgment, and their detailed meanings are explained in the relevant sections of this description. Moreover, this application should be understood not only through the actual terms used, but also through the meaning implied by each term.
[0043] It should be understood that when a component is referred to as "on another component," "connected to another component," "coupled to another component," or "in contact with another component," it can be directly on, connected to, coupled to, or in contact with that other component, or there may be an intervening component. In contrast, when a component is referred to as "directly on another component," "directly connected to," "directly coupled to," or "directly in contact with" another component, there is no intervening component. Similarly, when a first component is referred to as "electrically contacting" or "electrically coupled to" a second component, there is an electrical path between the first and second components that allows current to flow. This electrical path may include capacitors, coupled inductors, and / or other components that allow current to flow, even if there is no direct contact between the conductive components.
[0044] Flowcharts are used in this application to illustrate the operations performed by the system according to embodiments of this application. It should be understood that the preceding or following operations are not necessarily performed in exact order. Instead, various steps can be processed in reverse order or simultaneously. Furthermore, other operations may be added to these processes, or one or more steps may be removed from these processes.
[0045] Reference Figure 1 This application proposes an automatic multi-scenario adaptable printing access method 100 (hereinafter referred to as printing access method 100). This printing method 100 is applicable to electronic devices. The electronic device includes a host, which is adapted to establish a communication link with at least one printer, and the host includes an application terminal. It should be noted that this application does not limit the type of application terminal; in some embodiments, the application terminal includes a web application, in some embodiments, the application terminal includes a hybrid application, and in some embodiments, the application terminal includes a native application. Furthermore, this application does not limit the number of application terminals; in some embodiments, the host includes one application terminal, and in some embodiments, the host includes multiple application terminals. On the other hand, this application does not limit the type of communication link; in some embodiments, the communication link includes a wired communication link.
[0046] Continue to refer to Figure 1 The print access method 100 includes the following steps. Step S1 is to generate at least one Bluetooth node corresponding to the printer in response to the host establishing a communication link with at least one printer. For example, in some embodiments, after the host establishes a communication link with the printer, the Bluetooth node corresponding to the printer is generated internally within the host. Correspondingly, when the communication link between the host and the printer is disconnected, the host deregisters the Bluetooth node corresponding to the printer. Through the above method, the application can effectively identify printers that have communication links with the host, and the possibility of interference between the Bluetooth nodes corresponding to multiple printers when the host is suitable for establishing communication links with multiple printers is reduced.
[0047] Continue to refer to Figure 1 Step S2 involves establishing a Bluetooth Low Energy channel between the application and the Bluetooth node corresponding to the printer specified in the print request received by the application. Further details can be found in the documentation. Figure 2 In some embodiments, step S2 further includes the following sub-steps. Step S21 is to register the Bluetooth node to the host's Bluetooth Low Energy (BLE) list. In some embodiments, step S21 further includes: in response to receiving a broadcast from the Bluetooth node, registering the Bluetooth node to the BLE list via the host. That is, in some embodiments, broadcasting the Bluetooth node enables the host to discover the Bluetooth node, thereby enabling the host to register the Bluetooth node to the host's BLE list, thus conveniently and effectively registering the Bluetooth node on the host. It should be noted that each printer's corresponding Bluetooth node has a different Bluetooth name, so the corresponding printer can be determined based on the Bluetooth name in the BLE list. Furthermore, it is understood that once a printer's corresponding Bluetooth node is registered to the BLE list, when the printer re-establishes a communication link with the host, since the Bluetooth name of the corresponding Bluetooth node remains unchanged, it is not necessary to re-register the Bluetooth node to the BLE list.
[0048] Continue to refer to Figure 2 Step S22 involves the application generating a connection request based on printing requirements, the connection request including the connection target address. Step S23, in response to determining the defined address of the Bluetooth node corresponding to the connection target address, enables the application to establish a Bluetooth Low Energy (BLE) channel with the Bluetooth node. It can be understood that the application generates a corresponding connection target address based on the printer selected by the user. After the application sends a connection request to the host, the host determines that the connection target address matches the defined address, and then enables the application to establish a BLE channel with the Bluetooth node. In other words, through the above steps, the application can effectively establish a BLE channel with the Bluetooth node corresponding to the target printer. In some embodiments, the connection request also includes the Bluetooth name of the Bluetooth node, and the defined address is a MAC address. Therefore, under the premise that the Bluetooth name and MAC address correspond, the application establishes a BLE channel with the Bluetooth node. This setting can further improve the accuracy of BLE communication connections and avoid the application establishing a BLE communication connection with a Bluetooth device or Bluetooth node that is not the target printer when multiple Bluetooth nodes or Bluetooth devices exist.
[0049] Continue to refer to Figure 2 In some embodiments, step S2 further includes step S24. Specifically, step S24 involves obtaining the printing characteristic value of the Bluetooth node and determining whether the device corresponding to the Bluetooth node has printing capabilities based on the printing characteristic value. It should be noted that in some scenarios, due to the existence of multiple Bluetooth nodes or devices, to prevent the application from establishing a Bluetooth Low Energy communication connection with a non-target printer object, such as a Bluetooth speaker, and subsequently sending erroneous commands, some embodiments, after connecting to the corresponding Bluetooth node, read the corresponding printing characteristic value through the GATT (Generic Attribute Profile) service and determine whether the Bluetooth Low Energy connected object has printing functionality based on this printing characteristic value, thereby further determining whether it is connected to the Bluetooth node corresponding to the target printer. Step S24 further reduces the possibility of the application subsequently transmitting erroneous commands to Bluetooth devices or Bluetooth nodes that are not the target printer, preventing the Bluetooth devices or Bluetooth nodes of the non-target printer from executing erroneous commands. It is understood that in some embodiments, once it is determined that the application has established a Bluetooth Low Energy communication connection with a non-target printer object, no further commands related to printing needs are sent to that object through the application.
[0050] Continue to refer to Figure 1Step S3 involves acquiring the print request generated by the application based on printing needs through the Bluetooth Low Energy (BLE) channel, and generating corresponding print instructions based on the print request. It should be noted that in some embodiments, after determining that the connected Bluetooth node corresponds to the target printer, the application obtains the service and channel specified by the Bluetooth node through an agreed-upon UUID (Universally Unique Identifier), thereby writing the subsequently generated print request onto the channel with a specific characteristic value in the BLE channel. Correspondingly, by monitoring the channel corresponding to the specific characteristic value, the application can obtain the corresponding print request in the BLE channel. In some embodiments, the print request includes an initial print instruction, which includes an instruction type, and the instruction type includes ESC and TSPL instructions. Further details can be found by referring to... Figure 3 In some embodiments, step S3 further includes the following sub-steps: Step S31 is to generate a corresponding print instance based on the print request. Step S32 is to send the initial print command to the host's print service process by calling the corresponding interface according to the instruction type through the print instance. Step S33 is to generate the corresponding print command through the print service process based on the initial print command. Specifically, in some embodiments, a print instance corresponds one-to-one with a print request, and the print instance holds the aidl (Android Interface Definition Language) interface of the print service process, thereby enabling the print instance to send the initial print command to the print service process. In addition, since a print instance corresponds one-to-one with a print request, when different applications on the host generate multiple different print requests or multiple different print requests are generated sequentially in the same application, the corresponding print instance can be used to sort and manage the various print requests that need to be processed on the host, thereby coordinating multiple print requests. It should be noted that, since a print instance corresponds one-to-one with a print request, when a print request is completed, the corresponding print instance is also deregistered, that is, the lifecycle of the print instance is generated and disappears with the corresponding print request. Furthermore, in some embodiments, all initial print commands generated by the same print request are sent to the print service process through the same print instance.
[0051] Continue to refer to Figure 1 Step S4 involves sending the print command from the host to the designated printer via a communication link. It is understood that the printer is adapted to perform printing operations based on the print command. The print access method 100 described above can generate a Bluetooth node corresponding to the printer. After receiving the print request at the application end, a low-power Bluetooth channel is established between the Bluetooth node and the corresponding printer. Then, the print request from the application end is converted into a print command that the printer can execute through the low-power Bluetooth channel. This achieves the printing function while avoiding the integration and calling of the print SDK on the host, thus conveniently implementing printing capabilities and effectively reducing maintenance and adaptation costs.
[0052] In some embodiments, the print request in step S3 includes a query request, and accordingly, further refer to Figure 4 In these embodiments, the print access method 100 further includes the following steps: Step S5: The printer generates a query result according to the print instruction corresponding to the query request and sends the query result to the application. Step S6: The application displays the query result. For example, in some embodiments, the printer writes the query result back to the corresponding socket, and then the application receives the query result via a Bluetooth Low Energy channel. The query result includes printing status, paper out status, firmware version, etc.
[0053] Further references are provided below. Figure 5 The printing access method 100 is illustrated using a specific example. The host application is a web application, specifically a browser. Specifically, the steps include: registering the InnerPrinter node (generating a corresponding Bluetooth node for the printer and registering it on the host after establishing a communication link); scanning for BLE devices (the host scans for existing Bluetooth devices to find the printer's corresponding Bluetooth node); connecting the browser to the BLE printing device (establishing a Bluetooth Low Energy channel); determining if the device is an InnerPrinter (using printing characteristic values to determine if the connected Bluetooth node has printing capabilities, i.e., verifying a correct connection to the printer's Bluetooth node); if the determination is negative, normal BLE communication (the application communicates normally with the Bluetooth node, without sending or receiving print requests to or from the Bluetooth low-power channel); and if the determination is positive, obtaining the channel based on agreed-upon characteristic values (identifying the Bluetooth low-power channel used for printing requests). The process involves several steps: First, listening for print requests from a channel (monitoring the channel corresponding to a specific characteristic value). Second, determining if a print request has arrived (checking if a print request has been transmitted to the monitored channel). If so, parsing the ESC / TSPL command and creating a print client (generating a corresponding print instance based on the print request). Third, sending the command to the print service (converting the print request into an initial print command using the print instance and sending it to the print service process). Finally, the printer receiving the command and printing (the print service process converts the initial print command into a print command and sends it to the printer via the communication link, enabling the printer to perform the print operation).
[0054] Reference Figure 6An embodiment of this application also proposes an electronic device 200. For example... Figure 6 As shown, the electronic device 200 includes a host 20, which is adapted to establish a communication link with at least one printer. In this embodiment, the host 20 includes a BLE printing module 21 and an application terminal 22. In this embodiment, the BLE printing module 21 includes a BLE channel unit 211 and a request listening unit 212. Specifically, the BLE channel unit 211 is adapted to generate a Bluetooth node corresponding to at least one printer in response to the host 20 establishing a communication link with at least one printer. The Bluetooth node is adapted to establish a low-power Bluetooth channel with the application terminal 22. The request listening unit 212 is adapted to obtain the print request generated by the application terminal 22 according to the received print requirements through the low-power Bluetooth channel, and generate a corresponding print instruction according to the print request. In addition, in this embodiment, the host 20 is also adapted to send the print instruction to the printer through the communication link. With the above settings, the electronic device 200 can build a low-power Bluetooth channel through the Bluetooth node for the application terminal 22 to transmit print requests to the corresponding printer. Then, the print request of the application terminal 22 is converted into a print instruction that the printer can execute through the low-power Bluetooth channel and sent to the printer through the communication link. This achieves the printing function while avoiding the integration and calling of the printing SDK on the host 20. Therefore, it can easily realize printing capabilities and effectively reduce maintenance and adaptation costs.
[0055] Continue to refer to Figure 6 In some embodiments, the BLE channel unit 211 is adapted to register the Bluetooth node to the Bluetooth Low Energy list of the host 20, and the application terminal 22 is adapted to generate a connection request according to printing requirements. The connection request includes a connection target address. Furthermore, the application terminal 22 is also adapted to establish a Bluetooth Low Energy channel with the Bluetooth node in response to determining the defined address of the Bluetooth node corresponding to the connection target address. In some embodiments, the host 20 is also adapted to register the Bluetooth node to the Bluetooth Low Energy list in response to receiving a broadcast from the Bluetooth node, thereby conveniently and efficiently registering Bluetooth nodes on the host.
[0056] Continue to refer to Figure 6In some embodiments, the application terminal 22 is also adapted to acquire the printing characteristic value of the Bluetooth node, and determine whether the device corresponding to the Bluetooth node has printing capability based on the printing characteristic value, thereby further determining whether to connect to the Bluetooth node corresponding to the target printer. In some embodiments, the print request includes an initial print instruction, which includes an instruction type, including ESC and TSPL instructions. The request listening unit 212 is adapted to generate a corresponding print instance according to the print request. The print instance is adapted to call the corresponding interface according to the instruction type to send the initial print instruction to the print service process of the host 20. In addition, the print service process is adapted to generate a corresponding print instruction according to the initial print instruction. In some embodiments, the request listening unit 212 further includes an instance factory, which is adapted to create corresponding print instances according to different print requests and destroy the corresponding print instances after the print request is completed. Multiple print services can be accessed through the instance factory, which is compatible with different versions of print interfaces, thereby dynamically switching different print implementations according to needs. In some embodiments, the print request includes a query request. The printer is adapted to generate a query result according to the print instruction corresponding to the query request and send the query result to the application terminal 22. The application terminal 22 is adapted to display the query result.
[0057] The above has been referred to Figure 6 A brief description of the electronic device 200 is given below. The following section will further explain the working process of the electronic device 200 and the corresponding methods for setting up and testing the BLE printing module 21, using specific examples.
[0058] First, refer to Figure 7 The method 300 for setting up the BLE printing module in the host 20 includes the following steps. Step S101 is to verify the Bluetooth Low Energy (BLE) channel in the host's Bluetooth module and determine the output position of the BLE channel. For example, in some embodiments, the writeCharacteristic method of the Gatt service is used to verify the BLE channel. Specifically, after establishing BLE communication between the host's application and the Bluetooth device, it is determined whether there is corresponding printing information in the corresponding BLE service. If there is corresponding printing information, the verification result of the BLE channel is normal, and then the output position of the BLE channel is further determined.
[0059] Continue to refer to Figure 7Step S102 involves setting the BLE request listening unit 212 at the output position. Exemplarily, in some embodiments, the request listening unit 212 includes a thread loop that continuously intercepts communication data in the Bluetooth Low Energy channel. If the communication data contains a pre-agreed print-related request (i.e., a print request), the request listening unit 212 further processes the print request. If the communication data does not contain a print request, the request listening unit 212 does not continue to respond, thereby allowing the application terminal 22 to continue normal Bluetooth Low Energy communication with the connected Bluetooth device.
[0060] Continue to refer to Figure 7 Step S103 involves placing the call entry point of the print service process, namely the AIDL interface, on the request listening unit 212, so that the request listening unit 212 can parse the print request received from the low-power Bluetooth channel into an ESC command or a TSPL command, and then transmit the ESC command or TSPL command to the print service process through the AIDL interface.
[0061] Continue to refer to Figure 7 Step S104 involves testing the printing capability of the BLE printing module 21 on the application terminal 22. For example, in some embodiments, the application terminal 22 selects a corresponding printer, and the BLE printing module 21 generates the print content corresponding to the print request from the application terminal 22. If the print content corresponds to the print request, then the printing capability of the BLE printing module 21 is normal.
[0062] Next, the operation of the electronic device 200 will be described using a handheld POS machine as the electronic device 200, and the printer includes a built-in printer inside the handheld POS machine and an external printer located on the periphery of the handheld POS machine. It should be noted that this application does not limit the positional relationship between the printer and the electronic device. In some embodiments, the printer is located inside the electronic device, thus serving as part of the electronic device; in other embodiments, the printer is located outside the electronic device, thus being independent of the electronic device.
[0063] Specifically, the built-in printer maintains a continuous connection with the host 20 via a wired communication link, and this built-in printer is suitable for printing receipts. When the user operates the application terminal 22 to print a receipt, the application terminal 22 can discover the Bluetooth node InnerPrinter corresponding to the built-in printer by scanning surrounding Bluetooth devices. After the user confirms that they will use the built-in printer to print the receipt (i.e., the user selects the Bluetooth node InnerPrinter through the application terminal 22), the application terminal 22 establishes a Bluetooth Low Energy (BLE) channel with the Bluetooth node InnerPrinter. Subsequently, the application terminal 22 generates a corresponding print request based on the user's printing needs and transmits it to the BLE channel. The request listening unit 212 receives the print request from the BLE channel, converts the print request into a corresponding initial print command, and sends the initial print command to the print service process. The print service process further converts the initial print command into a print command and sends the print command to the built-in printer via the wired communication link, thereby realizing the operation of printing a receipt through the built-in printer on the application terminal. Understandably, since the built-in printer and host 20 are encapsulated in the handheld POS machine and maintain a continuous wired communication link connection, after the handheld POS machine is powered on, the BLE channel unit 211 causes the host 20 to generate a Bluetooth node InnerPrinter corresponding to the built-in printer.
[0064] In contrast, the external printer is suitable for printing labels and only connects to the host 20 via a wired communication link when the handheld POS machine needs to print labels. Understandably, when the user selects the external printer for label printing, the external printer maintains a connection with the host 20 via the wired communication link. Specifically, when the external printer is connected to the host 20 via the wired communication link, the BLE channel unit 211 causes the host 20 to internally generate a Bluetooth node, ExternalPrinter, corresponding to the external printer. The subsequent operation of printing labels via the external printer on the application side is the same as the operation of printing receipts via the built-in printer on the application side, and will not be repeated. It should be noted that when the external printer and the host 20 no longer maintain a wired communication link connection, the corresponding Bluetooth node, ExternalPrinter, is deregistered. This reduces the probability of the user selecting the wrong printer or forgetting to connect the required printer when using the handheld POS machine, thereby improving printing efficiency.
[0065] It should be noted that in some embodiments, the application terminal 22 includes a web application, and the web application has corresponding security restrictions, which prevent the web application, such as a browser, from providing the Bluetooth channel corresponding to classic Bluetooth (i.e., ordinary Bluetooth). However, the web application supports the Bluetooth Low Energy (BLE) channel; for example, the browser's Web Bluetooth API interface supports BLE, thus enabling the invocation of printing capabilities through the BLE channel. Correspondingly, native applications and hybrid applications also support the BLE channel, thus also enabling the invocation of printing capabilities through the BLE channel. Therefore, this application can be applied to various different application terminals such as web applications, native applications, and hybrid applications, without the need to integrate a corresponding printing SDK on the application terminal, achieving a more convenient effect of invoking printing capabilities. In addition, compared to communicating with the printing service via socket to send printing commands, the application terminal 22 does not need to manage socket communication itself, such as agreeing on socket addresses, socket allocation, and release.
[0066] In addition, this application also proposes a computer-readable medium storing computer program code that implements the above-described printing access method 100 when executed by a processor.
[0067] The basic concepts have been described above. Obviously, for those skilled in the art, the above disclosure is merely illustrative and does not constitute a limitation of this application. Although not explicitly stated herein, those skilled in the art may make various modifications, improvements, and corrections to this application. Such modifications, improvements, and corrections are suggested in this application, and therefore remain within the spirit and scope of the exemplary embodiments of this application.
[0068] Furthermore, this application uses specific terms to describe embodiments of the application. For example, "an embodiment," "one embodiment," and / or "some embodiments" refer to a particular feature, structure, or characteristic related to at least one embodiment of the application. Therefore, it should be emphasized and noted that "an embodiment," "one embodiment," or "an alternative embodiment" mentioned twice or more in different locations in this specification do not necessarily refer to the same embodiment. In addition, certain features, structures, or characteristics in one or more embodiments of the application can be appropriately combined.
[0069] Similarly, it should be noted that, in order to simplify the description of the present application and thus aid in the understanding of one or more embodiments, the foregoing description of the embodiments of the present application sometimes combines multiple features into a single embodiment, drawing, or description thereof. However, this disclosure method does not imply that the subject matter of the present application requires more features than those mentioned in the claims. In fact, the embodiments contain fewer features than all the features of the single embodiments disclosed above.
[0070] In some embodiments, numbers describing the quantity of components and attributes are used. It should be understood that such numbers used in the description of embodiments are modified in some examples with the terms "approximately," "approximately," or "generally." Unless otherwise stated, "approximately," "approximately," or "generally" indicates that the numbers are allowed to vary by ±20%. Accordingly, in some embodiments, the numerical parameters used in the specification and claims are approximate values, which may be changed depending on the characteristics required by individual embodiments. In some embodiments, numerical parameters should take into account specified significant digits and employ a general method of digit reservation. Although the numerical ranges and parameters used to confirm their breadth of scope in some embodiments of this application are approximate values, in specific embodiments, such values are set as precisely as feasible.
[0071] Some aspects of this application can be executed entirely by hardware, entirely by software (including firmware, resident software, microcode, etc.), or by a combination of hardware and software. The aforementioned hardware or software may be referred to as a "data block," "module," "engine," "unit," "component," or "system." The processor may be one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DAPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors, or combinations thereof. Furthermore, aspects of this application may manifest as computer products residing in one or more computer-readable media, including computer-readable program code. For example, computer-readable media may include, but are not limited to, magnetic storage devices (e.g., hard disks, floppy disks, magnetic tapes, etc.), optical discs (e.g., compressed CDs, digital multifunction DVDs, etc.), smart cards, and flash memory devices (e.g., cards, sticks, key drives, etc.).
[0072] A computer-readable medium may contain a propagated data signal containing computer program code, for example, on baseband or as part of a carrier wave. This propagated signal may take various forms, including electromagnetic, optical, and so on, or suitable combinations thereof. A computer-readable medium can be any computer-readable medium other than a computer-readable storage medium, which can be connected to an instruction execution system, apparatus, or device to enable communication, propagation, or transmission of a program for use. The program code located on the computer-readable medium can be propagated through any suitable medium, including radio, cable, fiber optic cable, radio frequency signals, or similar media, or any combination of the above media.
[0073] Although this application has been described with reference to specific embodiments, those skilled in the art should recognize that the above embodiments are only used to illustrate this application, and various equivalent changes or substitutions can be made without departing from the spirit of this application. Therefore, any changes or modifications to the above embodiments within the essential spirit of this application will fall within the scope of the claims of this application.
Claims
1. A method for automatically adapting to multiple scenarios for print access, characterized in that, Applicable to an electronic device, the electronic device including a host, the host being adapted to establish a communication link with at least one printer, the host including an application terminal, the print access method including: In response to the establishment of a communication link between the host and the at least one printer, a Bluetooth node corresponding to the at least one printer is generated; The application establishes a low-power Bluetooth channel with the Bluetooth node corresponding to the printer specified in the print request received by the application. The application receives the print request generated by the application based on the printing requirements through the low-power Bluetooth channel, and generates the corresponding print instruction based on the print request. The printing command is sent from the host to the designated printer via the communication link.
2. The automatic multi-scenario print access method as described in claim 1, characterized in that, The application includes web applications.
3. The automatic multi-scenario print access method as described in claim 2, characterized in that, The application side also includes hybrid applications and / or native applications.
4. The automatic multi-scenario print access method as described in claim 1, characterized in that, The step of establishing a Bluetooth Low Energy channel between the application and the Bluetooth node corresponding to the printer specified in the print request received by the application further includes: Register the Bluetooth node to the host's Bluetooth Low Energy list; The application generates a connection request based on the printing requirements, and the connection request includes the target address for connection. In response to determining that the connection target address corresponds to the defined address of the Bluetooth node, the application establishes the Bluetooth Low Energy channel with the Bluetooth node.
5. The automatic multi-scenario print access method as described in claim 4, characterized in that, The step of registering the Bluetooth node to the host's Bluetooth Low Energy list further includes: In response to receiving a broadcast from the Bluetooth node, the host registers the Bluetooth node to the Bluetooth Low Energy list.
6. The automatic multi-scenario print access method as described in claim 4, characterized in that, The step of establishing a Bluetooth Low Energy channel between the application and the Bluetooth node corresponding to the printer specified in the print request received by the application further includes: Obtain the printing feature value of the Bluetooth node, and determine whether the device corresponding to the Bluetooth node has printing capability based on the printing feature value.
7. The automatic multi-scenario print access method as described in claim 1, characterized in that, The print request includes an initial print instruction, which includes an instruction type, including ESC and TSPL instructions. The step of obtaining the print request generated by the application based on the print requirements through the Bluetooth Low Energy channel, and generating corresponding print instructions based on the print request, further includes: Generate a corresponding print instance based on the print request; The initial print command is sent to the host's print service process by calling the corresponding interface according to the command type through the print instance; The printing service process generates the corresponding printing instruction based on the initial printing instruction.
8. The automatic multi-scenario print access method as described in claim 1, characterized in that, The print request includes a query request, and the automatic adaptation method for print access across multiple scenarios further includes: The printer generates a query result based on the print instruction corresponding to the query request, and sends the query result to the application. The query results are displayed through the application.
9. The automatic adaptation method for printing access in multiple scenarios as described in claim 1, characterized in that, The communication link includes a wired communication link.
10. An electronic device, characterized in that, The electronic device includes: The host computer, including a BLE printing module and an application terminal, is adapted to establish a communication link with at least one printer. The BLE printing module includes: BLE channel unit, the BLE channel unit is adapted to generate a Bluetooth node corresponding to the at least one printer in response to the host establishing a communication link with the at least one printer, the Bluetooth node being adapted to establish a low-power Bluetooth channel with the application terminal; A request listening unit is configured to acquire a print request generated by the application based on the received print requirements via the Bluetooth Low Energy channel, and generate a corresponding print instruction based on the print request. The host is also adapted to send the printing command to the printer via the communication link.
11. The electronic device as claimed in claim 10, characterized in that, The BLE channel unit is adapted to register the Bluetooth node to the host's Bluetooth Low Energy list; The application is adapted to generate a connection request based on the printing requirements, wherein the connection request includes a connection target address; The application terminal is also adapted to establish the Bluetooth Low Energy channel with the Bluetooth node in response to determining that the connection target address corresponds to the defined address of the Bluetooth node.
12. The electronic device as claimed in claim 11, characterized in that, The host is also adapted to register the Bluetooth node to the Bluetooth Low Energy list in response to receiving a broadcast from the Bluetooth node.
13. The electronic device as claimed in claim 11, characterized in that, The application terminal is also adapted to acquire the printing characteristic value of the Bluetooth node, and determine whether the device corresponding to the Bluetooth node has printing capability based on the printing characteristic value.
14. The electronic device as claimed in claim 10, characterized in that, The print request includes an initial print instruction, which includes an instruction type, including ESC and TSPL instructions. The request listening unit is adapted to generate a corresponding print instance based on the print request. The print instance is adapted to call the corresponding interface according to the instruction type to send the initial print instruction to the print service process of the host. The print service process is adapted to generate the corresponding print instruction based on the initial print instruction.
15. The electronic device as claimed in claim 10, characterized in that, The print request includes a query request. The printer is adapted to generate a query result based on the print instruction corresponding to the query request and send the query result to the application terminal. The application terminal is adapted to display the query result.
16. The electronic device as claimed in claim 10, characterized in that, The communication link includes a wired communication link.
17. The electronic device as claimed in claim 10, characterized in that, The application includes web applications.
18. The electronic device as claimed in claim 10, characterized in that, The application side also includes hybrid applications and / or native applications.
19. A computer-readable medium storing computer program code, which, when executed by a processor, implements the automatic adaptation method for printing access in multiple scenarios as described in any one of claims 1-9.