Question

I'm attempting to set up a link between my laptop a thermal printer (bought from Sparkfun) through an FTDI Basic board using C# (running Mono 3.2 under Mac 10.8). I've been using a .net library from:

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

https://github.com/yukimizake/ThermalDotNet

The code doesn't seem to have any errors (I've changed serial ports and baudrate to match my settings) and it seems to run through the whole program on terminal. However, it fails to interact with the printer and as a consequence nothing is printed.

This is the exact code I'm using:

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();
    }
}
}

This is the terminal log I get after I run the program:

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...

Any ideas what the problem is?

Few things to note:

  1. The printer has been able to print out a sample so it seems to be working.
  2. When I play the program, I've noticed that on the FTDI only the TX (transmitting?) lights up while the RX (receiving?) stays unlit. I've checked the wiring and it all seems to be in order so not sure if anything is wrong (i've attached images) [edit: Not enough rep points for images!]
  3. I've also tried using Arduino as a comparison but had similar errors (debugging fine but no interaction)
  4. I'm a beginner so apologies for oversimplifications or grand oversights!

Thanks, Fionn

Was it helpful?

Solution

It looks to me like your wiring might not be correct.

TX (transmit) on the FTDI board should be connected to RX (receive) on the printer. Likewise, RX (receive) on the FTDI board should be connected to TX (transmit) on the printer.

See this tutorial for an example with further explanation: https://www.sparkfun.com/tutorials/224

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top