An adaptive flow control method based on print content feature analysis

By using an adaptive flow control method based on the analysis of printed content characteristics, the printhead temperature and data transmission strategy are dynamically adjusted, solving the problem of improper buffer management in existing technologies. This enables accurate prediction and control of buffer overflow, improving the efficiency and reliability of the printer.

CN121979464BActive Publication Date: 2026-06-26LICHU BUSINESS

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
LICHU BUSINESS
Filing Date
2026-04-03
Publication Date
2026-06-26

AI Technical Summary

Technical Problem

Existing flow control technologies cannot adapt to differences in print content density, device thermal characteristics, and communication environments, leading to improper buffer management and the risk of buffer overflow during long-term continuous printing.

Method used

By segmenting and analyzing the data stream to be printed, extracting energy density characteristics, calculating virtual heat values ​​and temperature correction factors, dynamically adjusting the waiting time based on the number of bytes in the data segment and the transmission rate, and using a sliding window to update the error ratio queue and an adaptive grading threshold to adjust the baseline coefficient, accurate prediction and control of buffer overflow can be achieved.

Benefits of technology

It achieves accurate prediction and control of buffer overflow risk, improves the reliability and adaptability of flow control algorithm in complex application scenarios, and significantly improves printing efficiency and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121979464B_ABST
    Figure CN121979464B_ABST
Patent Text Reader

Abstract

The application provides a self-adaptive flow control method based on printing content feature analysis, relates to the field of data flow control of a thermal printer, and comprises the following steps: segmenting a to-be-printed data stream and extracting energy density values of each data segment; calculating a virtual heat value in an iterative mode, calculating a physical printing time consumption; calculating a transmission time consumption according to the number of bytes of the data segment and the effective transmission rate of a communication interface; obtaining an actual time consumption of the data segment from sending completion to printing completion, obtaining an error ratio based on the ratio of the estimated time consumption to the actual time consumption, updating an error ratio queue by using a sliding window and calculating the standard deviation thereof, determining a self-adaptive grading threshold value according to the standard deviation, updating a reference coefficient according to the grade to which the error ratio belongs, and dynamically adjusting a heat dissipation attenuation coefficient based on actual time consumption feedback and a virtual heat state. The application realizes accurate prediction and control of the risk of buffer overflow.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data flow control technology for thermal printers, and in particular to an adaptive flow control method based on print content feature analysis. Background Technology

[0002] Thermal printers heat the printhead to develop the color in thermal paper, and their printing speed is significantly affected by the printhead temperature. When printing high-density images continuously, the increased printhead temperature leads to longer actual printing time. If the host computer transmits data at a fixed rate, it can easily cause the printer buffer to overflow, resulting in data loss, garbled text, or paper jams.

[0003] Existing flow control technologies control data transmission through fixed delays or simple rate limits, but they cannot adapt to differences in print content density, device thermal characteristics, and communication environments. In practical applications, fixed delay strategies face a dilemma: setting overly conservative delays can prevent buffer overflows but significantly reduces printing efficiency, while setting more aggressive delays improves efficiency but still carries the risk of overflow in high-density printing scenarios. This one-size-fits-all control approach struggles to find a balance between ensuring reliability and improving efficiency.

[0004] Chinese patent CN112039835B discloses an adaptive polling time estimation method, apparatus, device, and storage medium. This method establishes a connection with the printer via TCP / IP protocol and polls the printer's current remaining buffer before sending data. Data is only sent when the remaining buffer is sufficient to hold a complete print frame. However, it cannot perform fine-grained flow control based on the print content, and may lead to improper buffer management in long-term continuous printing scenarios. Summary of the Invention

[0005] In view of this, the present invention provides an adaptive flow control method based on print content feature analysis to solve the technical problem that the flow control strategy in the prior art cannot adapt to the difference in print content density, resulting in improper buffer management during long-term continuous printing, and to achieve accurate prediction and control of buffer overflow risk.

[0006] The technical solution of this invention is implemented as follows: This invention provides an adaptive flow control method based on print content feature analysis, comprising:

[0007] S1. The data stream to be printed is segmented to obtain multiple data segments. Energy density features are extracted in different ways according to the data segment type to obtain the energy density value of each data segment.

[0008] S2. The virtual heat value is calculated iteratively. The temperature correction factor is determined based on the relationship between the virtual heat value and the safety threshold. The physical printing time is calculated by combining the number of bytes in the data segment, the energy density value, the baseline coefficient, and the temperature correction factor. The virtual heat value is obtained by adding the energy density value of the current data segment after heat dissipation attenuation processing of the historical virtual heat value.

[0009] S3. Calculate the transmission time based on the number of bytes in the data segment and the effective transmission rate of the communication interface. Determine the estimated time based on the physical printing time and the transmission time. If the physical printing time exceeds the transmission time, insert a waiting time before sending the data segment. The waiting time is the difference between the physical printing time and the transmission time.

[0010] S4. Obtain the actual time taken from the completion of data segment transmission to the completion of printing. Based on the ratio of the estimated time to the actual time, obtain the error ratio. Update the error ratio queue using a sliding window and calculate its standard deviation. Determine the adaptive grading threshold based on the standard deviation. Update the baseline coefficient according to the level to which the error ratio belongs. When the virtual heat value exceeds the safety threshold and the error ratio meets the preset conditions, adjust the heat dissipation attenuation coefficient based on the error ratio.

