打印机清空色带和清空纸张操作

mizuho_2006 2012-04-14 09:57:26
请问思路应该怎么走?打印机是并口吧,我只做过串口读取数据的程序。
如何向打印机发送指令呢?
...全文
137 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mizuho_2006 2012-04-16
  • 打赏
  • 举报
回复
纠正一下,不是条码打印机,是打印单据的打印机。

我只想知道思路,当然有代码更好了。
mizuho_2006 2012-04-16
  • 打赏
  • 举报
回复
请问加点注释可以吗?

看不太明白
烟灰洒落键盘 2012-04-16
  • 打赏
  • 举报
回复
使用LPT1口就好了,
[DllImport("kernel32")]
static extern SafeFileHandle CreateFile(
string filename,
uint desiredAccess,
uint shareMode,
uint attributes, // really SecurityAttributes pointer
uint creationDisposition,
uint flagsAndAttributes,
uint templateFile);
private const uint GENERIC_READ = 0x80000000;
private const uint GENERIC_WRITE = 0x40000000;
private const int OPEN_EXISTING = 3;
private const int INVALID_HANDLE_VALUE = -1;

public static void PrintStringToPrinter(string as_str, string s_Port_)
{
string s_Port = s_Port_;
switch (s_Port.ToUpper())
{
case "LPT1":
SafeFileHandle iHandle;
iHandle = CreateFile("LPT1", GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if (iHandle.IsInvalid)
{
throw new Exception("Can't find the printer connecting to the port of LPT1");
}
else
{
FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);
//fs.WriteTimeout=0;
byte[] byteOut;
Int32 dwCount = as_str.Length;
byteOut = new byte[dwCount];
for (int i = 0; i < dwCount; i++)
{
byteOut[i] = System.Convert.ToByte(as_str[i]);
}
fs.Write(byteOut, 0, dwCount);
fs.Flush();
fs.Close();
}
break;

}

}
mizuho_2006 2012-04-16
  • 打赏
  • 举报
回复
是的,条码打印机。
烟灰洒落键盘 2012-04-16
  • 打赏
  • 举报
回复
什么样的打印机?条码打印机?
mizuho_2006 2012-04-15
  • 打赏
  • 举报
回复
自己顶一下。。

111,126

社区成员

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

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

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