当前位置:编程学习 > C#/ASP.NET >>

【求 C# 打开钱箱代码】

--------------------编程问答-------------------- 先顶下,不要沉了,急 --------------------编程问答-------------------- 写入byte[]数据到打印机,怎么弄出这么多ToString? --------------------编程问答--------------------
引用 2 楼 sp1234 的回复:
写入byte[]数据到打印机,怎么弄出这么多ToString?


代码是网上找的。

菜鸟,不太懂,请大侠指点下,如何操作,谢谢 --------------------编程问答-------------------- --------------------编程问答--------------------

[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);

        #region 开钱箱
        /// <summary>
        /// 开钱箱
        /// </summary>
        public  void OpenDrawer()
        {
            try
            {
                IntPtr iHandle = CreateFile("LPT1", 0x40000000, 0, 0, 3, 0, 0);
                                if (iHandle.ToInt32() == -1)
                {
                    MessageBox.Show("没有连接打印机或者打印机端口未打开!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                else
                {
                    SafeFileHandle handle = new SafeFileHandle(iHandle, true);
                    FileStream fs = new FileStream(handle, FileAccess.ReadWrite);
                    StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
                    sw.Write(((char)27).ToString() + "p" + ((char)0).ToString() + ((char)60).ToString() + ((char)255).ToString());

                    sw.Close();

                    fs.Close();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
        #endregion
--------------------编程问答--------------------
引用 5 楼 aisunrong 的回复:
C# code

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr CreateFile(string lpFileName,
        int dwDesiredAccess,
        int dwShareMode,
        int ……


关键的代码都和我一样,
我就是写了红色代码没反应 --------------------编程问答-------------------- 有高手吗 --------------------编程问答-------------------- 端口是串口COM1的,能不能用这个代码 --------------------编程问答-------------------- 串口COM1打不开
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,