【问题标题】:Send data to LPT on windows XP在 Windows XP 上将数据发送到 LPT
【发布时间】:2011-01-02 14:08:05
【问题描述】:

我想将数据发送到 LPT1 上的打印机,我尝试完全正确 this 但我的 CreateFile 返回 -1(系统找不到指定的文件。来自 HRESULT:0x80070002 的异常)。 如何打开LPT1端口并将数据发送到? 我在 XP 上尝试这个,然后在 win7 64 位中尝试,因为从我读过的内容来看,在 win7 64 位中使用 LPT 有点问题,或者我应该说 64 位的问题:)

PS:由于这是我今年的第一篇文章:祝大家新年快乐。

【问题讨论】:

  • 并行端口在很久以前就走上了渡渡鸟的道路。机器也有吗?例外说它没有。使用设备管理器,在 superuser.com 上提出更多问题
  • 打印机用USB连接

标签: c# .net dllimport kernel32 lpt


【解决方案1】:

您可以尝试以下方法。适用于文本模式。

'net share' 显示如下:

Share name   Resource                        Remark

-------------------------------------------------------------------------------
IPC$                                         Remote IPC
D$           D:\                             Default share
print$       C:\WINDOWS\system32\spool\drivers
                                             Printer Drivers
wwwroot$     c:\inetpub\wwwroot              Used for file share access to web
C$           C:\                             Default share
ADMIN$       C:\WINDOWS                      Remote Admin
SharedDocs   C:\DOCUMENTS AND SETTINGS\ALL USERS\DOCUMENTS

Printer2     IP_192.168.115.227     Spooled  HP LaserJet 2200 Series PS (MS)
TEST         LPT1:                  Spooled  Microsoft XPS Document Writer
The command completed successfully.

这是代码

using System;
using System.IO;

namespace SimplePrinting
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class SimplePrinting
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            string printingTaskFileName = Path.GetTempFileName(); // file in %temp%

            System.IO.FileStream printingTaskFile;
            System.IO.StreamWriter printingTaskStream;

            printingTaskFile = new System.IO.FileStream(printingTaskFileName, FileMode.Append);
            printingTaskStream = new System.IO.StreamWriter(printingTaskFile, System.Text.Encoding.Default);

            printingTaskStream.Write("some content here");
            printingTaskStream.Flush();
            printingTaskStream.Close();

            File.Copy(printingTaskFileName, @"\\127.0.0.1\TEST", true); // also can be \\127.0.0.1\PNT5 or smth like that
            File.Delete(printingTaskFileName);
        }
    }
}

【讨论】:

  • 我得到:FileNotFound:找不到文件“LPT1”
  • 我用共享名称“TSCTTP-1”共享了打印机(我忘记了),我尝试了而不是“LPT1”@“\\127.0.0.1\TSCTTP-1”,但我得到: IOException: 无法到达网络位置。
  • 我已经用我的设置和完整的代码片段更新了答案。不要忘记为执行代码的用户检查共享打印机的用户权限。
  • 感谢您的回答,您试图帮助我,我是个白痴,我在 cmd 中运行网络共享,我有 TSCTTP-1......USB001,我检查了打印机和传真我的打印机端口,确实它设置在 USB 上,如果我切换到 LPT1,它就不起作用,我在说,通过 Bartender 软件打印,而不是我要创建的软件,所以我猜我必须使用 USB也在我想要做的应用程序中吗?
  • 好吧,只需访问 USB 打印机抛出共享名称。对我来说,这是最简单的方法。
猜你喜欢
  • 1970-01-01
  • 2011-03-03
  • 2013-11-02
  • 1970-01-01
  • 2011-04-13
  • 1970-01-01
  • 2013-12-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多