[0011] Based on the above technical solutions, preferably, the data segment type includes bitmap data segments and instruction data segments, and step S1 specifically includes:

[0012] When the data segment is a bitmap data segment, the image is divided into multiple slices in the vertical direction. All pixels in the slice are traversed and the number of black pixels is counted. The energy density value of the slice is obtained based on the ratio of the number of black pixels to the total number of pixels in the slice.

[0013] When the data segment is an instruction data segment, the print control instruction sequence in the data stream is parsed, and the character width magnification factor, character height magnification factor, and bold mode coefficient are extracted. The time factor is obtained based on the product relationship of the three factors.

[0014] The time factor is normalized to obtain the energy density value of the instruction data segment.

[0015] Based on the above technical solutions, preferably, the specific steps for calculating the virtual heat value include:

[0016] Initialize virtual heat variables when the printing device starts up =0; where the virtual heat variable is 0. Used to simulate the heat accumulation state of the printhead;

[0017] When processing the first When processing a data segment, the historical virtual heat value is processed to reduce heat loss and obtain residual heat. This residual heat is then added to the normalized energy density value of the current data segment to obtain the updated virtual heat value.

[0018] ;

[0019] in, Indicates the first The virtual heat value of each data segment. To complete the first The virtual popularity value after each data segment This is the heat dissipation attenuation coefficient. For the first The normalized energy density values ​​of each data segment.

[0020] Based on the above technical solutions, preferably, the formula for calculating the temperature correction factor is as follows:

[0021] ;

[0022] in, Indicates the first Temperature correction factor for each data segment For temperature sensitivity coefficient, The safe heat threshold.

[0023] Based on the above technical solutions, preferably, when the data segment is a bitmap data segment, the calculation steps for the physical printing time are as follows:

[0024] Get the The total number of pixels, normalized energy density, temperature correction factor, and bitmap baseline coefficients of each slice corresponding to a bitmap data segment;

[0025] The physical printing time of a bitmap data segment is calculated based on the product of the total number of pixels in the slice, normalized energy density, temperature correction factor, and bitmap baseline coefficient:

[0026] ;

[0027] in, Indicates the first Physical printing time for each bitmap data segment Indicates the bitmap baseline coefficient. Indicates the total number of pixels. Indicates the height of the slice. Indicates the width of the slice. To normalize the energy density, For the first Temperature correction factor for each bitmap data segment.

[0028] Based on the above technical solutions, preferably, when the data segment is an instruction data segment, the calculation steps for the physical printing time are as follows:

[0029] Get the The time scaling factor, temperature correction factor, and instruction base coefficient of each instruction data segment;

[0030] The physical printing time of the instruction data segment is calculated based on the product relationship of the time multiplication factor, temperature correction factor, and instruction base coefficient.

[0031] ;

[0032] in, Indicates the first The physical printing time of each instruction data segment As the command baseline coefficient, For the first Time scaling factor for each instruction data segment For the first Temperature correction factor for each instruction data segment.

[0033] Based on the above technical solutions, preferably, step S3 specifically includes:

[0034] Transmission time is calculated based on the ratio of the number of bytes in the data segment to the effective transmission rate of the communication interface.

[0035] Compare the time spent on physical printing with the time spent on transmission:

[0036] When the physical printing time exceeds the transmission time, it is determined that there is a risk of buffer overflow, and the waiting time is calculated based on the difference between the two.

[0037] If the physical printing time does not exceed the transmission time, it is determined that there is no risk of buffer overflow, and the data segment is sent directly without inserting a waiting time.

[0038] The estimated time is determined based on the transmission time and the physical printing time:

[0039] ;

[0040] in, This represents the estimated time taken for the i-th data segment. Indicates the transmission time. This indicates the time taken for physical printing.

[0041] Based on the above technical solutions, preferably, the step of updating the error ratio queue using a sliding window specifically includes:

[0042] Initialize the error ratio history queue, wherein the error ratio history queue is used to store the most recent Error ratio values ​​for each data segment;

[0043] When the After each data segment is printed, the actual time taken from the completion of sending to the completion of printing for that data segment is obtained, and the error ratio is calculated based on the ratio of the estimated time to the actual time. ;

[0044] Determine the current length of the historical queue for the error ratio:

[0045] If the queue length has been reached Then, remove the oldest error ratio value from the queue while keeping the queue length constant. Then, the newly calculated error ratio is inserted at the end of the queue for sliding window updates;

[0046] If the queue length has not been reached If the error ratio is not found, the error ratio is directly inserted at the end of the queue for sliding window updates.

[0047] Based on the above technical solutions, preferably, the step of determining the adaptive grading threshold according to the standard deviation specifically includes:

[0048] The mean and standard deviation of the error ratio are calculated based on the historical error ratio queue.

[0049] An adaptive dead zone radius is set based on the product of standard deviation and noise tolerance coefficient, while constraining the dead zone radius to be no less than a preset lower limit:

[0050] ;

[0051] in, Indicates the dead zone radius, This is the lower limit of the dead zone radius. This is the noise tolerance factor. Indicates standard deviation;

[0052] A multi-level correction region is formed based on the dead zone radius, including the dead zone, fine-tuning region, fast-tuning region and anomaly region. The upper limit of the fine-tuning region is twice the dead zone radius, and the upper limit of the fast-tuning region is three times the dead zone radius.

