C# 针式打印机 要用C#控制针式打印机,一行一行的打印,怎么弄呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #region声明usingSystem;usingSystem.Runtime.InteropServices;usingSystem.IO;#endregionnamespaceLongRuan{///<summary>///POSPrinter的摘要说明。///</summary>publicclassPOSPrinter{constintOPEN_EXISTING=3;stringprnPort="LPT1";[DllImport("kernel32.dll",CharSet=CharSet.Auto)]privatestaticexternIntPtrCreateFile(stringlpFileName,intdwDesiredAccess,intdwShareMode,intlpSecurityAttributes,intdwCreationDisposition,intdwFlagsAndAttributes,inthTemplateFile);publicPOSPrinter(){////TODO:在此处添加构造函数逻辑//}publicPOSPrinter(stringprnPort){this.prnPort=prnPort;//打印机端口}publicstringPrintLine(stringstr){IntPtriHandle=CreateFile(prnPort,0x40000000,0,0,OPEN_EXISTING,0,0);if(iHandle.ToInt32()==-1){return"没有连接打印机或者打印机端口不是LPT1";}else{FileStreamfs=newFileStream(iHandle,FileAccess.ReadWrite);StreamWritersw=newStreamWriter(fs,System.Text.Encoding.Default);//写数据sw.WriteLine(str);//开钱箱//sw.WriteLine(Chr(&H1B)&Chr(70)&Chr(0)&Chr(20)&Chr(&HA0))sw.Close();fs.Close();return"";}}}}--------------------------------------------------------------------------------调用方法:LongRuan.POSPrinterprn=newLongRuan.POSPrinter("LPT1");stringstr=prn.PrintLine("写端口测试!");if(str!="")MessageBox.Show(str);答:>#region声明usingSystem;usingSystem.Runtime.InteropServices;usingSystem.IO;#endregionnamespaceLongRuan{///<summary>///POSPrinter的摘要说明。///</summary>publicclassPOSPrinter{constintOPEN_EXISTING=3;stringprnPort="LPT1";[DllImport("kernel32.dll",CharSet=CharSet.Auto)]privatestaticexternIntPtrCreateFile(stringlpFileName,intdwDesiredAccess,intdwShareMode,intlpSecurityAttributes,intdwCreationDisposition,intdwFlagsAndAttributes,inthTemplateFile);publicPOSPrinter(){////TODO:在此处添加构造函数逻辑//}publicPOSPrinter(stringprnPort){this.prnPort=prnPort;//打印机端口}publicstringPrintLine(stringstr){IntPtriHandle=CreateFile(prnPort,0x40000000,0,0,OPEN_EXISTING,0,0);if(iHandle.ToInt32()==-1){return"没有连接打印机或者打印机端口不是LPT1";}else{FileStreamfs=newFileStream(iHandle,FileAccess.ReadWrite);StreamWritersw=newStreamWriter(fs,System.Text.Encoding.Default);//写数据sw.WriteLine(str);//开钱箱//sw.WriteLine(Chr(&H1B)&Chr(70)&Chr(0)&Chr(20)&Chr(&HA0))sw.Close();fs.Close();return"";}}}}--------------------------------------------------------------------------------调用方法:LongRuan.POSPrinterprn=newLongRuan.POSPrinter("LPT1");stringstr=prn.PrintLine("写端口测试!");if(str!="")MessageBox.Show(str); 用api createfile 像写文件一样往 lpt1 写随便找个代码,没有仔细看,思路是对的。http://bytes.com/topic/c-sharp/answers/942783-write-escape-sequence-epson-printer 最后我用并口控制的打印机。usb总是控制不好 是的,这个代码要用lpt端口。 X轴有重复值的交易走势图如何实现? WCF 与WEB SERVICES 的区别? 菜鸟问题,帮帮忙 如何控制DataGrid垂直滚动条的位置 指定的路径不可用,IIS可能并未运行或者是路径已经重定向到另外的计算机。请检查internet servers manager 中虚拟目录的状态。 拒絕存取路徑問題? 最近做程序碰到个难题. swfupload部署到IIS上之后文件上传错误 有什么软件可以监视进程行为的 怎样使用水晶报表? 如何判断数组元素且顺序一致 存储过程 sqlserver
usingSystem;
usingSystem.Runtime.InteropServices;
usingSystem.IO;
#endregion
namespaceLongRuan
{
///<summary>
///POSPrinter的摘要说明。
///</summary>
publicclassPOSPrinter
{
constintOPEN_EXISTING=3;
stringprnPort="LPT1";
[DllImport("kernel32.dll",CharSet=CharSet.Auto)]
privatestaticexternIntPtrCreateFile(stringlpFileName,
intdwDesiredAccess,
intdwShareMode,
intlpSecurityAttributes,
intdwCreationDisposition,
intdwFlagsAndAttributes,
inthTemplateFile);
publicPOSPrinter()
{
//
//TODO:在此处添加构造函数逻辑
//
}
publicPOSPrinter(stringprnPort)
{
this.prnPort=prnPort;//打印机端口
}
publicstringPrintLine(stringstr)
{
IntPtriHandle=CreateFile(prnPort,0x40000000,0,0,OPEN_EXISTING,0,0);
if(iHandle.ToInt32()==-1)
{
return"没有连接打印机或者打印机端口不是LPT1";
}
else
{
FileStreamfs=newFileStream(iHandle,FileAccess.ReadWrite);
StreamWritersw=newStreamWriter(fs,System.Text.Encoding.Default);//写数据
sw.WriteLine(str);
//开钱箱
//sw.WriteLine(Chr(&H1B)&Chr(70)&Chr(0)&Chr(20)&Chr(&HA0))
sw.Close();
fs.Close();
return"";
}
}
}
}--------------------------------------------------------------------------------
调用方法:
LongRuan.POSPrinterprn=newLongRuan.POSPrinter("LPT1");
stringstr=prn.PrintLine("写端口测试!");
if(str!="")
MessageBox.Show(str);
答:>#region声明
usingSystem;
usingSystem.Runtime.InteropServices;
usingSystem.IO;
#endregion
namespaceLongRuan
{
///<summary>
///POSPrinter的摘要说明。
///</summary>
publicclassPOSPrinter
{
constintOPEN_EXISTING=3;
stringprnPort="LPT1";
[DllImport("kernel32.dll",CharSet=CharSet.Auto)]
privatestaticexternIntPtrCreateFile(stringlpFileName,
intdwDesiredAccess,
intdwShareMode,
intlpSecurityAttributes,
intdwCreationDisposition,
intdwFlagsAndAttributes,
inthTemplateFile);
publicPOSPrinter()
{
//
//TODO:在此处添加构造函数逻辑
//
}
publicPOSPrinter(stringprnPort)
{
this.prnPort=prnPort;//打印机端口
}
publicstringPrintLine(stringstr)
{
IntPtriHandle=CreateFile(prnPort,0x40000000,0,0,OPEN_EXISTING,0,0);
if(iHandle.ToInt32()==-1)
{
return"没有连接打印机或者打印机端口不是LPT1";
}
else
{
FileStreamfs=newFileStream(iHandle,FileAccess.ReadWrite);
StreamWritersw=newStreamWriter(fs,System.Text.Encoding.Default);//写数据
sw.WriteLine(str);
//开钱箱
//sw.WriteLine(Chr(&H1B)&Chr(70)&Chr(0)&Chr(20)&Chr(&HA0))
sw.Close();
fs.Close();
return"";
}
}
}
}--------------------------------------------------------------------------------
调用方法:
LongRuan.POSPrinterprn=newLongRuan.POSPrinter("LPT1");
stringstr=prn.PrintLine("写端口测试!");
if(str!="")
MessageBox.Show(str);
http://bytes.com/topic/c-sharp/answers/942783-write-escape-sequence-epson-printer