We have a Zebra QLn420 label printer and I am writing a .Net application to allow the user to scan an item, process it through our system, create a shipping label, then send it in a .ZPL file to the Zebra label printer. Where I'm running into trouble is getting the VB.Net application connected to the Zebra label printer.

The application is run on a wearable Motorola WT41N0 wearable terminal, and the terminal is connected to the printer through Bluetooth. I can see on the terminal the two devices are indeed connected, the port it is connected through (COM9), and the baud rate (57600).

This is a new experience for me, so forgive me for missing anything obvious, but here is the code I am currently using to connect.

Try
    PrinterSerial = New IO.Ports.SerialPort(Portname, 57600, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)
    AddHandler PrinterSerial.DataReceived, AddressOf getPrinterSerialData
    PrinterSerial.Open()
Catch ex as Exception
    MsgBox(ex.tostring)
End Try

The error is occurring on the PrinterSerial.Open() line with the error "The port 'COM9' does not exist.'

Any suggestions or thoughts would be very helpful. Thank you!

Dani AI

Generated

, the core issue is scope: your VB.NET code runs on the Windows Server session, so it only sees COM ports that exist in that session. The Bluetooth SPP port (COM9) lives on the handheld, not the server. Unless the RDP client redirects that local COM port into the remote session, SerialPort.Open("COM9") on the server will fail. You can quickly confirm whether any client COM ports are redirected by running chgport inside the remote session; redirected ports show up as RdpDrPort entries. Also note that Microsoft supports COM redirection only from supported Windows clients, and it must be enabled via policy/rdp properties; many CE/WEH RDP clients simply do not implement it. (learn.microsoft.com)

Given that, the most reliable path (as hinted) is to bypass Bluetooth and print over the network. Zebra printers accept raw ZPL over TCP port 9100 by default. Put the QLn420 on Wi‑Fi, give it an IP, and send the ZPL directly from your server app, avoiding the Windows print spooler. Example VB.NET:

Imports System.Net.Sockets
Imports System.Text
Using client As New TcpClient()
    client.Connect("PRINTER_IP", 9100) ' RAW socket
    Dim zpl As String = IO.File.ReadAllText("C:\labels\ship.zpl", Encoding.ASCII)
    Dim bytes = Encoding.ASCII.GetBytes(zpl)
    client.GetStream().Write(bytes, 0, bytes.Length)
End Using

Port 9100 is the printer’s raw print port and is the documented default on Zebra devices. Ensure each label starts with ^XA and ends with ^XZ. (docs.zebra.com)

If you must stay on Bluetooth, run the print component on the handheld so it can write to its local COM9, or use Zebra’s Link‑OS SDK for Windows Mobile/CE to talk Bluetooth directly from the device. If you insist on server‑side printing over RDP, you would need working COM redirection and redirectcomports:i:1 enabled, understanding client support varies and may not exist on CE handhelds. (developer.zebra.com)

Recommended Answers

All 11 Replies

Are you sure it's connected through "COM9"? (devices and printers >> printer properties >> ports), if yes then add this code before opening the serial port

PrinterSerial.DtrEnable = True
PrinterSerial.RtsEnable = True

Reference : Click Here

I added the code and I am still receiving the same error. I'm beginning to think this may not work as intended...the printer is connected through bluetooth via the terminal, and the terminal is remotely connected to our Windows 2012 server where the app resides. Would it be possible that the "COM9" port that the printer is connected to on the terminal is not the same "COM9" the app is looking for (IE: the app is trying to connect to "COM9" on the app server instead of "COM9" on the terminal)? If so, is there a way to get around this?

Thank you, but unfortunately I'm unable to link that to my issue. It would seem the main issue has become that I need to be able to see the "COM9" port that the wearble terminal is connected to the wireless printer too through bluetooth from the server where the application actually resides. It seems as though when trying to open "COM9", the application is looking to open "COM9" on the app server, which is NOT where the printer is connected to.

Btw what is your portname in runtime? (msgbox(portname))

My apologies, the variable Portname contains the string "COM9"

Ok so you are assuming it's COM9, to be sure add this code and tell me what happens

dim List As New ListBox
List.items.addRange(IO.Ports.SerialPort.GetPortNames)
for each item In List.Items
msgBox(item)
next

As suspected, it is only pulling the COM ports for the server and not for the wearable terminal running the application. Listing all the ports with the code you so kindly posted above only yielded "COM1", and no other results. I can plainly see that "COM9" is the port on the wearable terminal that the printer is connected to, but obviously the server that I am connecting to remotely is not pulling that information.

Is there anyway to access the COM ports on the wearable terminal while remotely connected to the server? Even so, there will be 8 of these wearable terminals with different user logins all running the same application, there would need to be some way to differentiate "COM9" for user 1 from user 2.

Since your printer is on a network and inaccessible through ports you are left with one option, you should target the ip address of that printer so don't use a serialport because you can't assign a printer's ip as a portname.
I highly recommend you to read the link cgeier gave, your answer is there.
gd luck.

I can do it through an IP address over our wireless connection from the wearable to the wireless printer, but we were hoping to find some way to allow us to utilize the bluetooth connection. I suppose that using the IP address is the best/only way to go at this point if there is no way for the remote desktop session to pass the devices connected to it to the server when logging in. Thanks for you help, it is much appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.