ESC指令打印

Bob66666 2013-12-07 06:09:24
 private void Form1_Load(object sender, EventArgs e)
{
printClass myPrint = new printClass();
if (!myPrint.init()) { MessageBox.Show("error"); }
else
{
myPrint.print("aaaaaaa");
myPrint.clo();

}
}
}
public class printClass {
const uint GENERIC_WRITE = 0x40000000;
const uint GENERIC_READ = 0x80000000;
const uint OPEN_EXISTING = 0x03;
[DllImport("kernel32.dll",CharSet=CharSet.Auto,SetLastError=true)]
static extern SafeFileHandle CreateFile(string name,uint access,uint shareMode,uint security,uint dispition,uint flag,uint tempfile);
SafeFileHandle handle;
FileStream fs;
public bool init() {
handle = CreateFile(@"LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (handle.IsInvalid) { return false; }
else {
fs = new FileStream(handle, FileAccess.Write);
fs.WriteByte(0x1B); fs.WriteByte(0x40);
return true;
}
}
public void print(string text)
{
byte[] bytes = Encoding.ASCII.GetBytes(text);
fs.Write(bytes, 0, bytes.Length);
}
public void scroll() {
fs.WriteByte(0x1B); fs.WriteByte(0x4A); fs.WriteByte(0x1E);
}
public void cate() {
fs.WriteByte(0x1B); fs.WriteByte(0x69);
}


WIN7系统下,运行后假死,窗体不显示,打印机也无反应,不知问题所在.
...全文
200 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bob66666 2013-12-08
  • 打赏
  • 举报
回复
ESC应该是与驱动无关的。
Bob66666 2013-12-08
  • 打赏
  • 举报
回复
原来是驱动问题导致的。
江王 2013-12-07
  • 打赏
  • 举报
回复
试试这种方法,你那种调用方式不是好方法。http://support.microsoft.com/kb/322091

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