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

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

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.

0
lawrmc
Asked:
lawrmc
  • 3
  • 2
1 Solution
 
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
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:
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
 
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

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