[0053] More preferably, the adjustment of the heat dissipation attenuation coefficient based on the error ratio specifically includes:

[0054] Calculate the error deviation ;

[0055] The error level is determined based on the relationship between the error deviation and the adaptive grading threshold.

[0056] when If the area is identified as a dead zone, no baseline coefficient correction will be performed.

[0057] when When the time is determined to be in the fine-tuning zone, the learning rate is 0.1, and the baseline coefficient is adjusted.

[0058] when When the time is determined to be in the fast adjustment region, the learning rate is 0.5, and the baseline coefficient is adjusted.

[0059] when or If the area is identified as an abnormal region, no correction will be made.

[0060] The formula for calculating the benchmark coefficient correction is as follows:

[0061] ;

[0062] ;

[0063] in, This represents the updated bitmap baseline coefficient for the bitmap data segment. This represents the bitmap baseline coefficient before the bitmap data segment is updated. This indicates the update instruction base coefficient for the instruction data segment. This represents the instruction baseline coefficient before the instruction data segment is updated. Indicates the learning rate;

[0064] Determine whether the virtual popularity value exceeds the safety threshold and whether the error deviation meets the requirements. :

[0065] If so, proceed with the heat dissipation attenuation coefficient update process:

[0066] ;

[0067] in, This indicates the heat dissipation attenuation coefficient after the update. The heat dissipation attenuation coefficient before the update. The learning rate is the heat dissipation attenuation coefficient. This indicates the error ratio.

[0068] The present invention has the following advantages over the prior art:

[0069] (1) By establishing a virtual heat accumulation model to simulate the heat accumulation and heat dissipation process of the print head, and dynamically calculating the physical printing time based on the energy density value of the printed content and the temperature correction factor, the accurate prediction and control of the buffer overflow risk is realized.

[0070] (2) By adjusting the heat dissipation attenuation coefficient proportionally according to the deviation of the error ratio, the virtual thermal model can be gradually calibrated to match the thermal characteristics of the actual equipment, which significantly improves the universality and prediction accuracy of the virtual thermal model on different equipment.

[0071] (3) The noise level of the communication environment is quantified by calculating the standard deviation of the error ratio, and the dead zone radius and other graded thresholds are set by multiples of the standard deviation. The correction area is divided into four levels according to the error deviation, which realizes the balance between adaptability and stability and significantly improves the reliability and adaptability of the flow control algorithm in complex application scenarios. Attached Figure Description

[0072] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0073] Figure 1 This is a flowchart of an adaptive flow control method based on print content feature analysis according to the present invention;

[0074] Figure 2 This is a timing diagram of an adaptive flow control method based on print content feature analysis according to the present invention.

[0075] Figure 3 This is a schematic diagram illustrating the adjustment of the heat dissipation attenuation coefficient in an adaptive flow control method based on print content feature analysis according to the present invention.

[0076] Figure 4 This is a flowchart of the adaptive threshold grading process for an adaptive flow control method based on print content feature analysis according to the present invention. Detailed Implementation

[0077] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0078] like Figure 1 and Figure 2 As shown, this invention provides an adaptive flow control method based on print content feature analysis, comprising:

[0079] S1. The data stream to be printed is segmented to obtain multiple data segments. Energy density features are extracted in different ways according to the data segment type to obtain the energy density value of each data segment. The data segment types include bitmap data segments and instruction data segments.

[0080] Specifically, step S1 includes:

[0081] When the data segment is a bitmap data segment, the image is divided into multiple slices in the vertical direction. All pixels within each slice are traversed, and the number of black pixels is counted. The energy density value of the slice is obtained based on the ratio of the number of black pixels to the total number of pixels in the slice. The energy density value of the bitmap data segment:

[0082] ;

[0083] in, This represents the energy density value of the nth slice. This represents the number of black pixels in the nth slice. This indicates the width of the slice, i.e., the width of the image. Indicates the height of the slice;

[0084] When the data segment is an instruction data segment, the print control instruction sequence in the data stream is parsed, and the character width magnification factor, character height magnification factor, and bold mode coefficient are extracted. The time factor is obtained based on the product relationship of the three factors. If no width magnification instruction is detected, the width magnification factor is set to 1.

[0085] The energy density value of the instruction data segment is obtained by normalizing the time factor:

[0086] ;

[0087] in, This represents the energy density value of the i-th data segment. Indicates the first Time scaling factor for each instruction data segment This represents the maximum possible value of the time multiplier factor.

[0088] Understandably, after the host computer generates the data to be printed, the flow control system parses and extracts features from the data, calculates the virtual heat and estimates the physical printing time, while simultaneously calculating the transmission time to determine whether a delay needs to be inserted. When the physical printing time exceeds the transmission time, the flow control system inserts a waiting period before sending the data segment to avoid printer buffer overflow; when the physical printing time does not exceed the transmission time, the flow control system directly sends the data segment. After receiving the data segment, the printer executes the printing operation and returns a completion signal upon completion. The flow control system acquires the completion signal and records the actual time, calculates the error ratio, and updates the baseline coefficient, heat dissipation attenuation coefficient, and adaptive grading threshold based on error feedback to form a closed-loop control.

