Search

CN-122018831-A - C# based Linux shared printing control method, system, medium and product

CN122018831ACN 122018831 ACN122018831 ACN 122018831ACN-122018831-A

Abstract

A Linux shared printing control method, system, medium and product based on C# relates to the technical field of printing control. The method comprises the steps of creating and running a WebSocket server through a printing daemon, analyzing a JSON format printing instruction in a printing message through the printing daemon to obtain canvas parameters and content drawing instructions, creating a virtual canvas in a memory based on the canvas parameters, generating image data to be printed according to the content drawing instructions, adding printing tasks containing the image data to be printed into a concurrent queue, sequentially processing the printing tasks in the concurrent queue through the printing daemon, packaging the printing tasks into a bottom instruction in a preset format through a USB interface with acquired authority for each printing task, and directly sending the bottom instruction to a printer for printing after the user-state USB communication library is utilized. By implementing the technical scheme, the effect of efficient, flexible and stable Linux shared printing control is achieved.

Inventors

  • LI JIANGUO
  • LIU ZIQI

Assignees

  • 北京硕方信息技术有限公司

Dates

Publication Date
20260512
Application Date
20260414

Claims (10)

  1. 1. The Linux shared printing control method based on the C# is characterized by comprising the following steps of: registering a printing daemon as an operating system level service, and creating and running a WebSocket server through the printing daemon for establishing communication connection with a remote client; When a print message from the remote client is received through the WebSocket server, analyzing a JSON format print instruction in the print message through the print daemon to obtain canvas parameters and content drawing instructions; Creating a virtual canvas in a memory based on the canvas parameters, calling a cross-platform graphic rendering library according to the content drawing instruction, drawing texts, bar codes or images on the virtual canvas to generate image data to be printed, and adding a print task containing the image data to be printed into a concurrent queue; And sequentially processing the printing tasks in the concurrent queue through the printing daemon, detecting the access authority of the current system to the target USB printer through a user-state USB communication library for each printing task, dynamically applying for temporary authority through the authorized service of the operating system if the authority is insufficient, persistence the authority rule into the system equipment management rule, and directly sending the printing task to the printer for printing after the user-state USB communication library is used for packaging the printing task into a bottom instruction in a preset format through the USB interface with the acquired authority.
  2. 2. The method of claim 1, wherein persisting the entitlement rules into the system device management rules comprises: Acquiring an equipment descriptor of the target USB printer through the user mode USB communication library, wherein the equipment descriptor comprises a supplier identifier, a product identifier and a serial number; Generating a device authority rule containing multiple matching conditions according to the acquired device information, wherein the device authority rule identifies a single device through a serial number and designates the read-write authority of a non-privileged user group for the identified device; invoking a system command by using an administrator authority, writing the device authority rule into a configuration file under a device management rule catalog of a system, and checking whether conflict rules exist before writing; and calling a device management command provided by an operating system to reload all the device authority rules and trigger a device event to enable the new rules to be effective immediately, and simultaneously, enumerating whether the device verification authority is successfully applied or not through re-enumeration, and persisting successfully authorized printer information into a local configuration file so as to apply the saved authority configuration when a subsequent system is started or the device is plugged in and plugged out again.
  3. 3. The method according to claim 1, wherein the method further comprises: Inserting the printing task into the corresponding position of the concurrent queue according to the priority field in the JSON format printing instruction so as to realize the queue inserting processing of the high-priority task; After the printing task is successfully added into the concurrent queue, if the receipt request mark is true, a confirmation message containing a task ID and the current queue position estimated waiting time is returned to the client through the WebSocket server; In the execution process of the print task, if an event with a feedback progress occurs, pushing an intermediate state update comprising a task ID, an execution progress percentage and a residual estimated time to a client through the WebSocket server; After the printing task is executed or fails, a final state report containing the task ID, the execution result, the time consuming statistics and the detailed error code is generated, and is asynchronously pushed to the client through the WebSocket server.
  4. 4. The method according to claim 1, wherein the calling a cross-platform graphics rendering library according to the content drawing instruction draws text, bar codes or images on the virtual canvas to generate image data to be printed, specifically comprising: Initializing a memory canvas of the cross-platform graphic rendering library according to the canvas parameters, and setting rendering resolution based on DPI parameters of the target USB printer; Sequentially rendering texts, vector bar codes and decoded images on the memory canvas according to the sequence of the content drawing instructions to form gray images; applying a preset edge enhancement algorithm to the gray level image, identifying boundary areas of texts and graphics and sharpening to compensate ink point diffusion in the thermal printing process; Applying a preset self-adaptive dithering algorithm to the gray level image after edge enhancement according to the physical characteristics of the thermal print head of the target USB printer, and dynamically adjusting dithering matrix parameters to generate a monochromatic bitmap aiming at the target USB printer; And cutting the single-color bitmap according to the minimum printing line unit of the target USB printer, and packaging the single-color bitmap into a raster bitmap printing instruction stream conforming to a native protocol.
  5. 5. The method according to claim 4, wherein the dynamically adjusting the dither matrix parameters to generate the monochrome bitmap for the target USB printer according to the thermal print head physical characteristics of the target USB printer, specifically comprises: acquiring physical characteristic parameters of a thermal printing head of the target USB printer, wherein the physical characteristic parameters of the thermal printing head comprise printing head resolution, heating lattice density, single-point heating time curve and thermal diffusion coefficients of adjacent heating points; according to the thermal diffusion coefficient, a thermal diffusion model is constructed, and the heat influence range of each printing point on adjacent pixels in the printing process is predicted; Based on the thermal diffusion model, performing precompensation calculation on each pixel point in the monochromatic bitmap, and dynamically adjusting the heating intensity of the current pixel according to the printing state of the adjacent pixel so as to offset the blurring effect caused by thermal diffusion; According to the historical printing data of the target USB printer, calculating optimal jitter matrix parameters at different environment temperatures, and establishing a mapping relation between the environment temperatures and the jitter matrix parameters; and acquiring the current environment temperature in real time in the printing process, dynamically selecting a matched dither matrix according to the mapping relation, and carrying out halftone processing on the monochromatic bitmap to generate a final monochromatic bitmap.
  6. 6. The method of claim 1, wherein the sequentially processing, by the print daemon, print jobs in the concurrency queue comprises: After a print job is taken out from the concurrent queue, a pre-print diagnosis instruction is sent to the target USB printer through the user mode USB communication library, wherein the pre-print diagnosis instruction comprises comprehensive inquiry on the state of an internal buffer zone of the printer, the temperature of a printing head and the residual quantity of paper; Receiving and analyzing diagnosis response data of the target USB printer aiming at the pre-printing diagnosis instruction, and establishing a state vector of the target USB printer; Inputting the state vector into a preset expert rule engine, judging whether the current state is suitable for continuous printing or not according to a historical fault mode library by the expert rule engine, and predicting the possible fault type; if the printing is not suitable or the high-risk fault is predicted, executing a corresponding processing strategy according to the output of the rule engine, wherein the processing strategy comprises pausing the current queue or putting the task back to the head of the queue and marking that manual intervention is needed; if the printer is judged to be suitable for printing, the printing task is continuously executed, and the real-time state feedback of the printer is continuously monitored in the printing process.
  7. 7. The method according to claim 1, wherein the method further comprises: Enumerating all connected USB printers through the user state USB communication library, creating equipment objects for each USB printer and collecting performance parameters, wherein the performance parameters comprise maximum printing speed, resolution, current task number and historical failure rate; Dynamically calculating real-time load weights for each printer according to the collected performance parameters, and constructing a consistency hash ring based on the real-time load weights for routing decisions of tasks; Matching and screening a candidate printer set meeting printing conditions through a printing quality requirement field in the JSON format printing instruction and performance parameters of each USB printer; for each print task to be processed, selecting an optimal target USB printer through a consistent hash algorithm according to the hash value of the task identifier and the real-time load weight of the candidate printer, and routing the task to a concurrent queue exclusive to the target USB printer; And when processing each concurrent queue, continuously monitoring the real-time load and task completion condition of each USB printer, dynamically adjusting the real-time load weight and updating the consistency hash ring, and realizing the self-adaptive load balancing among multiple printers.
  8. 8. A computer system comprising a memory, a processor and a computer program stored on the memory, characterized in that the processor executes the computer program to carry out the steps of the method according to any one of claims 1-7.
  9. 9. A computer readable storage medium having stored thereon a computer program/instruction, which when executed by a processor, implements the steps of the method of any of claims 1-7.
  10. 10. A computer program product comprising computer programs/instructions which, when executed by a processor, implement the steps of the method of any of claims 1-7.

