使用.net打印到热敏打印机 [英] Print to Thermal Printer using .net
本文介绍了使用.net打印到热敏打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在不使用OPOS驱动程序的情况下将收据打印到热敏打印机。
请在这种情况下指导我。
谢谢
解决方案
您好在中创建一个通用文本打印机pc(添加新打印机......或谷歌如何添加通用文本打印机)
看看这篇文章如何将原始数据发送到打印机。
http://support.microsoft.com/kb/322090 [ ^ ]
使用它你可以将ESC / POS命令发送到打印机。
对于ESC / POS命令参考使用此链接 http://www.google.co.in/url?sa=t&source=web&cd=1&ved=0CBYQFjAA&url=http%3A%2F%2Fnicholas.piasecki.name %2Fblog%2Fwp-content%2Fuploads%2F2009%2F12%2FESC-POS-Command-Guide.pdf& ei = kaxbTcvZI8uXcde_iNoK& usg = AFQjCNFX385l9jOit_86cfsoHmpH4kPKKQ [ ^ ]
或google它更多
1.使用打印机端口创建打印机的句柄
2.WriteFile(句柄,Str,len,0,NULL)
public partial class frmBook:表格
{
public const Int32 FILE_ATTRIBUTE_NORMAL = 128 ; // 初始化端口属性
public const Int32 INVALID_HANDLE_VALUE = -1;
public const Int32 GENERIC_READ = -2147483648;
public const Int32 GENERIC_WRITE = 1073741824 ;
public const Int32 CREATE_NEW = 1 ;
public const Int32 CREATE_ALWAYS = 2 ;
public const Int32 OPEN_EXISTING = 3 ;
受保护 void Print_Ticket( string ticketNo, string seatNo, string Showtime, string 价格)
{
IntPtr ptr = CreateFile( LPT1,GENERIC_WRITE, 0 ,
IntPtr .Zero,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, IntPtr .Zero);
/ * 处理不好? INVALID_HANDLE_VALUE * /
if (ptr.ToInt32()== -1)
{
/ * 要求框架将win32错误代码编组为异常* /
Marshal.ThrowExceptionForHR(Marshal。 GetHRForLastWin32Error());
}
其他
{
/// //// Print Reciept Print //////
FileStream lpt = new FileStream(ptr,FileAccess.ReadWrite);
byte [] LineFeedChar = new byte [] { 13 , 10 };
byte [] BackNormalChar = new byte [] { 27 , 33 , 0 };
byte [] CuttingChar = new byte [] { 29 , 86 , 66 };
字节 [] buf_TheaterName = new 字节 [ 8048 ];
字节 [] buf_Address = new 字节 [ 8048 ];
字节 [] buf_Line1 = 新 字节 [ 8048 ];
字节 [] buf_TicketNo = new 字节 [ 8048 ];
字节 [] buf_Date = new 字节 [ 8048 ];
字节 [] buf_SeatNo = new 字节 [ 8048 ];
字节 [] buf_Showtime = new 字节 [ 8048 ];
字节 [] buf_Price = new 字节 [ 8048 ];
字节 [] buf_FooterMsg = new 字节 [ 8048 ];
StringBuilder strFooter = new StringBuilder();
lpt.Write(CuttingChar, 0 , 3 ); //
buf_TheaterName = System.Text.Encoding.ASCII.GetBytes( + cmbTheatre.Text.ToString()+ );
lpt.Write(buf_TheaterName, 0 ,buf_TheaterName.Length);
lpt.Write(LineFeedChar, 0 , 2 );
buf_TicketNo = System.Text.Encoding.ASCII.GetBytes( 票号:。 PadLeft( 9 )+ ticketNo.PadLeft( 3 )); //
lpt.Write(buf_TicketNo, 0 ,buf_TicketNo.Length ); //
lpt.Write(LineFeedChar, 0 , 2 );
buf_Date = System.Text.Encoding.ASCII.GetBytes( 日期: .PadLeft ( 9 )+ dteBookDate.Text.PadLeft( 3 ));
lpt.Write(buf_Date, 0 ,buf_Date.Length);
lpt.Write(LineFeedChar, 0 , 2 );
buf_SeatNo = System.Text.Encoding.ASCII.GetBytes( 席位号:.PadLeft( 9 )+ seatNo.PadLeft( 3 ));
lpt.Write(buf_SeatNo, 0 ,buf_SeatNo.Length);
lpt.Write(LineFeedChar, 0 , 2 );
buf_Showtime = System.Text.Encoding.ASCII.GetBytes( Show Time:。 PadLeft( 9 )+ Showtime.PadLeft( 3 ));
lpt.Write(buf_Showtime, 0 ,buf_Showtime.Length);
lpt.Write(LineFeedChar, 0 , 2 );
buf_Price = System.Text.Encoding.ASCII.GetBytes( Price: .PadLeft ( 9 )+ Price.PadLeft( 3 ));
lpt.Write(buf_Price, 0 ,buf_Price.Length);
lpt.Write(LineFeedChar, 0 , 2 );
buf_FooterMsg = System.Text.Encoding.ASCII.GetBytes( 谢谢你访问Agin 跨度>);
lpt.Write(buf_FooterMsg, 0 ,buf_FooterMsg.Length);
lpt.Write(LineFeedChar, 0 , 2 );
lpt.Write(CuttingChar, 0 , 3 );
lpt.Write(BackNormalChar, 0 , 3 );
lpt.Close();
}
}
Hi,
I want to print the receipt to thermal printer without using OPOS driver.
Please guide me in this case.
Thanks
解决方案
Hi Create a Generic text printer in the pc (Add new Printer...or google it how to add a generic text printer)
Look at this article how to send raw data to printer.
http://support.microsoft.com/kb/322090[^]
using this you can send ESC/POS commands to the printer.
For ESC/POS commands reference use this link http://www.google.co.in/url?sa=t&source=web&cd=1&ved=0CBYQFjAA&url=http%3A%2F%2Fnicholas.piasecki.name%2Fblog%2Fwp-content%2Fuploads%2F2009%2F12%2FESC-POS-Command-Guide.pdf&ei=kaxbTcvZI8uXcde_iNoK&usg=AFQjCNFX385l9jOit_86cfsoHmpH4kPKKQ[^]
or google it for more
1.Create Handle for printer using printer port
2.WriteFile(Handle,"Str",len,0,NULL)
public partial class frmBook : Form { public const Int32 FILE_ATTRIBUTE_NORMAL = 128;//Intializing Port Attributes public const Int32 INVALID_HANDLE_VALUE = -1; public const Int32 GENERIC_READ = -2147483648; public const Int32 GENERIC_WRITE = 1073741824; public const Int32 CREATE_NEW = 1; public const Int32 CREATE_ALWAYS = 2; public const Int32 OPEN_EXISTING = 3; protected void Print_Ticket(string ticketNo, string seatNo, string Showtime, string Price) { IntPtr ptr = CreateFile("LPT1", GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, IntPtr.Zero); /* Is bad handle? INVALID_HANDLE_VALUE */ if (ptr.ToInt32() == -1) { /* ask the framework to marshall the win32 error code to an exception */ Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } else { /////// Print Reciept Print////// FileStream lpt = new FileStream(ptr, FileAccess.ReadWrite); byte[] LineFeedChar = new byte[] { 13, 10 }; byte[] BackNormalChar = new byte[] { 27, 33, 0 }; byte[] CuttingChar = new byte[] { 29, 86, 66 }; Byte[] buf_TheaterName = new Byte[8048]; Byte[] buf_Address = new Byte[8048]; Byte[] buf_Line1 = new Byte[8048]; Byte[] buf_TicketNo = new Byte[8048]; Byte[] buf_Date = new Byte[8048]; Byte[] buf_SeatNo = new Byte[8048]; Byte[] buf_Showtime = new Byte[8048]; Byte[] buf_Price = new Byte[8048]; Byte[] buf_FooterMsg = new Byte[8048]; StringBuilder strFooter = new StringBuilder(); lpt.Write(CuttingChar, 0, 3); // buf_TheaterName = System.Text.Encoding.ASCII.GetBytes(" " + cmbTheatre.Text.ToString() + " "); lpt.Write(buf_TheaterName, 0, buf_TheaterName.Length); lpt.Write(LineFeedChar, 0, 2); buf_TicketNo = System.Text.Encoding.ASCII.GetBytes("Ticket No :".PadLeft(9) + ticketNo.PadLeft(3));// lpt.Write(buf_TicketNo, 0, buf_TicketNo.Length);// lpt.Write(LineFeedChar, 0, 2); buf_Date = System.Text.Encoding.ASCII.GetBytes("Date :".PadLeft(9) + dteBookDate.Text.PadLeft(3)); lpt.Write(buf_Date, 0, buf_Date.Length); lpt.Write(LineFeedChar, 0, 2); buf_SeatNo = System.Text.Encoding.ASCII.GetBytes("Seat No :".PadLeft(9) + seatNo.PadLeft(3)); lpt.Write(buf_SeatNo, 0, buf_SeatNo.Length); lpt.Write(LineFeedChar, 0, 2); buf_Showtime = System.Text.Encoding.ASCII.GetBytes("Show Time :".PadLeft(9) + Showtime.PadLeft(3)); lpt.Write(buf_Showtime, 0, buf_Showtime.Length); lpt.Write(LineFeedChar, 0, 2); buf_Price = System.Text.Encoding.ASCII.GetBytes("Price :".PadLeft(9) + Price.PadLeft(3)); lpt.Write(buf_Price, 0, buf_Price.Length); lpt.Write(LineFeedChar, 0, 2); buf_FooterMsg = System.Text.Encoding.ASCII.GetBytes(" Thank You Visit Agin "); lpt.Write(buf_FooterMsg, 0, buf_FooterMsg.Length); lpt.Write(LineFeedChar, 0, 2); lpt.Write(CuttingChar, 0, 3); lpt.Write(BackNormalChar, 0, 3); lpt.Close(); } }
这篇关于使用.net打印到热敏打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文