1

I've been tasked with establishing a USB connection which I can use to send and receive data. More specifically, I need to send ZPL commands to a Zebra Label Printer ZD421 and the whole process needs to be done in C#.

I looked at around 10 different stackoverflow questions, which sadly did not help me much.

I first tried searching if an out of the box solution exists.

I tried the following nugets: Zebra.Printer.Sdk, LibUsbDotNet, Usb.Net

The newest update from Zebra uses MAUI, which is not compatible with my other projects. The 2.14 updates are too old and thus also not compatible. The 2.15 versions have the wrong docs, but through the Class View in Visual Studio I saw that there is no UsbDiscoverer.

LibUsbDotNet simply did not want to work, even though I looked at working examples, I did not get it to work.

Usb.Net is what I imagine could probably work? But I think I'm missing something. I tried looking through the documentation but I was none the wiser. I wanted to create an UsbDevice like this:

GetUsbInterfaceManager getUsbInterfaceManager = null;
CancellationToken cancellationToken = new CancellationToken();
IUsbInterfaceManager usbInterfaceManager = await getUsbInterfaceManager(comm.SelectedPrinterDevice.GetPropertyValue("DeviceID").ToString(), cancellationToken);
UsbDevice usbDevice = new UsbDevice(comm.SelectedPrinterDevice.GetPropertyValue("DeviceID").ToString(), (IUsbInterfaceManager)usbInterfaceManager);

But this is obviously wrong, because getUsbInterfaceManager is still null at line 3. I still don't know how to instantiate a GetUsbInterfaceManager. But I believe as it is a delegate, I need to implement it myself? Apparently I need that to get the IUsbInterfaceManager?

Apparently the Usb.Net docs are also out of date and I'm more confused by the minute it seems.

The only thing that worked at all was the System.Management, with which I was able to list all Zebra Printers that are currently connected.

I'd appreciate any help a lot.

8
  • Please add the model number of the printer to your post. Commented Jul 19, 2024 at 13:56
  • The following may be of interest: stackoverflow.com/questions/36803821/… Commented Jul 19, 2024 at 14:02
  • Why are you not just simply using the printer API from Windows itself!? Commented Jul 30, 2024 at 12:48
  • @user246821 that looked informative, but I did not quite wanted to reinvent the wheel. I wanted to search for a simple solution, which did not exist. So I just settled with newest nuget from zebra, which forces me to use target framework net8.0-windows10.0.1904. Commented Aug 8, 2024 at 12:53
  • @DelphiCoder I didn't look at that, but I would guess that this API does not help me manage USB connection easily or atleast it's not possible with a single line of code. Commented Aug 8, 2024 at 12:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.