Printing Zebra ZPL direct to COM1

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

lawrmcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PockyMasterCommented:
uh? you are printer serial now? before you were printing on LPT1
0
PockyMasterCommented:


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
                'found
                Try
                    Dim sp As Ports.SerialPort = My.Computer.Ports.OpenSerialPort(COMPort)

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

                    sp.Close()

                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
                Exit For
            End If
        Next


    End Function
0
PigtorCommented:
.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.
   http://www.commstudio.com/CommStudio/SerialPorts.aspx
   

   
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

lawrmcAuthor Commented:
PockyMaster,
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?
0
PockyMasterCommented:
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()
tr.Close()

pass these filecontents to the modified function

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.