Description

C# based Linux shared printing control method, system, medium and product Technical Field The application relates to the field of printing control, in particular to a C# based Linux shared printing control method, a system, a medium and a product. Background In the era of frequent digital office and information interaction today, printing demands are increasing, and particularly in a multi-device, cross-platform environment, it is becoming important to achieve efficient and stable printing control. With the continuous development of computer technology and network technology, remote printing has become an important means for improving the working efficiency and convenience. In the prior art, solutions to remote printing requirements are mainly the following: The first is a browser plug-in based printing scheme. The scheme enables the Web page to call the printing interface of the local system by installing ActiveX, NPAPI or PPAPI plug-ins in the browser. However, with the increasing strictness of browser security policies, mainstream browsers have phased out support for legacy plug-ins. In addition, the plug-in mode depends on the browser process, when the browser is closed or the plug-in crashes, the printing task is interrupted and cannot be automatically recovered, and the requirement of industrial application on stability is difficult to meet. The second is the way the client application directly integrates the print functionality. This solution requires the user to install specific client software locally, which is responsible for communicating with the remote system and invoking the local print interface. The method has the defects that the printing interfaces of different operating system platforms are large in difference, the cost for maintaining the multi-platform client is high, the client is tightly coupled with a service system, the client is required to be synchronously updated when the service logic is changed, the deployment and maintenance complexity is increased, the client program is usually operated in a common application process mode, an abnormal self-recovery mechanism is lacked, and the printing service is interrupted after the process is accidentally exited. Therefore, there is an urgent need for a print control scheme capable of solving the above-described technical problems. Disclosure of Invention The application provides a C# based Linux sharing printing control method, a system, a medium and a product, which achieve the effect of high-efficiency, flexible and stable Linux sharing printing control. In a first aspect, the present application provides a c# based Linux sharing print control method, which includes: registering a printing daemon as an operating system level service, and creating and running a WebSocket server through the printing daemon for establishing communication connection with a remote client; When a print message from the remote client is received through the WebSocket server, analyzing a JSON format print instruction in the print message through the print daemon to obtain canvas parameters and content drawing instructions; Creating a virtual canvas in a memory based on the canvas parameters, calling a cross-platform graphic rendering library according to the content drawing instruction, drawing texts, bar codes or images on the virtual canvas to generate image data to be printed, and adding a print task containing the image data to be printed into a concurrent queue; And sequentially processing the printing tasks in the concurrent queue through the printing daemon, detecting the access authority of the current system to the target USB printer through a user-state USB communication library for each printing task, dynamically applying for temporary authority through the authorized service of the operating system if the authority is insufficient, persistence the authority rule into the system equipment management rule, and directly sending the printing task to the printer for printing after the user-state USB communication library is used for packaging the printing task into a bottom instruction in a preset format through the USB interface with the acquired authority. By adopting the technical scheme, the daemon core logic is realized in a cross-platform running environment by adopting the C# language, and service development is performed by utilizing high-level abstract grammar and rich class library resources, so that development complexity and maintenance cost are obviously reduced, and code readability and sustainable iteration capability are improved. Through a dynamic authority application and persistence mechanism, the authority barrier of USB equipment access under a domestic system is solved, and the universality and popularization value of the system are improved. And the daemon locally completes data analysis, image drawing and task scheduling, realizes decoupling of a remote system and a bottom printing device, and improves the expandability and real-