[0089] Commonly used printer instruction sets include standard or proprietary protocols such as ESC / POS, TSPL, and CPCL. These instruction sets define functions such as character printing, graphic printing, paper control, and print mode settings. In normal printing mode, the execution time of these instructions is usually much shorter than that of bitmap printing and can therefore be ignored. However, when high-time-consuming special print mode instructions are detected, the flow control system needs to extract relevant parameters for quantitative evaluation. These special modes include character width / height magnification mode, inverted mode, and bold mode. Among these, the character width magnification factor... The character height magnification factor is obtained from the width setting parameter in the instruction. The bold mode coefficient is obtained from the height setting parameter in the instruction. Determined based on whether a bold instruction is detected.

[0090] Energy density value The value ranges from 0 to 1, where 0 indicates that a completely white slice does not require heating the print head and can be quickly skipped, and 1 indicates that a completely black slice requires the maximum energy to heat and takes the longest to print.

[0091] In one embodiment of the present invention, the character width magnification factor... The value ranges from 1 to 8 times; character height magnification factor. The value ranges from 1 to 8 times; the bolding mode coefficient is used when a bolding command is detected. The value is 1.5 otherwise 1.0. This coefficient reflects the extra time required for the printhead to be repeatedly heated in bold mode.

[0092] S2. The virtual heat value is calculated iteratively. The temperature correction factor is determined based on the relationship between the virtual heat value and the safety threshold. The physical printing time is calculated by combining the number of bytes in the data segment, the energy density value, the baseline coefficient, and the temperature correction factor. The virtual heat value is obtained by adding the energy density value of the current data segment after heat dissipation attenuation processing of the historical virtual heat value.

[0093] Specifically, the calculation steps for virtual popularity value include:

[0094] Initialize virtual heat variables when the printing device starts up =0; where the virtual heat variable is 0. Used to simulate the heat accumulation state of the printhead;

[0095] When processing the first When processing a data segment, the historical virtual heat value is processed to reduce heat loss, resulting in residual heat. This residual heat is then added to the normalized energy density value of the current data segment to obtain the updated virtual heat value.

[0096] ;

[0097] in, Indicates the first The virtual heat value of each data segment. To complete the first The virtual popularity value after each data segment This is the heat dissipation attenuation coefficient. For the first The normalized energy density values ​​of each data segment.

[0098] Understandably, as the core component of a thermal printer, the printhead's temperature characteristics directly affect printing speed and quality. The printhead heats up when printing black pixels and cools down through natural or active cooling systems when idle or printing white pixels. The virtual thermal value is a software simulation of this physical process. Virtual thermal variable A value of 0 indicates that the printhead is at room temperature with no heat accumulation.

[0099] This represents the amount of residual heat from the previous moment after natural dissipation over one printing cycle; the heat dissipation attenuation coefficient. The closer to 1, the slower the heat dissipation and the more heat remains; the closer to 0, the faster the heat dissipation and the faster the heat decays. This indicates the newly added heat in the current data segment. The higher the energy density, the more heat is added. The coefficient of 100 is a scaling factor used to map the normalized density value to a safety threshold. The corresponding range of popularity values.

[0100] Furthermore, the formula for calculating the temperature correction factor is:

[0101] ;

[0102] in, Indicates the first Temperature correction factor for each data segment For temperature sensitivity coefficient, This is the safe heat threshold.

[0103] Understandably, during actual printing, when the printhead temperature gets too high, the printer will automatically reduce the printing speed or insert a forced cooling interval to protect the printhead from burning out or to ensure print quality. This includes a temperature correction factor. This is precisely the quantitative modeling of this physical phenomenon.

[0104] In the formula The function ensures that when the virtual heat value does not exceed the safety threshold, hour The function returns 0, which makes the correction factor... A value of 1 indicates that no speed reduction correction is needed. When the virtual heat value exceeds the safety threshold, the correction factor increases linearly with the degree to which the virtual heat exceeds the threshold.

[0105] In one embodiment of the present invention, when the data segment is a bitmap data segment, the calculation steps for the physical printing time are as follows:

[0106] Get the The total number of pixels, normalized energy density, temperature correction factor, and bitmap baseline coefficients of each slice corresponding to a bitmap data segment;

[0107] The physical printing time of a bitmap data segment is calculated based on the product of the total number of pixels in the slice, normalized energy density, temperature correction factor, and bitmap baseline coefficient:

[0108] ;

[0109] in, Indicates the first Physical printing time for each bitmap data segment Indicates the bitmap baseline coefficient. This indicates the total number of pixels contained in the slice. Indicates the height of the slice. Indicates the width of the slice. To normalize the energy density, For the first Temperature correction factor for each bitmap data segment.

[0110] Understandable, bitmap baseline coefficient Reflecting the inherent printing speed characteristics of a printer, different models and configurations of printers have different baseline coefficients, which represent the average time required to print each pixel when the printhead is at room temperature and the slice energy density is 1 (i.e., a completely black image). During adaptive flow control, the bitmap baseline coefficient is dynamically adjusted based on actual time feedback to adapt to changes in the actual performance and working environment of different printers.

[0111] In one embodiment of the present invention, when the data segment is an instruction data segment, the calculation steps for the physical printing time are as follows:

[0112] Get the The time scaling factor, temperature correction factor, and instruction base coefficient of each instruction data segment;

[0113] The physical printing time of the instruction data segment is calculated based on the product of the time factor, temperature correction factor, and instruction base coefficient.

[0114] ;

