在Zebra TLP 2844的Windows 7(Windows XP没问题)上打印的问题

时间:2017-07-18 14:08:37

标签: c# asp.net .net zebra-printers zebra

我有一个Web应用程序(c#framework 3.5)来发送打印标签和两个斑马tlp 2844(第一个安装在Windows XP上,另一个安装在Windows 7上 - 两者都是共享的)。

使用相同的应用程序和代码,我可以在Windows XP的Zebra中打印(我只需更改路径:192.168.0.251/ZebraTest)。我无法在Windows 7上打印Zebra(路径:192.168.0.121/ZebraTest)。

我已经更换了使用最后一个驱动程序安装的打印机,问题是相同的 - 我只能在Windows XP上打印。

错误是:无效句柄 - 在端口返回-1。 遵循代码(错误发生在这一行:zPrint.StartWrite(impressora);):

Waterfurnace.ZebraPrint zPrint = new Waterfurnace.ZebraPrint();
zPrint.StartWrite(impressora);
zPrint.Write("Q508,019");
zPrint.Write("q831");
zPrint.Write("I8,A,351");
zPrint.Write("rN");
zPrint.Write("S3");
zPrint.Write("D7");
zPrint.Write("ZT");
zPrint.Write("JB");
zPrint.Write("OD");
zPrint.Write("R0,0");
zPrint.Write("N");
zPrint.Write("A815,415,2,3,4,3,N,\"" + nomecracha.ToUpper() + "\"");
zPrint.EndWrite();

我已经尝试过使用其他代码,例如:

ZebraPrint zPrint = new ZebraPrint();
zPrint.StartWrite(impressora);

...

public void StartWrite(string printerPath)
{
    SECURITY_ATTRIBUTES SA = default(SECURITY_ATTRIBUTES);
    IntPtr hPortP = default(IntPtr);

    //Dim retval As Integer
    //Create connection
    _hPort = CreateFile(printerPath, GENERIC_WRITE, FILE_SHARE_WRITE, ref
     SA, OPEN_EXISTING, 0, 0);
    //_hPort = CreateFile(printerPath, GENERIC_WRITE, FILE_SHARE_WRITE, 
    null, OPEN_EXISTING, 0, 0);

    //Get unsafe pointer
    hPortP = new IntPtr(_hPort);

    //convert Integer to IntPtr 
    //Create file stream
    _outFile = new FileStream(hPortP, FileAccess.Write);

    //Create stream writer
    _fileWriter = new StreamWriter(_outFile, System.Text.Encoding.Default);
}

public void Write(string rawLine)
{
    _fileWriter.WriteLine(rawLine);
}

/// <summary>
/// This function must be called after writing to the zebra printer.
/// </summary>
public void EndWrite()
{
    //Clean up
    _fileWriter.Flush();
    _fileWriter.Close();
    _outFile.Close();
    CloseHandle(_hPort);
}

0 个答案:

没有答案