Printing Zebra ZPL direct to COM1

Posted on 2006-04-12
Last Modified: 2012-05-05
looking for pointers on how to print Zebra ZPL labels to a Zebra printer through COM1. I have the sample code from the MS KB that opens print dialogues etc, but I am looking to print straight to com1 and send the zpl .txt document to it(if that even works??)
Would appreciate any tips.

Question by:lawrmc
    LVL 14

    Expert Comment

    uh? you are printer serial now? before you were printing on LPT1
    LVL 14

    Expert Comment


    In visual studio 2005 you can try this kind of function
    call like :

    dim myBytes() as Byte
    WriteToSerial ("COM1", myBytes)

    you can also just send text to port, which may be more convenient for you...

     Private Function WriteToSerial(ByVal COMPort As String, ByVal data() As Byte) As Boolean

            For Each port As String In My.Computer.Ports.SerialPortNames
                If port = COMPort Then
                        Dim sp As Ports.SerialPort = My.Computer.Ports.OpenSerialPort(COMPort)

                        sp.Write(data, 0, data.GetLength(0))


                    Catch ex As Exception
                    End Try
                    Exit For
                End If

        End Function
    LVL 3

    Expert Comment

    .NET 2002, 2003 doesn't have classes or components to access the serial ports.  
    If you have this versions of .NET, you have two options:

    1.  Implement a class that reads and writes the serial port using the CreateFile API:
       serial_port = CreateFile(port_name, GENERIC_READ | GENERIC_WRITE,  0, 0, OPEN_EXISTING, 0, 0);
       For .NET, read this articule:
       In C++, this article may be usefull:

    2. Download a component for .NET that reads and writes from the serialport.
       I don't know about free components, but I have used serialcommunications dll and works fine for me.


    Author Comment

    how do I go about getting the ZPL code in the .txt document passed to com1 though. Do I have to convert in some way?
    LVL 14

    Accepted Solution

    Well, as far as I remember, you were writing a textfile first, either don't write it but pass the text as a string to the Serial Port (in my example i put a byte array, but the port also accepts strings) or otherwise read the whole file at once with a streamreader:

    Dim tr As New IO.StreamReader("c:\test.txt")
    Dim sFileContents As String = tr.ReadToEnd()

    pass these filecontents to the modified function


    Author Comment

    That works fine. I can print the template label from My next thing to tackle is how to print the barcode labels and entering the serial numbers scanned by a user.

    I'll open another question for this though.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now