我正在尝试通过使用C#的FTDI Basic主板(在Mac 10.8下运行Mono 3.2)在我的笔记本电脑和热敏打印机(从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...
任何想法是什么问题?
很少有事情需要注意:
谢谢, 菲永
答案 0 :(得分:0)
在我看来,你的布线可能不正确。
FTDI板上的TX(发送)应连接到打印机上的RX(接收)。同样,FTDI板上的RX(接收)应连接到打印机上的TX(发送)。
有关进一步说明的示例,请参阅本教程:https://www.sparkfun.com/tutorials/224