Printing in (parallel port) Matrix of dots over C #

For the needs of the project, I want to print on LPT1 in certain places, this will print the document in a matrix printer, where I have to print the values โ€‹โ€‹in the places where they should go. I really enjoy coming back and I donโ€™t know where to start. The Internet does not have specific information about printing to an LPT port with C #, and especially about how to send values โ€‹โ€‹to specific places during printing. Is there a good example? tutorial for this? will be the savior of life.

+4
source share
4 answers

I could offer one thing to make your life easier, install the universal text printer driver (this is standard) and install it on the LPT1 port. Then you can simply open 'LPT1' and send the escape code sequence to indicate the type of font (bold / italics), underlined, font pitch, etc. I do not know if resources will be required. But I would suggest that it would be something like this:

  System.IO.StreamWriter sr = new System.IO.StreamWriter (@ "\\. \ LPT1");
 sr.Write (0x1b);  sr.Write ('k');  sr.Write ('1');  sr.Write ("Hello");  // print in sans serif
 sr.WriteLine ();
 sr.Flush ();
 sr.Close ();

Resources

  • Printing to a zebra printer using VB.NET (this can be easily translated into C # or compiled into a DLL and referenced in your C # project)
  • MSDN article on how to interact with LPT1
  • The following is an extensive list of information related to the Parallel Port . (see below under "Programming Tools for Port I / O and Interrupts"), discussing the use of this DLL called inpout32.
  • Here is another article about MSDN that shows how to perform rough printing.

Edited @ 2017-07-12: Updated parallel port link to use reverse archive machine.

+5
source

Does the printer have a printer driver? If so, it doesn't matter if it prints to LPT1 or not, it just uses standard print media. A.

A similar question: Printing a matrix of points in C #?

+3
source

If your printer has drivers for Windows, you can use standard printing methods. See the Petzold Book on Microsoft Windows Programming with C # for good input.

+1
source

Hey, I just got a dot matrix printer in 2019, and you can still buy ribbons for ยฃ 5.

using System.IO; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; public class ParallelPrinter { [DllImport("kernel32.dll", SetLastError = true)] static extern SafeFileHandle CreateFile(string lpFileName, FileAccess dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, FileMode dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile); public static void Print(string text) { using (SafeFileHandle fileHandle = CreateFile("LPT1:", FileAccess.Write, 0, IntPtr.Zero, FileMode.OpenOrCreate, 0, IntPtr.Zero)) { if (fileHandle.IsInvalid == true) throw new ApplicationException("Printer is Invalid"); using (FileStream stream = new FileStream(fileHandle, FileAccess.Write)) { using (StreamWriter writer = new StreamWriter(stream, Encoding.ASCII)) { writer.Write(text); } } } } } 

There are no drivers, you just need a parallel port, you can get a PCI-e card if you do not have one.

0
source

Source: https://habr.com/ru/post/1299388/


All Articles