Design of real-time line-print system in Windows

Source: Internet
Author: User

As we all know, the Windows System's page print system has many good features, such as WYSIWYG, device-independent, and so on. However, in some real time demanding industrial control systems, it is necessary to print the random information of the system in real time, which requires a row to play, but not a line to play a page, and the Windows system of the page printing system is difficult to meet the needs of such applications. For this reason, it is necessary to design a new real-time line-print system to meet the requirements of real-time system printing. The following is a detailed description of how to implement such a system on Windows 2000/NT.

Overall design

The basic requirement of real time system is real-time. In this paper, the use of shared memory as a relay of the print spooling technology, all the printing operations in memory submitted to ensure that the application system to print operations in time response.

Another requirement is device independence, which allows the submission of printing to be as relevant to the device as possible. The program will not cause a large change in the program because of different printer devices. If the printer is different, simply load the appropriate print driver.

In general, the design of real-time line-print system is divided into two parts, one is the design of the print spool part based on memory, and the other is the design of the real time printing driver layer. The system's schematic design is as follows:

Live Line Print spool part

The rationale for this section is to use a first in first out queue based on shared memory technology to store real-time print requests submitted by other applications. Print process from into the first out of the ring queue to remove the print request, after the necessary processing, submitted to the Print Driver section, the print driver is responsible for driving the corresponding printer output.

To meet the needs of other applications to submit print requests, this uses the shared memory technology provided by the Windows operating system. Shared memory is a technology used to communicate between processes, is a more standard, more core technology, and it has a better portability between different operating system platforms (Unix series operating systems also have this technology). Another benefit is improved real-time performance, since it avoids the overhead of system space and time for multiple memory replications.

The system functions associated with creating shared memory in Windows systems are createfilemapping and mapviewoffile.

The first function is used to create a shared memory in the system and return a handle to the shared memory. The parameters are described below:

HANDLE WINAPI CreateFileMapping (
HANDLE hFile,
LPSECURITY _ATTRIBUTES lpsa,
DWORD dwPROTECT,
DWORD dwMaxSizeHigh,
DWORD dwMaxSizeLow,
LPCSTR lpszMapName);

hfile is a file handle, to create shared memory, the parameter must be 0xffffffff; LPSA is a security attribute structure pointer; Dwprotect is a page protection identification, such as Page_readonly,page_readwrite; Dwmaxsizehigh and Dwmaxsizelow together define the size of shared memory, which is 32-bit and 32-bit high in shared memory size respectively; Lpszmapname defines the name of the shared memory and must ensure its uniqueness within the system scope.

The second function is used to map the created shared memory to the address space of the calling process and return the first address of that address space. The parameters are described below:

MapViewOfFile(
HANDLE hFileMappingObject,
DWORD dwDesiredAccess,
DWORD dwFileOffsetHigh,
DWORD dwFileOffsetLow,
DWORD dwNumberOfBytesToMap);
hFileMappingObject定义了CreateFileMapping

The shared memory handle returned by the function; dwDesiredAccess defines the access mode for shared memory, such as: file_map_all_access

Wait Dwfileoffsethigh and Dwfileoffsetlow together define the offset of the starting position of the shared memory, which is higher 32 bits and 32 bits of the offset, and usually has zero value. Dwnumberofbytestomap defines the number of bytes of shared memory mapped to this process address space, and if this value is zero, all shared memory is mapped.

Here, the name of the shared memory used for the live print system is defined as g_szrealtimeprintsystemsharememname. REALTIMEPRINT_DB is a structure type that defines the internal structure of shared memory, which is the data core of a real-time printing system, including information to be printed, writing pointers, reading pointers, and so on. The specific steps are as follows (schematic code):

REALTIMEPRINT_DB *g_pRealTimePrint-
SystemDb ;
HANDLE hShareMemHandle = NULL;
DWORD dwRTPSShmLen = sizeof(REALTIMEPRINT_DB);
//REALTIMEPRINT_DB 结构的长度
hShareMemHandle =
//生成共享内存,并返回其句柄
CreateFileMapping((HANDLE)0xffffffff,NULL,PAGE_READWRITE,0,
dwRTPSShmLen, //共享内存的大小 “g_szRealTimePrintSystemShareMemName”);
g_pRealTimePrintSystemDb =
//将共享内存映射到本进程的地址空间
(REALTIMEPRINT_DB *)MapViewOfFile(hShareMemHandle,FILE_MAP_ALL_ACCESS,0,0,0);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.