๕/๑๑/๕๐

How to make DOS programs printing faster in Windows

ทำอย่างไรให้โปรแกรม DOS ภายใต้ Windows พิมพ์ได้เร็วขึ้น


Introduction: This article explains how to speed up printing from DOS to a DOS compatible printer on Windows.If you need to print from DOS to a Windows printer which is not DOS compatible, like a Windows-Only (GDI) USB printer or a virtual printer (WinFax, PDF writers, etc.), please see: How to print from DOS to Windows-Only printers.

บทความนี้ อธิบายวิธีที่ทำให้การพิมพ์จากโปรแกรม DOS ใน Windows ไปยังเครื่องพิมพ์ที่สามารถรับคำสั่ง DOS ได้โดยตรง ถ้าคุณต้องการพิมพ์จาก DOS ไปยังเครื่องพิมพ์ที่รับคำสั๋ง Windows อย่างเดียว เช่น GDI USB printer (inkjet printer) หรือ เครื่องพิมพ์เสมือนบน Windows เช่น WixFax, PDF writers จะต้องไปดูเรื่องของ วิธีการสั่งพิมพ์จาก DOS ไปยังเครื่องพิมพ์ของ Windows

The Problem: If you run a DOS application on NT-based Windows systems (Windows 2000, XP, 2003, Vista), you may find that your print jobs are spooled after many seconds, sometimes minutes, especially when printing to a network printer. It may even happen on Windows 95/98/ME machines.

ถ้าคุณใช้โปรแกรม DOS ภายใต้ระบบ Windows แบบ NT เช่น Windows 2000, XP, 2003, Vista มักมีปัญหาคือ เมื่อสั่งพิมพ์งานออกไปแล้ว จะต้องรออีกหลายวินาที บางครั้งอาจนานเป็นนาที โดยเฉพาะเมื่อส่งพิมพ์ไปยัง network printer บางครั้งปัญหานี้ ก็เกิดขึ้นเมื่อทำงานภายใต้ Windows 95/98/ME ด้วย

The problem has two main causes:
ปัญหาเกิดขึ้นจาก 2 สาเหตุ

  1. How the DOS program manages the printing device
    วิธีที่โปรแกรม DOS จัดการเครื่องพิมพ์
  2. How the DOS program uses the CPU on the machine
    วิธีที่โปรแกรม DOS ใช้ขีดความสามารถของ CPU

Managing the DOS printing device
การจัดการเครื่องพิมพ์ของ DOS

In the age of DOS, most of the printers were dot-matrix and connected to a parallel port (LPT1:, LPT2: or LPT3:)

ในยุคของ DOS เครื่องพิมพ์ส่วนใหญ่ เป็นแบบ dot-matrix
และต่อผ่าน parrallel port (LPT1:, LPT2: หรือ LPT3:)

A typical DOS program sends binary data (characters) to one of these ports (usually LPT1:). A dot matrix printer can start printing that data as soon as it's sent to the port and before all the data has been sent by the program.
โปรแกรมบน DOS ส่วนใหญ่ ข้อมูลตัวอักษรออกทาง port เหล่านี้ (มักจะใช้ LPT1:) และเครื่องพิมพ์ dot-matrix สามารถเริ่มพิมพ์ข้อมูลทันที ที่ได้รับข้อมูลทาง port นั้น โดยไม่ต้องรอให้โปรแกรมส่งข้อมูลที่จะพิมพ์จบ

A DOS programmer did not need to close the printing device (port) when the print job ended, because the printer had already finished its job.

ดังนั้นโปรแกรมเมอร์ที่เขียนโปรแกรมสมัยนั้น จึงไม่จำเป็น ส่งคำสั่งปิดงานพิมพ์ไปยังเครื่องพิมพ์ เมื่อส่งข้อมูลจบ

Under Windows things are different. Laser and other graphical printers need to receive an entire page before rendering it on paper. Additionally, multiple applications running/printing on the same machine introduced the need for a printing queue, especially with network printers.
So, if the DOS program does not close the printer port at the print job end, then Windows does not know the job is really finished. It waits for a timeout value to expire before deciding to finally spool the next job.
แต่เมื่อเราใช้งานภายใต้ Windows ผลที่ได้กลับแตกต่างออกไป
เพราะเครื่องพิมพ์เลเซอร์ และเครื่องพิมพ์ graphic จะเริ่มพิมพ์ต่อเมื่อได้รับข้อมูลครบหน้ากระดาษ ยิ่งไปกว่านั้นโปรแกรมบน Windows หลายตัวที่กำลังทำงานอยู่และต้องการพิมพ์ ก็ต้องใช้งานผ่าน print queue โดยเฉพาะเวลาส่งพิมพ์ไปยัง network printers ถ้าโปรแกรมบน DOS ไม่ส่งคำสั่งปิด printer port เมื่อจบงาน Windows ก็ไม่สามารถทราบได้ว่างานพิมพ์นั้นจบหรือยัง มันจะต้องรอรับข้อมูลที่โปรแกรม DOS ส่งมาพิมพ์ต่อไปอีกระยะหนึ่ง จนครบเวลา timeout ที่ตั้งเอาไว้ จึงปิดงานพิมพ์ของโปรแกรม DOS นั้น

