Show TOC Start of Content Area

This graphic is explained in the accompanying textSoft Trigger  Locate the document in its SAP Library structure

This example shows how to use and activate the soft trigger. The program does as explained below:

Caution

This example assumes that at least one driver has been installed. It also assumes this driver supports all the attributes that are being used.

...

       1.      Implements the constructor for the class. It opens a connection to the scanner in scan aware mode, activates the Code 39 symbology, and sets an event listener.

       2.      Implements the onError method from ScannerListener.

       3.      Implements the onDataReceived method from ScannerListener.

       4.      Declares and implements a method called scanBarcode. This method starts the scanning engine, turns on the soft trigger, waits for the application to read a barcode, and stops the scanning engine.

       5.      Declares and implements the close method. It closes the connection to the scanner.

       6.      Creates an instance of the class.

       7.      Scans a barcode.

       8.      Closes the connection to the scanner.

 

package scanner_api_examples;

 

import com.sap.ip.me.api.pios.PIOSException;

import com.sap.ip.me.api.pios.connection.*;

import com.sap.ip.me.api.pios.scanner.*;

import com.sap.ip.me.api.pios.symbology.*;

 

public class SoftTrigger implements ScannerListener {

 

   private ScannerConnection scannerConnection = null;

   private boolean barcodeScanned = false;

   private Exception lastException = null;

   public static final boolean ON = true;

 

   //-----------------------(1)-----------------------

   public SoftTrigger() throws PIOSException {

      Connector connector = Connector.getInstance();

      DriverInfo[] scanners = connector.listDrivers(ConnectionType.SCANNER);

      ScannerParameters parameters = new ScannerParameters(scanners[0]);

      parameters.setMode(ScannerParameters.SCAN_AWARE);

      scannerConnection = (ScannerConnection) connector.open(parameters);

      scannerConnection.addSymbology(new Code39(Code39.FULLASCII));

      scannerConnection.setEventListener(this);

   }

 

   //-----------------------(2)-----------------------

   public void onError(ScannerException e) {

      lastException = e;

      barcodeScanned = true;

   }

 

   //-----------------------(3)-----------------------

   public void onDataReceived(ScannerData scannerData) {

      try {

         System.out.println(

            "Data = " + new String(scannerData.toByteArray(), "ASCII"));

      } catch (Exception ex) {

         lastException = ex;

      }

      barcodeScanned = true;

   }

 

   //-----------------------(4)-----------------------

   public void scanBarcode() throws Exception {

      scannerConnection.startRead();

      scannerConnection.setSoftTrigger(ON);

     

      while (!barcodeScanned) {

         Thread.sleep(500);

      }

     

      if (lastException != null) {

         throw lastException;

      }

     

      scannerConnection.endRead();

      barcodeScanned = false;

   }

 

   //-----------------------(5)-----------------------

   public void close() {

      try {

         scannerConnection.close();

      } catch (Exception ex) {

         ex.printStackTrace();

      }

   }

 

   public static void main(String[] args) {

      SoftTrigger softTriggerExample = null;

 

      try {

         //-----------------------(6)-----------------------

         softTriggerExample = new SoftTrigger();

 

         //-----------------------(7)-----------------------

         softTriggerExample.scanBarcode();

 

      } catch (Exception ex) {

         ex.printStackTrace();

      } finally {

         //-----------------------(8)-----------------------

         softTriggerExample.close();

      }

   }

}

 

End of Content Area