[0115] in, Indicates the first The physical printing time of each instruction data segment Indicates the command base coefficient. For the first Time scaling factor for each instruction data segment For the first Temperature correction factor for each instruction data segment.

[0116] Understandable, instruction base coefficient This represents the average time required for the printer to execute a command when the printhead is at room temperature and the command is executed in standard mode (width magnification of 1, height magnification of 1, and non-bold mode). During adaptive flow control, the command baseline coefficient is dynamically adjusted based on actual time feedback. Among these, the bitmap baseline coefficient... and instruction baseline coefficient These are two independent parameters, one for estimating the time consumption of the bitmap data segment and the other for the instruction data segment. During the adaptive adjustment process, once the actual time consumption of a certain data segment is obtained, the corresponding baseline coefficient is selected and updated according to the type of the data segment. Error feedback from the bitmap data segment only affects the bitmap baseline coefficient, and error feedback from the instruction data segment only affects the instruction baseline coefficient.

[0117] The command data uses normalized values ​​when calculating virtual heat. Using the same units as bitmap data facilitates the calculation of heat accumulation in the virtual thermal model, but a time factor is used when estimating physical duration. This design ensures accurate reflection of the actual execution time of instructions. It balances the versatility of the virtual thermal model (both bitmap data and instruction data participate in heat accumulation with normalized density values ​​in the range of 0 to 1) with the accuracy of physical time estimation (different calculation methods are used based on their respective physical characteristics).

[0118] This invention employs different energy density extraction methods for bitmap data and instruction data, enabling the flow control strategy to distinguish the printing time differences between all-white images, all-black images, and medium-density images. Compared to methods that rely solely on nominal speed, this significantly improves the accuracy of physical time estimation and can accurately predict the heat accumulation rate of the printhead under different content densities, thereby achieving refined delay control.

[0119] S3. Calculate the transmission time based on the number of bytes in the data segment and the effective transmission rate of the communication interface. Determine the estimated time based on the physical printing time and the transmission time. If the physical printing time exceeds the transmission time, insert a waiting time before sending the data segment. The waiting time is the difference between the physical printing time and the transmission time.

[0120] Specifically, step S3 includes:

[0121] Transmission time is calculated based on the ratio of the number of bytes in the data segment to the effective transmission rate of the communication interface.

[0122] ;

[0123] in, Indicates the first Transmission time of each data segment For the first Number of bytes in each data segment The effective transmission rate of the communication interface is measured in bytes per millisecond.

[0124] Compare the time spent on physical printing with the time spent on transmission:

[0125] When the physical printing time exceeds the transmission time, it is determined that there is a risk of buffer overflow, and the waiting time is calculated based on the difference between the two.

[0126] If the physical printing time does not exceed the transmission time, it is determined that there is no risk of buffer overflow, and the data segment is sent directly without inserting a waiting time.

[0127] The estimated time is determined based on the transmission time and the physical printing time:

[0128] ;

[0129] in, This represents the estimated time taken for the i-th data segment. Indicates the first Transmission time of each data segment Indicates the first The physical printing time for each data segment.

[0130] Understandable, for bitmap data segments, It equals the total number of pixels in the slice divided by 8. This is because thermal printers typically transmit image data in bitmap format, with each pixel occupying 1 bit, meaning 8 pixels occupy 1 byte. For the instruction data segment, Equal to the byte length of the instruction sequence, and the effective transmission rate of the communication interface. The effective transmission rate is defined based on the interface type and measured throughput. It refers to the actual data throughput capacity after deducting protocol overhead, handshake time, acknowledgment delay, and other factors. While USB interfaces have nominal speeds of up to 12Mbps or 480Mbps, their actual effective throughput is typically 60% to 80% of the nominal speed, with a typical value of 10 bytes per millisecond. Bluetooth interfaces, especially Bluetooth 2.0 or 2.1 versions, have lower effective throughput due to signal interference, retransmission mechanisms, and time-division multiplexing, with a typical value of 2 bytes per millisecond. Transmission time reflects the time required for data to be transmitted from the host computer through the communication interface to the printer's receive buffer.

[0131] Buffer overflow risk indicates that the printer's physical data processing speed is slower than the speed at which data arrives through the communication channel. Without flow control, data will quickly fill the printer's receive buffer, leading to buffer overflow, manifesting as data loss, scrambled print content, and printer unresponsiveness. By waiting before sending, the rate at which data arrives in the printer buffer matches the rate at which the printer consumes data from the buffer, thus preventing buffer backlog. The absence of buffer overflow risk means the printer's processing speed is fast enough to consume the data in the buffer during data transmission, preventing buffer backlog. In this case, data segments should be sent immediately to maximize printing efficiency and avoid efficiency losses caused by overly conservative flow control strategies. When transmission time is significant, the estimated time being determined by the transmission time indicates that the communication channel is the bottleneck; when physical printing time is significant, the estimated time being determined by the physical printing time indicates that the printer's processing capacity is the bottleneck.

[0132] S4. Obtain the actual time taken from the completion of data segment transmission to the completion of printing. Based on the ratio of the estimated time to the actual time, obtain the error ratio. Update the error ratio queue using a sliding window and calculate its standard deviation. Determine the adaptive grading threshold based on the standard deviation. Update the baseline coefficient according to the level to which the error ratio belongs. When the virtual heat value exceeds the safety threshold and the error ratio meets the preset conditions, adjust the heat dissipation attenuation coefficient based on the error ratio.

