4 Replies Latest reply on Dec 3, 2018 12:47 PM by Robin West

    Sample code for VB.net to print to zt230 via usb

    John Lee

      Do you have an updated version of the sample code on the link:

      https://support.zebra.com/cpws/docs/zpl/zpl_elp_vbnet.htm

       

      The following lines of code no longer work. The FileStream now needs a SaveFileHandle instead of

      a the file handle created by the CreateFile (this is what is reported by VS2008.)

       

      hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)

      hPortP = New IntPtr(hPort) 'convert Integer to IntPtr

      outFile = New FileStream(hPortP, FileAccess.Write, False) 'Create FileStream using Handle

       

      I can not figure out how to correct the sample code in the link but it is exactly what I need to do. I need to write

      the ZPL directly to the printer. We have a ZT230/USB and it is installed and working with ZebraDesigner. I just

      need to learn how to send the ZPL from my VB.Net app. I would imagine this is a very common requirement, so any samples would

      be greatly appreciated. I need to also mention that I must work in .Net version 2-3 due to other limitations in the application.

       

      Thanks,

      John

        • Re: Sample code for VB.net to print to zt230 via usb
          John Lee

          Someone mentioned using the SDK. Is it compatible with VS2008, x86 and .Net 3.5?

          This seems such an simple request and I would think Zebra would want to make it easy for developers to embed their printers in projects so why not a simple Hello World example?

            • Re: Sample code for VB.net to print to zt230 via usb
              Robin West

              Hi John,

              Thanks for making us aware that tho old sample doesn't work for you.  We are sorry for the inconvenience. 

              I think The Link-OS SDK is compatible with x86 (not tested), but it is minimum of .NET 4.7 unfortunately. 

              There are several other methods to work with USB printers in older versions of .NET and OS.  Are you printing primarily images or do you have ZPL?  Do you need to get any information back from the printer?  There are several options using the standard PrintDocument class or the spooler to work with Zebra printers. 

              Otherwise making a direct connection to the printer with USB is complicated as the sample code shows. Is the version of VS, Windows, and .NET framework what it isn't working on?  Have you tried any other versions of VS or Windows?  Did it used to work for you before?  I'm asking because there is no way for us to get the exact same system you have and I'm trying to figure out what the factor is to get you code that might work.

              Robin

                • Re: Sample code for VB.net to print to zt230 via usb
                  John Lee

                  I believe the old sample code is correct but needs to be updated to use safe handles not the old file handles. But in the end it was just too complicated for such an easy task (I am sending ZPL and do not need info back from the printer,  I just want to print a label!) so I just used the serial interface. I am disappointed that Zebra does not provide a sample based on the code used in your ZebraDesigner. That would be perfect and since you developed the designer code it should be easy to have one of your developers provide a simple code snippet just to send the simple commands of the original sample. I actually used the designer to create the label then printed to a file to get the underlying ZPL code. That is a great tool.

                   

                  Thanks,

                  John

                    • Re: Sample code for VB.net to print to zt230 via usb
                      Robin West

                      Hi John,

                      Thanks for the update and feedback.  As a note, the ZebraDesigner does not open direct USB connections to the printer, but uses the Windows drivers.  Direct USB communication is complicated on Windows which is why so many USB devices have used drivers over the years. I'm not saying it's right, but that it is difficult to maintain code that requires so much work to figure out underlying Windows issues.  Most developers who just need basic printing use the drivers or the SDKs.

                      I am sorry we don't have what you were looking for.  We will look into updating the code to use the new Windows safe file handles.

                      Robin