Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3480
  • Last Modified:

Printing Zebra ZPL direct to COM1

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.

  • 3
  • 2
1 Solution
uh? you are printer serial now? before you were printing on LPT1

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
.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: http://msdn.microsoft.com/msdnmag/issues/02/10/netserialcomm/
   In C++, this article may be usefull: http://www.codeproject.com/system/chaiyasit_t.asp

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

lawrmcAuthor Commented:
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?
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

lawrmcAuthor Commented:
That works fine. I can print the template label from Vb.net. 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.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now