[0133] Specifically, the error ratio queue is updated using a sliding window, which includes:

[0134] Initialize the error ratio history queue, wherein the error ratio history queue is used to store the most recent Error ratio values ​​for each data segment;

[0135] When the After each data segment is printed, the actual time taken from the completion of sending to the completion of printing for that data segment is obtained, and the error ratio is calculated based on the ratio of the estimated time to the actual time. :

[0136] ;

[0137] in For the first The estimated total time for each data segment is equal to the larger of the transmission time and the physical printing time. For the first The actual total time taken for each data segment is obtained by recording the time difference between the data transmission completion time and the printer return completion signal.

[0138] Determine the current length of the historical queue for the error ratio:

[0139] If the queue length has been reached Then, remove the oldest error ratio value from the queue while keeping the queue length constant. Then, the newly calculated error ratio is inserted at the end of the queue for sliding window updates;

[0140] If the queue length has not been reached If the error ratio is not found, the error ratio is directly inserted at the end of the queue for sliding window updates.

[0141] Understandable, error ratio This indicates that the estimate was higher than the actual result, suggesting that the estimate was too conservative and that excessive delays were inserted. This indicates that the estimated value is less than the actual value, which may indicate a buffer overflow risk and necessitates increasing the delay.

[0142] In one embodiment of the present invention, when the first After each data segment is printed, the flow control system obtains the actual time elapsed using one of the following methods:

[0143] (1) After sending a data segment, the flow control system waits for a completion signal from the printer. After completing the printing operation of the data segment, the printer sends a completion response message to the flow control system through the communication interface. The flow control system records the time difference between sending the message and receiving the response message as the actual time elapsed. This method is applicable to printers that support a completion response mechanism.

[0144] (2) After sending a data segment, the flow control system polls the printer's working status by sending a printer status query command. When the query result shows that the printer has completed printing the current data segment and the buffer is empty, the flow control system records the time difference between the sending time and the successful query time as the actual time consumed. This method is suitable for printers that do not support a completion response mechanism but do support status queries.

[0145] Furthermore, determining the adaptive grading threshold based on the standard deviation specifically includes:

[0146] Calculate the mean and standard deviation of the error ratio based on the historical error ratio cohort:

[0147] ;

[0148] ;

[0149] in, Let j represent the mean of the error ratios, j represent the index of the error ratio, and N represent the length of the historical queue of error ratios. This represents the j-th error ratio. Standard deviation representing the error ratio;

[0150] An adaptive dead zone radius is set based on the product of standard deviation and noise tolerance coefficient, while constraining the dead zone radius to be no less than a preset lower limit:

[0151] ;

[0152] in, Indicates the dead zone radius, This is the lower limit of the dead zone radius. This is the noise tolerance factor. Indicates standard deviation;

[0153] A multi-level correction region is formed based on the dead zone radius, including the dead zone, fine-tuning region, fast-tuning region, and anomaly region. The upper bound of the fine-tuning region is twice the dead zone radius. The upper limit of the fast adjustment zone is three times the radius of the dead zone, that is... .

[0154] In one embodiment of the present invention, the noise tolerance factor The value of is 2. This value is based on the statistical principle that two standard deviations under a normal distribution can cover about 95% of normal fluctuations. Therefore, setting the dead zone radius to two standard deviations can effectively distinguish between random noise and systematic bias.

[0155] This invention quantifies the noise level of the communication environment by calculating the standard deviation of the error ratio, and sets the dead zone radius and other graded thresholds by multiples of the standard deviation. Based on the error deviation, the correction area is divided into four levels: dead zone, fine-tuning zone, fast-tuning zone and abnormal zone. Different levels correspond to different learning rates, achieving a balance between adaptability and stability, and significantly improving the reliability and adaptability of the flow control algorithm in complex application scenarios.

[0156] like Figure 3 and Figure 4 As shown, in one embodiment of the present invention, adjusting the heat dissipation attenuation coefficient based on the error ratio specifically includes:

[0157] Calculate the error deviation ;

[0158] The error level is determined based on the relationship between the error deviation and the adaptive grading threshold.

[0159] when If the area is identified as a dead zone, no baseline coefficient correction will be performed.

[0160] when When the time is determined to be in the fine-tuning zone, the learning rate is 0.1, and the baseline coefficient is adjusted.

[0161] when When the time is determined to be in the fast adjustment region, the learning rate is 0.5, and the baseline coefficient is adjusted.

[0162] when or If the area is identified as an abnormal region, no correction will be made.

[0163] The formula for calculating the benchmark coefficient correction is as follows:

[0164] ;

[0165] ;

[0166] in, This represents the updated bitmap baseline coefficient for the bitmap data segment. This represents the bitmap baseline coefficient before the bitmap data segment is updated. This indicates the update instruction base coefficient for the instruction data segment. This represents the instruction baseline coefficient before the instruction data segment is updated. Indicates the learning rate;

[0167] Determine whether the virtual popularity value exceeds the safety threshold and whether the error deviation meets the requirements. :

[0168] If so, proceed with the heat dissipation attenuation coefficient update process:

[0169] ;

[0170] in, This indicates the heat dissipation attenuation coefficient after the update. The heat dissipation attenuation coefficient before the update. The learning rate is the heat dissipation attenuation coefficient. This indicates the error ratio.

