【问题标题】:Thermal Printer - Laptop via FTDI Basic Board and C#热敏打印机 - 通过 FTDI 基本板和 C# 的笔记本电脑
【发布时间】:2013-08-28 13:20:40
【问题描述】:

我正在尝试使用 C#(在 Mac 10.8 下运行 Mono 3.2)通过 FTDI Basic 板在我的笔记本电脑和热敏打印机(从 Sparkfun 购买)之间建立链接。我一直在使用 .net 库:

http://electronicfields.wordpress.com/2011/09/29/thermal-printer-dot-net/

https://github.com/yukimizake/ThermalDotNet

代码似乎没有任何错误(我已经更改了串行端口和波特率以匹配我的设置)并且它似乎在终端上运行了整个程序。但是,它无法与打印机交互,因此没有打印任何内容。

这是我正在使用的确切代码:

using System;
using System.IO;
using System.Text; 
using System.Threading;
using System.IO.Ports;
//using System.Collections.Generic;
//using System.Drawing;
using ThermalDotNet;
using Microsoft.SPOT;

namespace ThermalPrinterTestApp
{
class PrinterClass
{
    SerialPort printerPort;
    ThermalPrinter printer;

    public PrinterClass(string printerPortName = "/dev/tty.usbserial-AD025HP0")
    {
        //Serial port init
        printerPort = new SerialPort(printerPortName, 19200);

        if (printerPort != null)
        {
            Debug.Print("Port ok");
            if (printerPort.IsOpen)
            {
                printerPort.Close();
            }
        }

        Debug.Print("Opening port");

        try
        {
            printerPort.Open();
        }
        catch
        {
            Debug.Print("I/O error");
            //Environment.Exit(0);
        }

        //Printer init
        printer = new ThermalPrinter(printerPort, 9, 110, 10);
        printer.Reset();
    }

    public void TestBarcode()
    {
        printer.WakeUp(); 
        ThermalPrinter.BarcodeType myType = ThermalPrinter.BarcodeType.ean13;
        string myData = "3350030103392";
        printer.SetBarcodeLeftSpace(25);
        printer.WriteLine(myType.ToString() + ", data: " + myData);
        printer.SetLargeBarcode(true);
        printer.LineFeed();
        printer.PrintBarcode(myType,myData);
        printer.LineFeed(2);
    }

    /*
    static void TestImage(ThermalPrinter printer)
    {
        printer.WriteLine("Test image:");
        Bitmap img = new Bitmap("../../../mono-logo.png");
        printer.LineFeed();
        printer.PrintImage(img);
        printer.LineFeed();
        printer.WriteLine("Image OK");
    }*/

    public void PrintTest()
    {
        printer.WakeUp();
        Debug.Print(printer.ToString());

        //System.Threading.Thread.Sleep(5000);
        printer.SetBarcodeLeftSpace(25);
        TestBarcode();
        printer.LineFeed(3);

        //System.Threading.Thread.Sleep(5000);
        //TestImage();

        //System.Threading.Thread.Sleep(5000);

        printer.WriteLineSleepTimeMs = 200;
        printer.WriteLine("Default style");
        printer.WriteLine("PrintingStyle.Bold",ThermalPrinter.PrintingStyle.Bold);
        printer.WriteLine("PrintingStyle.DeleteLine",ThermalPrinter.PrintingStyle.DeleteLine);
        printer.WriteLine("PrintingStyle.DoubleHeight",ThermalPrinter.PrintingStyle.DoubleHeight);
        printer.WriteLine("PrintingStyle.DoubleWidth",ThermalPrinter.PrintingStyle.DoubleWidth);
        printer.WriteLine("PrintingStyle.Reverse",ThermalPrinter.PrintingStyle.Reverse);
        printer.WriteLine("PrintingStyle.Underline",ThermalPrinter.PrintingStyle.Underline);
        printer.WriteLine("PrintingStyle.Updown",ThermalPrinter.PrintingStyle.Updown);
        printer.WriteLine("PrintingStyle.ThickUnderline",ThermalPrinter.PrintingStyle.ThickUnderline);
        printer.SetAlignCenter();
        printer.WriteLine("BIG TEXT!",((byte)ThermalPrinter.PrintingStyle.Bold +
            (byte)ThermalPrinter.PrintingStyle.DoubleHeight +
            (byte)ThermalPrinter.PrintingStyle.DoubleWidth));
        printer.SetAlignLeft();
        printer.WriteLine("Default style again");           
        printer.LineFeed(3);

        printer.Sleep();
    }
}
}

这是我运行程序后得到的终端日志:

Port ok
Opening port
ThermalPrinter:
    _serialPort=/dev/tty.usbserial-AD025HP0,
    _maxPrintingDots=2,
    _heatingTime=180,
    _heatingInterval=2,
    PictureLineSleepTimeMs=40,
    WriteLineSleepTimeMs=0,
    Encoding=ibm850
Printer is now offline.

Press any key to continue...

任何想法是什么问题?

注意事项:

  1. 打印机已经能够打印出一个样本,所以它似乎可以正常工作。
  2. 当我播放程序时,我注意到在 FTDI 上只有 TX(发送?)亮起,而 RX(接收?)保持不亮。我检查了接线,一切似乎都井井有条,所以不确定是否有任何问题(我已附上图片)[编辑:图片的代表点不足!]
  3. 我也尝试使用 Arduino 作为比较,但有类似的错误(调试正常但没有交互)
  4. 我是初学者,因此对于过于简单化或重大疏忽深表歉意!

谢谢, 芬恩

【问题讨论】:

标签: c# printing mono thermal-printer ftdi


【解决方案1】:

在我看来你的接线可能不正确。

FTDI 板上的 TX(发送)应连接到打印机上的 RX(接收)。同样,FTDI 板上的 RX(接收)应连接到打印机上的 TX(发送)。

请参阅本教程以获取进一步说明的示例:https://www.sparkfun.com/tutorials/224

【讨论】:

  • 就是这样!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-30
  • 2022-08-03
  • 2016-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-27
相关资源
最近更新 更多