|
|
|
|
Re: how to get weight in oracle forms from weighment machine [message #334360 is a reply to message #334344] |
Wed, 16 July 2008 05:11   |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
How is this machine connected to your workstation?
How can you get data in other applications? For example, can you see the data in Notepad or vi?
Barcode-scanners work like a keyboard when attached to a computer; I can't tell from your exhaustive problem description how your machine works.
|
|
|
|
|
Re: how to get weight in oracle forms from weighment machine [message #334473 is a reply to message #334441] |
Wed, 16 July 2008 12:10   |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
goharshamke@yahoo.com wrote on Wed, 16 July 2008 16:03 | there is weighment scale which shows weight of vehicles on its own screen. I want to get this weight into my oracle forms application.
|
You are not a developer, are you? No problem if you are not, but better tell that upfront because the answers you might get would differ.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: how to get weight in oracle forms from weighment machine [message #541056 is a reply to message #540891] |
Fri, 27 January 2012 06:07   |
owais_baba
Messages: 289 Registered: March 2008 Location: MUSCAT
|
Senior Member |
|
|
that's good but its better just embedded java code
Most projects that deal with hardware and devices, needs to communicate with them using the COM port of the PC or Server. For example if there is a modem that is connected to a server via its COM port and the Java program has to read the output of the modem then the Java program has to read the COM port for any incoming data.
This sample Java program can be used to Read from a COM port for incoming data and process it. Note that you will need to change the Port number to COM1 or COM2 or any other ports as required.
import java.io.*;
import java.util.*;
import javax.comm.*;
public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM1")) {
// if (portId.getName().equals("/dev/term/a")) {
SimpleRead reader = new SimpleRead();
}
}
}
}
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {System.out.println(e);}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {System.out.println(e);}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {System.out.println(e);}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {System.out.println(e);}
readThread = new Thread(this);
readThread.start();
}
public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {System.out.println(e);}
}
public void serialEvent(SerialPortEvent event) {
switch(event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {System.out.println(e);}
break;
}
}
}
---------------------------END---------------------
-----------------------------SERIAL COMMUNICATION---------------
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.HashMap;
import javax.comm.CommPort;
import javax.comm.CommPortIdentifier;
import javax.comm.NoSuchPortException;
import javax.comm.ParallelPort;
import javax.comm.PortInUseException;
import javax.comm.SerialPort;
import javax.comm.UnsupportedCommOperationException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* Open a serial port using Java Communications.
*
* @author Ian F. Darwin, http://www.darwinsys.com/
*/
public class CommPortOpen {
/** How long to wait for the open to finish up. */
public static final int TIMEOUTSECONDS = 30;
/** The baud rate to use. */
public static final int BAUD = 19200;
/** The parent JFrame, for the chooser. */
protected JFrame parent;
/** The input stream */
protected BufferedReader is;
/** The output stream */
protected PrintStream os;
/** The chosen Port Identifier */
CommPortIdentifier thePortID;
/** The chosen Port itself */
CommPort thePort;
public static void main(String[] argv)
throws IOException, NoSuchPortException, PortInUseException,
UnsupportedCommOperationException {
new CommPortOpen(null).converse();
System.exit(0);
}
/* Constructor */
public CommPortOpen(JFrame f)
throws IOException, NoSuchPortException, PortInUseException,
UnsupportedCommOperationException {
// Use the PortChooser from before. Pop up the JDialog.
PortChooser chooser = new PortChooser(null);
String portName = null;
do {
chooser.setVisible(true);
// Dialog done. Get the port name.
portName = chooser.getSelectedName();
if (portName == null)
System.out.println("No port selected. Try again.\n");
} while (portName == null);
// Get the CommPortIdentifier.
thePortID = chooser.getSelectedIdentifier();
// Now actually open the port.
// This form of openPort takes an Application Name and a timeout.
//
System.out.println("Trying to open " + thePortID.getName() + "...");
switch (thePortID.getPortType()) {
case CommPortIdentifier.PORT_SERIAL:
thePort = thePortID.open("DarwinSys DataComm",
TIMEOUTSECONDS * 1000);
SerialPort myPort = (SerialPort) thePort;
// set up the serial port
myPort.setSerialPortParams(BAUD, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
break;
case CommPortIdentifier.PORT_PARALLEL:
thePort = thePortID.open("DarwinSys Printing",
TIMEOUTSECONDS * 1000);
ParallelPort pPort = (ParallelPort)thePort;
// Tell API to pick "best available mode" - can fail!
// myPort.setMode(ParallelPort.LPT_MODE_ANY);
// Print what the mode is
int mode = pPort.getMode();
switch (mode) {
case ParallelPort.LPT_MODE_ECP:
System.out.println("Mode is: ECP");
break;
case ParallelPort.LPT_MODE_EPP:
System.out.println("Mode is: EPP");
break;
case ParallelPort.LPT_MODE_NIBBLE:
System.out.println("Mode is: Nibble Mode.");
break;
case ParallelPort.LPT_MODE_PS2:
System.out.println("Mode is: Byte mode.");
break;
case ParallelPort.LPT_MODE_SPP:
System.out.println("Mode is: Compatibility mode.");
break;
// ParallelPort.LPT_MODE_ANY is a "set only" mode;
// tells the API to pick "best mode"; will report the
// actual mode it selected.
default:
throw new IllegalStateException("Parallel mode " +
mode + " invalid.");
}
break;
default: // Neither parallel nor serial??
throw new IllegalStateException("Unknown port type " + thePortID);
}
// Get the input and output streams
// Printers can be write-only
try {
is = new BufferedReader(new InputStreamReader(thePort.getInputStream()));
} catch (IOException e) {
System.err.println("Can't open input stream: write-only");
is = null;
}
os = new PrintStream(thePort.getOutputStream(), true);
}
/** This method will be overridden by non-trivial subclasses
* to hold a conversation.
*/
protected void converse() throws IOException {
System.out.println("Ready to read and write port.");
// Input/Output code not written -- must subclass.
// Finally, clean up.
if (is != null)
is.close();
os.close();
}
}
class PortChooser extends JDialog implements ItemListener {
/** A mapping from names to CommPortIdentifiers. */
protected HashMap map = new HashMap();
/** The name of the choice the user made. */
protected String selectedPortName;
/** The CommPortIdentifier the user chose. */
protected CommPortIdentifier selectedPortIdentifier;
/** The JComboBox for serial ports */
protected JComboBox serialPortsChoice;
/** The JComboBox for parallel ports */
protected JComboBox parallelPortsChoice;
/** The JComboBox for anything else */
protected JComboBox other;
/** The SerialPort object */
protected SerialPort ttya;
/** To display the chosen */
protected JLabel choice;
/** Padding in the GUI */
protected final int PAD = 5;
/** This will be called from either of the JComboBoxen when the
* user selects any given item.
*/
public void itemStateChanged(ItemEvent e) {
// Get the name
selectedPortName = (String)((JComboBox)e.getSource()).getSelectedItem();
// Get the given CommPortIdentifier
selectedPortIdentifier = (CommPortIdentifier)map.get(selectedPortName);
// Display the name.
choice.setText(selectedPortName);
}
/* The public "getter" to retrieve the chosen port by name. */
public String getSelectedName() {
return selectedPortName;
}
/* The public "getter" to retrieve the selection by CommPortIdentifier. */
public CommPortIdentifier getSelectedIdentifier() {
return selectedPortIdentifier;
}
/** A test program to show up this chooser. */
public static void main(String[] ap) {
PortChooser c = new PortChooser(null);
c.setVisible(true); // blocking wait
System.out.println("You chose " + c.getSelectedName() +
" (known by " + c.getSelectedIdentifier() + ").");
System.exit(0);
}
/** Construct a PortChooser --make the GUI and populate the ComboBoxes.
*/
public PortChooser(JFrame parent) {
super(parent, "Port Chooser", true);
makeGUI();
populate();
finishGUI();
}
/** Build the GUI. You can ignore this for now if you have not
* yet worked through the GUI chapter. Your mileage may vary.
*/
protected void makeGUI() {
Container cp = getContentPane();
JPanel centerPanel = new JPanel();
cp.add(BorderLayout.CENTER, centerPanel);
centerPanel.setLayout(new GridLayout(0,2, PAD, PAD));
centerPanel.add(new JLabel("Serial Ports", JLabel.RIGHT));
serialPortsChoice = new JComboBox();
centerPanel.add(serialPortsChoice);
serialPortsChoice.setEnabled(false);
centerPanel.add(new JLabel("Parallel Ports", JLabel.RIGHT));
parallelPortsChoice = new JComboBox();
centerPanel.add(parallelPortsChoice);
parallelPortsChoice.setEnabled(false);
centerPanel.add(new JLabel("Unknown Ports", JLabel.RIGHT));
other = new JComboBox();
centerPanel.add(other);
other.setEnabled(false);
centerPanel.add(new JLabel("Your choice:", JLabel.RIGHT));
centerPanel.add(choice = new JLabel());
JButton okButton;
cp.add(BorderLayout.SOUTH, okButton = new JButton("OK"));
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PortChooser.this.dispose();
}
});
}
/** Populate the ComboBoxes by asking the Java Communications API
* what ports it has. Since the initial information comes from
* a Properties file, it may not exactly reflect your hardware.
*/
protected void populate() {
// get list of ports available on this particular computer,
// by calling static method in CommPortIdentifier.
Enumeration pList = CommPortIdentifier.getPortIdentifiers();
// Process the list, putting serial and parallel into ComboBoxes
while (pList.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier)pList.nextElement();
// System.out.println("Port " + cpi.getName());
map.put(cpi.getName(), cpi);
if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
serialPortsChoice.setEnabled(true);
serialPortsChoice.addItem(cpi.getName());
} else if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
parallelPortsChoice.setEnabled(true);
parallelPortsChoice.addItem(cpi.getName());
} else {
other.setEnabled(true);
other.addItem(cpi.getName());
}
}
serialPortsChoice.setSelectedIndex(-1);
parallelPortsChoice.setSelectedIndex(-1);
}
protected void finishGUI() {
serialPortsChoice.addItemListener(this);
parallelPortsChoice.addItemListener(this);
other.addItemListener(this);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
|
|
|
|
|
|
|
Re: how to get weight in oracle forms from weighment machine [message #541444 is a reply to message #541144] |
Tue, 31 January 2012 06:40   |
owais_baba
Messages: 289 Registered: March 2008 Location: MUSCAT
|
Senior Member |
|
|
this java with API
package msr;
/**
*
* @author Dell
*/
import java.io.*;
import java.util.*;
import javax.comm.*;
/**
* Class declaration
*
*
* @author
* @version 1.8, 08/03/00
*/
public class SimpleRead implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;
InputStream inputStream;
SerialPort serialPort;
Thread readThread;
/**
* Method declaration
*
*
* @param args
*
* @see
*/
public static void main(String[] args) {
boolean portFound = false;
String defaultPort = "COM3";
if (args.length > 0) {
defaultPort = args[0];
}
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals(defaultPort)) {
System.out.println("Found port: "+defaultPort);
portFound = true;
SimpleRead reader = new SimpleRead();
}
}
}
if (!portFound) {
System.out.println("port " + defaultPort + " not found.");
}
}
/**
* Constructor declaration
*
*
* @see
*/
public SimpleRead() {
try {
serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
} catch (PortInUseException e) {}
try {
inputStream = serialPort.getInputStream();
} catch (IOException e) {}
try {
serialPort.addEventListener(this);
} catch (TooManyListenersException e) {}
serialPort.notifyOnDataAvailable(true);
try {
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
readThread = new Thread(this);
readThread.start();
}
/**
* Method declaration
*
*
* @see
*/
public void run() {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {}
}
/**
* Method declaration
*
*
* @param event
*
* @see
*/
public void serialEvent(SerialPortEvent event) {
switch (event.getEventType()) {
case SerialPortEvent.BI:
case SerialPortEvent.OE:
case SerialPortEvent.FE:
case SerialPortEvent.PE:
case SerialPortEvent.CD:
case SerialPortEvent.CTS:
case SerialPortEvent.DSR:
case SerialPortEvent.RI:
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
} catch (IOException e) {}
break;
}
}
}
hope this will help u
|
|
|
|
|
|
|
|
|