日期:2014-05-17  浏览次数:21345 次

C#如何驱动USB口热敏打印机
我的程序里可以支持并口打印机,也能打印小票,但是用USB口打印机就不行,打印不出来小票,请高手们看一看,是不是需要DeviceIoControl这个类才行呀,请问如何实现。
 QtSz qtsz = new QtSz();
        string dpmc = QtSz.scmc;
        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);
                QT qt11 = new QT("LPT1");
                //string str=qt11.PrintLine("");
                IntPtr iHandle1 = CreateFile(prnPort, 0x50000000, 0, 0, OPEN_EXISTING, 0, 0);
                if (iHandle1.ToInt32() == -1)
                {
                    Console.WriteLine(iHandle1.ToString());
                    //return "没有连接打印机或者打印机端口不是LPT1";

                }

                else
                {
                    Console.WriteLine(iHandle1.ToString());

                    FileStream fs = new FileStream(iHandle1, FileAccess.ReadWrite);

                    StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
                    //PrintEsc(1);

                    //sw.WriteLine(str);
                    //开钱箱指令
                    sw.Write(((char)27).ToString() + "p" + ((char)0).ToString() + ((char)60).ToString() + ((char)255).ToString());
       &nb