C # operation of the small ticket machine printing using the/C mode

Source: Internet
Author: User

This method is suitable for most small ticket machines in the market, such as good bo, POS58, etc., not suitable for some label printers such as zebra printers, etc.

Direct Sticker Code:

 PrivateFileStream fs =NULL; [DllImport ("Kernel32.dll", CharSet = CharSet.Auto)]//Call System API Print function         Public Static externIntPtr CreateFile (stringFileName,//file name            UINTDesiredaccess,//access Mode            UINTShareMode,//Share mode            UINTSecurityattributes,//Security Attributes            UINTCreationdisposition,//How to Create            UINTFlagsandattributes,//file Attributes            stringhTemplateFile//handle to template file        ); /// <summary>        ///Print a small ticket/// </summary>        /// <param name= "msg" ></param>        /// <returns></returns>         Public stringPrintmsg (stringPosport,stringMsgBOOLIsopenmoneybox) {            Try{IntPtr Ihandle= CreateFile (Posport,0x40000000,0,0,3,0,NULL); if(Ihandle.toint32 () = =-1)                {                    return "Ticket Machine Connection failed. Or the port number is wrong. Please test the printer is OK!"; }                Else                {                    Try{FS=NewFileStream (Ihandle, FileAccess.ReadWrite); StreamWriter SW=NewStreamWriter (FS, System.Text.Encoding.Default);//Write DataSW.                        WriteLine (msg); //Open the cash drawer                        if(isopenmoneybox) {sw. Write ( (Char) -). ToString () +"P"+ ((Char)0). ToString () + ((Char) -). ToString () + ((Char)255).                        ToString ()); } SW.                        Flush (); Sw.                        Close (); Fs.                        Close (); return ""; }                    Catch(Exception ex) {returnEx. InnerException = =NULL?Ex. Message:ex.                    Innerexception.message; }                }            }            Catch(Exception exp) {return "TPL or COM port connection failed! "; }        }
View Code

C # operation of the small ticket machine printing using the/C mode

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.