How to listen for USB Alerts

// Expert user has replied. //Solved
S SDK NDD 11 months 3 weeks ago
138 7 1

Hi,

 

We are implementing a feature to retrieve Alerts from Zebra Printer Link-OS devices, such as ZT231, via USB.

I found the class PrinterAlert in the PC-Java SDK that has a constructor that you can pass various settings about how the Alert will be sent, for example:

PrinterAlert myPrinterAlert = new PrinterAlert(AlertCondition.PAPER_OUT, AlertDestination.USB, true, false, , , false);

and then later you can pass this alert to be configured on the printer calling "ZebraPrinterLinkOs.configureAlert(myPrinterAlert );"

Until that part we found explained on the documentation.

 

What we couldn't understand is how to listen for the incoming alerts at the other end via USB.

 

Do you have any sample code that show us how that is meant to work?

 

Best regards,

Please Register or Login to post a reply

Accepted Solution

S Steven Si

We don't have sample code on how to receive alerts. For USB, however, you would have to create a USB connection with the API from the Link-OS SDK, and then monitor the alerts sent from the printer over USB (i.e., reading from the USB connection (i.e., connection.read()) in a loop) to receive alerts. 

7 Replies

S Steven Si

We don't have sample code on how to receive alerts. For USB, however, you would have to create a USB connection with the API from the Link-OS SDK, and then monitor the alerts sent from the printer over USB (i.e., reading from the USB connection (i.e., connection.read()) in a loop) to receive alerts. 

S SDK NDD

Hi,
 

I will try using the connection.read() loop.

 

About configuring the Alert, how do we set up the PrinterAlert constructor to configure for a USB connection?
 

I tried the way below but it did not work, maybe I am passing incorrect values to the constructor?


PrinterAlert  alert = new PrinterAlert(AlertCondition.HEAD_OPEN, AlertDestination.USB, false, false, "", 0, false);
 

I suspect of parameters 5 and 6. 

Parameter 5 asks for a String for destinationAddress and parameter 6 for an Int for Port, but we are not sure if this is right since it is a USB connection.

 


Best regards,

S Steven Si

The parameters for the IP address and the port number will be ignored if the alert destination is USB. If you want to get alerts for the HEAD OPEN on set and on clear, you will need to pass true to the onSet and onClear parameter (as shown below)

// Define the alert to monitor
PrinterAlert  alert = new PrinterAlert(AlertCondition.HEAD_OPEN, AlertDestination.USB, true, true, "", 0, false);

// Configure the printer with the defined alert
printer.configureAlert(alert);
S SDK NDD

Hi Steven,

 

I am trying to run the code below on a ZD230 like this:

 

    public static void ConfigureAlerts(DiscoveredPrinterDriver printer) {
       Connection connection = null;
       try {
           connection = printer.getConnection();
           connection.open();
           ZebraPrinter genericPrinter = ZebraPrinterFactory.getInstance(connection);
           ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.createLinkOsPrinter(genericPrinter);
           
           PrinterAlert alert = new PrinterAlert(AlertCondition.HEAD_OPEN, AlertDestination.USB, true, true, "", 0, false);
           linkOsPrinter.configureAlert(alert);
       } catch (Exception e) {
           logMessage("Error " + e.getMessage());
       } finally {
            connection.close();             
       }
   }

 

but its giving the following error:

 Cannot invoke "com.zebra.sdk.printer.ZebraPrinterLinkOs.configureAlert(com.zebra.sdk.printer.PrinterAlert)" because "linkOsPrinter" is null

 

Running the same code in a ZT231 works as normal, do you know why is that?

 

Best regards.

S Steven Si

The ZD230 is not a Link-OS printer. It's a Link-OS Basic printer. The following statement is only applicable to Link-OS printers. If it used for a non Link-OS printer or a Link-OS Basic printer, a null pointer will be returned.

ZebraPrinterLinkOs linkOsPrinter = ZebraPrinterFactory.createLinkOsPrinter(genericPrinter);
S SDK NDD

Does this mean that Link-OS Basic printers do not have the Alerts system that can be captured? or does this mean that for getting the alerts from that device we can't use the above code and therefore if we want to configure and listen for alerts for this device, we need to use other methods? like connecting the printer via network and accessing the MIB?

S Steven Si

Alerts are supported on both Link-OS and Link-OS Basic printers. With Link-OS Basic printers, we have to stick with the ZebraPrinter instance to communicate with the printer, as we cannot use the ZebraPrinterLinkOs instance. Unlike the ZebraPrinterLinkOs, which has convenient alert methods, the alert configuration with the ZebraPrinter instance can be done via the SGD commands.

CONTACT
Can’t find what you’re looking for?