If you're in this situation, you can close the DOS program as soon as it finishes printing. You'll see your print job start immediately because all the DOS handles will be closed by the Operating System itself, including the printer port.

ถ้าคุณเคยเจอปัญหาอย่างนี้ คุณสามารถสั่งปิดโปรแกรม DOS หลังจากที่โปรแกรมส่งข้อมูลที่จะพิมพ์จบแล้ว เพื่อให้เครื่องพิมพ์เริ่มพิมพ์ทันที เนื่องจาก port เครื่องพิมพ์บน DOS ถูกปิดอัตโนมัติเมื่อเราปิดโปรแกรม DOS

The best solution for this problem should be to fix the DOS program, if you are the original programmer. In further articles I'll show you how to do this with popular DOS programming languages, like Basic and Clipper.

การแก้ปัญหาดีที่สุดคือ แก้โปรแกรม DOS ถ้าคุณเป็นผู้เขียนโปรแกรมนั้นเอง แต่ถ้าคุณไม่สามารถแก้ไขโปรแกรมได้ ก็คงต้องแก้ปัญหาโดยวิธีอื่น ตามที่จะแนะนำต่อไป

If you're not a programmer, you can change the Windows timer above, to make the delay shorter. Do not set the value too low or the printer could start printing before the DOS program has really finished creating the job.

ถ้าคุณไม่ใช่โปรแกรมเมอร์ คุณสามารถตั้งค่า timeout ใหม่ ให้น้อยกว่าเดิม แต่ต้องระวังอย่าตั้งค่าน้อยเกินไป จนเครื่องพิมพ์เริ่มพิมพ์ก่อนที่โปรแกรมจะส่งงานพิมพ์นั้นออกไปเสร็จ

1) If you're running an NT based Windows system (2000, XP, Vista)
The timeout value is stored into a Registry entry. TAKE CARE using RegEdit. It could be rather dangerous. If you'll perform the wrong actions, your machine could even refuse to reboot.

สำหรับ Windows ที่ใช้ระบบ NT (2000,XP,Vista) ค่า timeout อยู่ใน Registry เราต้องใช้คำสั่ง RegEdit ระวัง ถ้าคุณเข้าไปแก้ไขผิดที่ อาจทำให้เครื่องคอมพิวเตอร์ของคุณ ไม่สามารถทำงานได้เมื่อ restart ใหม่
  • In REGEDIT ( START -> RUN -> REGEDIT )
    click :
    HKey_Local_Machine
    then click :
    System
    then click :
    CurrentControlSet
    then click :
    Control
    then click : WOW
Here you'll find the LPT_timeout property. Double clicking the value you can choose how many seconds you prefer, then reboot your machine to apply the change.
เมื่อเปิดเข้าไปใน WOW คุณจะเห็นชื่อ LPT_timeout ให้ double click ตรงค่าของมัน เพื่อเข้าไปแก้ให้เป็นค่าวินาที ที่ต้องการ เมื่อแก้ไขเสร็จแล้ว คุณต้องสั่ง restart เครื่องเพื่อให้ Windows ใช้ค่าที่กำหนดใหม่นั้น

