C # Backend Call LPT1 port implementation of small ticket machine printing method.

Source: Internet
Author: User
Tags ticket

public class Posprinter {const int open_existing = 3;        String prnport = "LPT1";        [DllImport ("kernel32.dll", CharSet = CharSet.Auto)] private static extern IntPtr CreateFile (String lpfilename,        int dwdesiredaccess, int dwsharemode, int lpsecurityattributes, int dwcreationdisposition,        int dwflagsandattributes, int htemplatefile); Public Posprinter () {} public Posprinter (string prnport) {This.prnport = prnport;//Printer Port} public string PrintLine (String str) {IntPtr ihandle = CreateFile (prnpor            T, 0x50000000, 0, 0, open_existing, 0, 0);                if (ihandle.toint32 () = =-1) {Console.WriteLine (ihandle.tostring ());            Return "Not connected to the printer or the printer port is not LPT1";                } else {Console.WriteLine (ihandle.tostring ()); FileStream fs = new FileStream (Ihandle, FIleaccess.readwrite);                StreamWriter SW = new StreamWriter (FS, System.Text.Encoding.Default); Sw.                WriteLine ("Small ticket list"); Sw.                WriteLine (); Sw.                WriteLine (str); Sw.                WriteLine ("Print content"); Sw.                WriteLine ("---------------------------"); Sw.                Close (); Fs.                Close ();            Return "Print succeeded!"; }        }    }

Direct call to PrintLine () method to print the specific required parameters and printing format for everyone to adjust themselves.

C # Backend Call LPT1 port implementation of small ticket machine printing method.

Related Article

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.