[OT] Jak primo na tiskarnu pres USB + carove kody?

Míra Beneš benes.m@stapro.cz
Pátek Říjen 16 11:11:23 CEST 2009


Pouzijte ovladac Generic - Generic/Text Only
a sypte tam ty EPL/ZPL data naprimo. funkcni na stovkach tiskaren.
vice klidne soukromne

tu je trida v C# - stejne pouziva api windows

/// <summary>
	/// Primy tisk dat na tiskarnu danou UNC cestou
	/// </summary>

	public class PrintDirect
	{
		[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=false,
			  CallingConvention=CallingConvention.StdCall )]
		public static extern long OpenPrinter(string pPrinterName,ref IntPtr 
phPrinter, int pDefault);
		[ DllImport( "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=false,
			  CallingConvention=CallingConvention.StdCall )]
		public static extern long StartDocPrinter(IntPtr hPrinter, int Level, 
ref DOCINFO pDocInfo);


		[ DllImport(
			  "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=true,
			  CallingConvention=CallingConvention.StdCall)]
		public static extern long StartPagePrinter(IntPtr hPrinter);
		[ DllImport( "winspool.drv",CharSet=CharSet.Ansi,ExactSpelling=true,
			  CallingConvention=CallingConvention.StdCall)]
		public static extern long WritePrinter(IntPtr hPrinter,string data, 
int buf,ref int pcWritten);

		[ DllImport( "winspool.drv" ,CharSet=CharSet.Unicode,ExactSpelling=true,
			  CallingConvention=CallingConvention.StdCall)]
		public static extern long EndPagePrinter(IntPtr hPrinter);

		[ DllImport( "winspool.drv"
			  ,CharSet=CharSet.Unicode,ExactSpelling=true,
			  CallingConvention=CallingConvention.StdCall)]
		public static extern long EndDocPrinter(IntPtr hPrinter);

		[ DllImport(
			  "winspool.drv",CharSet=CharSet.Unicode,ExactSpelling=true,
			  CallingConvention=CallingConvention.StdCall )]
		public static extern long ClosePrinter(IntPtr hPrinter);

		/// <summary>
		/// Vytiskne zadane retezce na zadanou tiskarnu
		/// </summary>
		/// <param name="UNCPath">UNC cesta k tiskarne</param>
		/// <param name="data"></param>
		/// <returns></returns>
		public static string Print(string UNCPath, params string[] data)
		{
			System.IntPtr lhPrinter=new System.IntPtr();

			DOCINFO di = new DOCINFO();
			int pcWritten=0;
			PrintDirect.OpenPrinter(UNCPath,ref lhPrinter,0);

			if (lhPrinter == (System.IntPtr) 0)
			{
				return "Printer \"" + UNCPath + "\" not found";
			}

			PrintDirect.StartDocPrinter(lhPrinter,1,ref di);
			PrintDirect.StartPagePrinter(lhPrinter);
			foreach (string ret in data)
			{
				try
				{
					PrintDirect.WritePrinter(lhPrinter,ret,ret.Length,ref pcWritten);
				}
				catch (Exception e1)
				{
					return e1.Message;
				}
				if (ret.Length != pcWritten)
					return "Printing error";
			}
			PrintDirect.EndPagePrinter(lhPrinter);
			PrintDirect.EndDocPrinter(lhPrinter);
			PrintDirect.ClosePrinter(lhPrinter);
			return null;
		}
	}

	[StructLayout( LayoutKind.Sequential)]
	public struct DOCINFO
	{
		[MarshalAs(UnmanagedType.LPWStr)]public string pDocName;
		[MarshalAs(UnmanagedType.LPWStr)]public string pOutputFile;
		[MarshalAs(UnmanagedType.LPWStr)]public string pDataType;
	}

}




On 15.10.2009 23:00, Jaroslav Buchta wrote:
> Zdravim, jedna se o Zebru ZM400, zatim jsem resil pripojeni pres PP nebo
> RS232 a tam neni problem primo pouzit ZPL jazyk tiskarny otevrenim portu
> LPT1 nebo COMx. Jak se na ni ale dostat pres USB???
> Nebo jeste lepe, jak tisknout carove kody skrz windows? (cili, kde
> rostou nejake osvedcene fonty, nebo jak jinak to nejlepe udelat? Vim ze
> u jineho typu tiskarny, kde byly carove kody primo v ovladacich s tim
> byly i problemy)
> A nebo da se nejak jit pres High level, pouzit dodavany Zebra Designer a
> ten pak spoustet z aplikace s prikazem, aby vytisknul jednu etiketu?
> Tiskarnu budu mit az zitra, specha to a musi to byt zadarmo.
> Dik za inspiraci.
>


Další informace o konferenci Hw-list