2) If you're runnign an older Windows OS (9x/ME)
Search your C drive for the SYSTEM.INI file and open it with NOTEPAD (don't use Ms-Word or other word processors). In the [386enh] section search [Network] if it does not exist enter the following:

ถ้าคุณใช้ Windows รุ่นเก่า (9x/ME) ให้ใช้โปรแกรม NOTEPAD เปิดไฟล์ที่ชื่อ SYSTEM.INI ที่อยู่ใน drive C แล้วค้นหา บรรทัดที่มีคำว่า [386enh] แล้วหาบรรทัด [Network] ที่อยู่ภายใต้มัน หรือถ้าไม่พบ ให้เพิ่มบรรทัดตามตัวอย่างต่อไปนี้ลงไป
  • [Network]
    PrintBufTime=10
    [IFSMGR]
    PrintBufTime=10

This will set the timeout to 10 seconds. Reboot your machine to apply the changes.

คำสั่งนี้ เป็นการตั้งค่า timeout เท่ากับ 10 วินาที เสร็จแล้วให้ restart เครื่องเพื่อให้ Windows ใช้ค่าที่ตั้งใหม่ในการทำงาน
DOS CPU usage
การใช้ขีดความสามารถ CPU ของ DOS

Unlike Windows, MS-DOS was a single-user operating system. You could only run a single program at a time, which could even keep the entire CPU for itself, to work as fast as possible.
This causes a common problem for DOS programs running on recent Windows machines: the CPU hogging.
ข้อแตกต่างระหว่าง Windows กับ DOS คือ DOS สามารถเรียกโปรแกรมใช้งานทีละโปรแกรม ดังนั้น DOS จึงใช้ขีดความสามารถทั้งหมดของ CPU เพื่อให้ทำงานได้เร็วที่สุด และนี่คือปัญหาที่ทำให้โปรแกรมบน DOS หลายตัวเมื่อนำมาใช้งานภายใต้ Windows จะเกิดปัญหา การทำงานสะดุด ไม่ลื่นไหลเหมือนกับการทำงานบน DOS
Typically, when polling the keyboard (during a wait state), the DOS program performs an infinite loop, to check it as fast as possible. In DOS this did not cause any troubles at all, but on Windows, the system might be so "busy" that no other tasks can be performed (including the print spooling process, which usually starts when the DOS program has finished printing and is waiting for user input, typically on a menu).
กล่าวคือ ในระหว่างที่รอรับการกด keyboard จากผู้ใช้ โปรแกรมบน DOS จะวนรอเพื่อตรวจสอบการกด keyboard ตลอดเวลา แต่สำหรับใน Windows การทำงานดังกล่าว มีผลให้ระบบ ไม่สามารถแบ่งเวลาของ CPU ระหว่างที่รอรับ keyboard ไปให้โปรแกรมหรือการทำงานอื่นๆ ที่รออยู่ รวมทั้ง print spooler ของ Windows ที่รับข้อมูลจากโปรแกรม DOS มาส่งพิมพ์ ก็ไม่สามารถทำการประมวลผลได้เช่นกัน

To check if your own DOS program is actually hogging the CPU, please try to leave the Task Manager opened while it's on execution.

การตรวจสอบว่าโปรแกรม DOS นั้นกินเวลาของ CPU มากแค่ไหน สามารถดูได้จาก Task Manager ระหว่างที่เรียกใช้โปรแกรม DOS นั้น ดังนี้
  • Press CTRL+ALT+DEL
    Click the "Performance" tab

If the CPU usage often go to 100 percent while using your DOS program, then you're experiencing this problem.

ถ้าการทำงานของ CPU ขึ้นเป็น 100% ระหว่างที่เรียกใช้โปรแกรม DOS แสดงว่าเกิดปัญหานี้ขึ้นแล้ว
A DOS programmer cannot do much for this problem because the keyboard polling routine is usually implemented in a low level routine inside the DOS compiler itself. Fortunately some patches has been released for popular DOS compilers to include a "release CPU" command inside that loop.
สำหร้บโปรแกรมเมอร์ผู้เขียนโปรแกรม DOS เอง สามารถแก้ปัญหานี้ได้ง่ายกว่า โดยการปรับโปรแกรมในส่วนของ loop ที่รอรับ keyboard หรือถ้าสามารถ compile โปรแกรมใหม่ โดยใช้ compiler รุ่นใหม่ ที่มี option ที่สั่งให้ release CPU ภายใน loop รอรับ keyboard ให้เลือกอยู่แล้ว ก็เพียงแค่สั่ง compile โปรแกรมใหม่เท่านั้น
You can find some of the DOS 100% CPU patches at the Citrix website.
If the solutions in the page above does not apply to you, you may want to try TameDOS as a replacement for the Windows Command Prompt, which is supposed to solve this problem.
คุณสามารถหาโปรแกรมเล็ก ๆ ที่ใช้แก้ปัญหา 100% CPU จากเว็บของ Citrix หรืออาจลองใช้โปรแกรม TameDOS แทน Windows Command Prompt เดิมก็ได้

original article http://www.amazines.com/Software/article_detail.cfm/329253?articleid=329253

1 ความคิดเห็น:

adm กล่าวว่า...

แปล.. อ่านง่ายดีครับ
ขอบคุณมาก ที่ช่วยแปลให้อ่าน

Google