1

I'm trying to connect my laptop to a thermal printer from Sparkfun through an FTDI Basic board using C#. 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'm a complete noob so apologies for oversimplifications or grand oversights!

Thanks, Fionn

fionntom
  • 13
  • 4
  • 2
    Are you running under Windows or Mono under Linux? The `/dev/tty.usbserial-AD025HP0` will only work under Linux. – PeterJ Aug 28 '13 at 11:03
  • Post links to images and we'll attach them. – AndrejaKo Aug 28 '13 at 11:24
  • Also do you have any links to the printer itself? Any documentation on its protocol? It's bit strange to me that the printer isn't sending anything back. – AndrejaKo Aug 28 '13 at 11:26
  • Hi guys. Thanks for quick replies. Running mono under mac. Got the serial path from Arduino. This is the printer manual: https://www.sparkfun.com/datasheets/Components/General/A2-user%20manual-1.pdf. Will post links to images shortly. – fionntom Aug 28 '13 at 12:03
  • Public dropbox link here: http://db.tt/7bI6piom - goes straight to download – fionntom Aug 28 '13 at 12:16

1 Answers1

1

Your RX and TX are flipped. They are always with respect to the device they are connected to. RXI <=- Rx Input comes from TX output of your printer.

Try swapping RX/TX on either the FTDI or printer side (But not both!) and retry.

HL-SDK
  • 2,539
  • 1
  • 19
  • 26