How to use Lpt Port Printing Class in C #
This article mainly introduces how to use the Lpt port printing class in C#, which is very detailed and has a certain reference value. Friends who are interested must finish reading it!
What is the operation of the C#LPT port print class? First of all, let's take a look at what is the LPT port (for printers)? LPT port is an enhanced bi-directional parallel transmission interface. Before the emergence of USB interface, it was the most commonly used interface for scanners and printers. * the transmission speed is 1.5Mbps, and the device is easy to install and use, but the speed is relatively slow. The following are specific examples of C#LPT port printing:
Summary description of using System; using System.Runtime.InteropServices; using System.IO; namespace printBarcode {/ LPTControl, operation of C#LPT port print class / public class LPTControl {public LPTControl () {} [StructLayout (LayoutKind.Sequential)] private struct OVERLAPPED {int Internal; int InternalHigh; int Offset; int OffSetHigh; int hEvent } [DllImport ("kernel32.dll")] private static extern int CreateFile (string lpFileName, uint dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile); [DllImport ("kernel32.dll")] private static extern bool WriteFile (int hFile, byte [] lpBuffer, int nNumberOfBytesToWrite, ref int lpNumberOfBytesWritten, ref OVERLAPPED lpOverlapped) [DllImport ("kernel32.dll")] private static extern bool CloseHandle (int hObject); / / Operation of C#LPT port printing class private int iHandle; public bool Open () {iHandle=CreateFile ("lpt1", 0x40000000); if (iHandle! =-1) {return true;} else {return false }} public bool Write (String Mystring) {if (iHandle! =-1) {int ionomo; OVERLAPPED x=new OVERLAPPED (); byte [] mybyte= System.Text.Encoding.Default.GetBytes (Mystring); return WriteFile (iHandle,mybyte,mybyte.Length,ref iJournal ref x);} else {throw new Exception ("Port not open!");}} public bool Close () {return CloseHandle (iHandle) }} / / the operation of the C#LPT port print class} the above is all the contents of the article "how to use the Lpt Port print Class in C#". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!