本帖最后由 oh_ku 于 2011-05-06 13:24:44 编辑

解决方案 »

  1.   

    写入byte[]数据到打印机,怎么弄出这么多ToString?
      

  2.   


    [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
      

  3.   

    端口是串口COM1的,能不能用这个代码