Wedge Mode
This example shows how to use the wedge mode. The program does the following:

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 class constructor. It opens a connection to the scanner in wedge mode, starts the scanning engine, and launches a window that receives the scanned data.
2. Declares and implements the cancel method. It calls the closeConnection method and closes the window.
3. Declares and implements the closeConnection method. It stops the scanning engine and closes the connection to the scanner.
4. Calls the class constructor and displays the window.
package scanner_api_examples;
import com.sap.ip.me.api.pios.connection.*;
import com.sap.ip.me.api.pios.scanner.*;
import com.sap.ip.me.api.pios.symbology.*;
import java.awt.*;
import java.awt.event.*;
public class WedgeMode extends Frame {
private ScannerConnection scannerConnection = null;
//-----------------------(1)-----------------------
public WedgeMode() throws Exception {
Connector connector = Connector.getInstance();
DriverInfo[] scanners = connector.listDrivers(ConnectionType.SCANNER);
ScannerParameters parameters = new ScannerParameters(scanners[0]);
parameters.setMode(ScannerParameters.WEDGE);
scannerConnection = (ScannerConnection) connector.open(parameters);
scannerConnection.addSymbology(new Code39(Code39.FULLASCII));
scannerConnection.setPostamble("\t".getBytes());
scannerConnection.startRead();
this.setTitle("Wedge Window");
this.setLayout(new BorderLayout());
this.setSize(new Dimension(240, 265));
this.add(new TextArea());
Button cancel = new Button("Cancel");
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cancel();
}
});
Panel p = new Panel(new FlowLayout());
p.add(cancel);
this.add(p, BorderLayout.SOUTH);
cancel.setBounds(new Rectangle(15, 15));
cancel.repaint();
this.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
this.setLocation(
(screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
}
//-----------------------(2)-----------------------
public void cancel() {
this.closeConnection();
this.dispose();
}
//-----------------------(3)-----------------------
private void closeConnection () {
try {
scannerConnection.endRead();
scannerConnection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
try {
//-----------------------(4)-----------------------
WedgeMode t = new WedgeMode();
t.setVisible(true);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}