[0171] Understandable, correction factor Determine the direction and magnitude of the correction, when the error ratio Correction factor when the estimate is too high This reduces the baseline coefficient, thereby lowering subsequent physical time estimations, when the error ratio... That is, the correction factor when the estimated deviation is small. This increases the baseline coefficient, thereby improving the subsequent physical time estimation.

[0172] This invention adjusts the heat dissipation attenuation coefficient proportionally according to the deviation of the error ratio, so that the virtual thermal model can be gradually calibrated to match the thermal characteristics of the actual device. It can converge the heat dissipation attenuation coefficient to the optimal value within dozens of printing cycles, which significantly improves the universality and prediction accuracy of virtual thermal model on different devices.

[0173] In one embodiment of the present invention, the learning rate Take 0.1 in the fine-tuning zone and 0.5 in the fast-tuning zone.

[0174] This invention simulates the heat accumulation and dissipation process of the printhead by establishing a virtual heat accumulation model, and dynamically calculates the physical printing time based on the energy density value of the printed content and the temperature correction factor. This enables accurate prediction and control of the risk of buffer overflow, improving printing efficiency while ensuring the reliability of data transmission, and avoiding the problems of overly conservative fixed delay strategies and insufficient accuracy of simple rate limits.

[0175] To illustrate with a specific embodiment, a printer is connected via a USB interface. The error ratios of the most recent 10 data segments in the error ratio history queue are 1.01, 0.99, 1.02, 1.00, 0.98, 1.01, 1.03, 0.99, 1.00, and 1.02, respectively. The calculated mean is 1.005 and the standard deviation is 0.015.

[0176] The dead zone radius is 3%, the upper limit of the fine-tuning zone is 6%, and the upper limit of the fast-tuning zone is 9%.

[0177] If the error ratio of the next data segment is 1.04, which is 4% off, then the error falls within the fine-tuning area and is corrected with a learning rate of 0.1.

[0178] Assuming the data segment is a bitmap data segment and the current bitmap baseline coefficient is 0.0025 milliseconds per pixel, the new baseline coefficient will be milliseconds per pixel, slightly lowered to correct the problem of overestimation;

[0179] If the error ratio is 1.08, which is 8% off, it falls into the fast adjustment zone and is corrected with a learning rate of 0.5. The new baseline coefficient is milliseconds per pixel, and the decrease is larger for faster correction.

[0180] If the error ratio is 0.50, meaning it deviates by 50% and exceeds the absolute threshold, it is considered abnormal and no correction is made; the baseline coefficient remains unchanged.

[0181] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. An adaptive flow control method based on print content feature analysis, characterized in that, include: S1. The data stream to be printed is segmented to obtain multiple data segments. Energy density features are extracted in different ways according to the data segment type to obtain the energy density value of each data segment. The data segment types include bitmap data segments and instruction data segments. Step S1 specifically includes: When the data segment is a bitmap data segment, the image is divided into multiple slices in the vertical direction. All pixels in the slice are traversed and the number of black pixels is counted. The energy density value of the slice is obtained based on the ratio of the number of black pixels to the total number of pixels in the slice. When the data segment is an instruction data segment, the print control instruction sequence in the data stream is parsed, and the character width magnification factor, character height magnification factor, and bold mode coefficient are extracted. The time factor is obtained based on the product relationship of the three factors. The time factor is normalized to obtain the energy density value of the instruction data segment; S2. The virtual heat value is calculated using an iterative method, and the temperature correction factor is determined based on the relationship between the virtual heat value and the safety threshold. The virtual heat value is obtained by superimposing the energy density value of the current data segment after the historical virtual heat value has been processed for heat dissipation attenuation. The virtual heat value represents the heat accumulation state of the print head, and the historical virtual heat value represents the heat accumulation state of the print head after printing the previous data segment. S3. Calculate the transmission time based on the number of bytes in the data segment and the effective transmission rate of the communication interface. Determine the estimated time based on the physical printing time and the transmission time. If the physical printing time exceeds the transmission time, insert a waiting time before sending the data segment. The waiting time is the difference between the physical printing time and the transmission time. The estimated time is the maximum value between the physical printing time and the transmission time. When the data segment is a bitmap data segment, the calculation steps for the physical printing time are as follows: Get the The total number of pixels, normalized energy density, temperature correction factor, and bitmap baseline coefficients of each slice corresponding to a bitmap data segment; The physical printing time of a bitmap data segment is calculated based on the product of the total number of pixels in the slice, the normalized energy density, the temperature correction factor, and the bitmap baseline coefficient. When the data segment is an instruction data segment, the calculation steps for the physical printing time are as follows: Get the The time multiplier factor, temperature correction factor, and instruction base coefficient of each instruction data segment; The physical printing time of the instruction data segment is calculated based on the product relationship of the time multiplication factor, temperature correction factor, and instruction base coefficient. S4. Obtain the actual time taken from the completion of data segment transmission to the completion of printing. Based on the ratio of the estimated time to the actual time, obtain the error ratio. Update the error ratio queue using a sliding window and calculate its standard deviation. Determine the adaptive grading threshold based on the standard deviation. Update the baseline coefficient according to the level to which the error ratio belongs. When the virtual heat value exceeds the safety threshold and the error ratio meets the preset conditions, adjust the heat dissipation attenuation coefficient based on the error ratio.

