【问题标题】:Zebra-printer TTP 2030 does not work斑马打印机 TTP 2030 不工作
【发布时间】:2014-06-30 13:06:13
【问题描述】:

我正在尝试在 Zebra 打印机 TTP 2030 中打印“Hello World”。

std::ofstream of;

of.open("Zebra TTP 2030");
if (of.is_open())
{
  debug(std::string("open : ok"));

  of << ticket.generateCode(); // return std::string
                               // ^XA^FO50,50^ADN,10,10^FDHello World^FS^XZ
  of.flush();
  of.close();
}
else 
  debug(std::string("open : ko"));

在控制台中,“open : ok”是跟踪。

我使用的是 Microsoft XP Pro (VM)。我正在使用 Visual Studio 2010。打印机是在 VM 上设置的。

有人知道为什么没有创建票证吗?

【问题讨论】:

  • 你试过of.open("PRN:");吗?
  • @CaptainGiraffe 它不起作用。我的 Zebra 打印机已连接到 USB 端口。

标签: c++ printing ofstream zebra-printers


【解决方案1】:

您已经创建了一个名为“Zebra TTP 2030”的文本文件,并且您的文本就在其中。

C++ 没有将输出发送到打印机的标准方式 - 您必须查阅 Microsoft 帮助以了解它是如何完成的。

【讨论】:

    【解决方案2】:

    从命令行打印内容的方法是使用printPrint, TechNet

    因此,您可以通过在应用程序中调用 print 来实现您的要求。例如

    #include<fstream>
    #include<string>
    #include<cstdlib>
    
    void print_to_file(string filename){
        std::ofstream printer(filename);
        printer<<"Hello";
    }
    
    //create file with contents to print
    int main(){
        std::string filename("print_this.tmp");
        print_to_file(filename);
        std::string command("print \\d:\\\\ServerName\\PrinterName ");
        std::system(command + filename);
    }
    

    正如 TechNet 文章所述,您有几个打印机名称选项。

    【讨论】:

    • 我在终端中试过这个:“无法初始化设备 \\USB001\\TTP2030”
    • USB001 不是您的计算机名称。我想您可以在打印机设置中找到它。或者运行net user
    • 这行得通。但我不得不做一个小把戏,我的 Zebra 打印机使用 USB001 端口。所以我不得不:右键单击打印机,属性>端口*检查启用打印机池。 * 选择端口 LPT1。然后,下面的代码system("print /d:lpt1 test.tmp") 工作了
    猜你喜欢
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多