2. The adaptive flow control method based on print content feature analysis as described in claim 1, characterized in that: The specific steps for calculating the virtual heat value include: Initialize virtual heat variables when the printing device starts up =0; where the virtual heat variable is 0. Used to simulate the heat accumulation state of the printhead; When processing the first When processing a data segment, the historical virtual heat value is processed to reduce heat loss, resulting in residual heat. This residual heat is then added to the normalized energy density value of the current data segment to obtain the updated virtual heat value. ; in, Indicates the first The virtual heat value of each data segment. To complete the first The virtual popularity value after each data segment This is the heat dissipation attenuation coefficient. For the first The normalized energy density values ​​of each data segment.

3. The adaptive flow control method based on print content feature analysis as described in claim 2, characterized in that: The formula for calculating the temperature correction factor is as follows: ; in, Indicates the first Temperature correction factor for each data segment For temperature sensitivity coefficient, The safe heat threshold.

4. The adaptive flow control method based on print content feature analysis as described in claim 1, characterized in that: When the data segment is a bitmap data segment, the formula for calculating the physical printing time is: ; in, Indicates the first Physical printing time for each bitmap data segment Indicates the bitmap baseline coefficient. Indicates the total number of pixels. Indicates the height of the slice. Indicates the width of the slice. To normalize the energy density, For the first Temperature correction factor for each bitmap data segment.

5. The adaptive flow control method based on print content feature analysis as described in claim 1, characterized in that: When the data segment is an instruction data segment, the formula for calculating the physical printing time is: ; in, Indicates the first The physical printing time of each instruction data segment As the command baseline coefficient, For the first Time scaling factor for each instruction data segment For the first Temperature correction factor for each instruction data segment.

6. The adaptive flow control method based on print content feature analysis as described in claim 1, characterized in that: Step S3 specifically includes: Transmission time is calculated based on the ratio of the number of bytes in the data segment to the effective transmission rate of the communication interface. Compare the time spent on physical printing with the time spent on transmission: When the physical printing time exceeds the transmission time, it is determined that there is a risk of buffer overflow, and the waiting time is calculated based on the difference between the two. If the physical printing time does not exceed the transmission time, it is determined that there is no risk of buffer overflow, and the data segment is sent directly without inserting a waiting time. The estimated time is determined based on the transmission time and the physical printing time: ; in, This represents the estimated time taken for the i-th data segment. Indicates the transmission time. This indicates the time taken for physical printing.

7. The adaptive flow control method based on print content feature analysis as described in claim 1, characterized in that: The method of updating the error ratio queue using a sliding window specifically includes: Initialize the error ratio history queue, wherein the error ratio history queue is used to store the most recent Error ratio values ​​for each data segment; When the After each data segment is printed, the actual time taken from the completion of sending to the completion of printing for that data segment is obtained, and the error ratio is calculated based on the ratio of the estimated time to the actual time. ; Determine the current length of the historical queue for the error ratio: If the queue length has been reached Then, remove the oldest error ratio value from the queue while keeping the queue length constant. Then, the newly calculated error ratio is inserted at the end of the queue for sliding window updates; If the queue length has not been reached If the error ratio is not found, the error ratio is directly inserted at the end of the queue for sliding window updates.

8. The adaptive flow control method based on print content feature analysis as described in claim 7, characterized in that: The step of determining the adaptive grading threshold based on the standard deviation specifically includes: The mean and standard deviation of the error ratio are calculated based on the historical error ratio queue. An adaptive dead zone radius is set based on the product of standard deviation and noise tolerance coefficient, while constraining the dead zone radius to be no less than a preset lower limit: ; in, Indicates the dead zone radius, This is the lower limit of the dead zone radius. This is the noise tolerance factor. Indicates standard deviation; A multi-level correction region is formed based on the dead zone radius, including the dead zone, fine-tuning region, fast-tuning region and anomaly region. The upper limit of the fine-tuning region is twice the dead zone radius, and the upper limit of the fast-tuning region is three times the dead zone radius.

9. The adaptive flow control method based on print content feature analysis as described in claim 8, characterized in that: The adjustment of the heat dissipation attenuation coefficient based on the error ratio specifically includes: Calculate the error deviation ; The error level is determined based on the relationship between the error deviation and the adaptive grading threshold. when If the area is identified as a dead zone, no baseline coefficient correction will be performed. when When the time is determined to be in the fine-tuning zone, the learning rate is 0.1, and the baseline coefficient is adjusted. Indicates the upper bound of the fine-tuning area; when When the time is determined to be in the fast adjustment region, the learning rate is 0.5, and the baseline coefficient is adjusted. Indicates the upper bound of the fast-tone region; when or If the area is identified as abnormal, no correction will be made. The formula for calculating the benchmark coefficient correction is as follows: ; ; in, This represents the updated bitmap baseline coefficient for the bitmap data segment. This represents the bitmap baseline coefficient before the bitmap data segment is updated. This indicates the update instruction base coefficient for the instruction data segment. This represents the instruction baseline coefficient before the instruction data segment is updated. Indicates the learning rate; Determine whether the virtual popularity value exceeds the safety threshold and whether the error deviation meets the requirements. : If so, proceed with the heat dissipation attenuation coefficient update process: ; in, This indicates the heat dissipation attenuation coefficient after the update. The heat dissipation attenuation coefficient before the update. The learning rate is the heat dissipation attenuation coefficient. This indicates the error ratio.