Home » Developer & Programmer » Forms » Serial Communication and Forms
Serial Communication and Forms [message #538077] Tue, 03 January 2012 15:56 Go to next message
Areint
Messages: 9
Registered: February 2010
Location: Iowa
Junior Member
Hey,

Is it possible to communicate with a serial device (via COM1) with oracle forms / webutil? I am able to communicate in java using RXTXcomm, but I am having problems making a bean that uses it (getting security errors and yes, I have signed the jars).

Basically, I have a scale hooked up to my COM1 port and want to be able to send commands (zero and tare) to it and read the weight from it through a form or java bean.

Any help would be greatly appreciated!
Re: Serial Communication and Forms [message #538088 is a reply to message #538077] Tue, 03 January 2012 22:51 Go to previous messageGo to next message
na.vaithianathan
Messages: 6
Registered: November 2007
Junior Member
use MSCOMM control in forms6i
Re: Serial Communication and Forms [message #541350 is a reply to message #538088] Mon, 30 January 2012 14:54 Go to previous messageGo to next message
Areint
Messages: 9
Registered: February 2010
Location: Iowa
Junior Member
Hey,

Thanks for the reply and sorry for the long delay here. Right now we are using Oracle Forms 11g, is this feature still available in it? I've looked into it but haven't really found anything yet.
Re: Serial Communication and Forms [message #541441 is a reply to message #541350] Tue, 31 January 2012 06:19 Go to previous messageGo to next message
owais_baba
Messages: 289
Registered: March 2008
Location: MUSCAT
Senior Member
this is a sample code come with the 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 it will help u
Re: Serial Communication and Forms [message #543292 is a reply to message #541441] Tue, 14 February 2012 00:33 Go to previous messageGo to next message
nthieuutc
Messages: 3
Registered: February 2012
Location: VietNam
Junior Member

How to use this sample! I am new member, so it is difficult for me!
Re: Serial Communication and Forms [message #544554 is a reply to message #543292] Wed, 22 February 2012 07:21 Go to previous message
mughals_king
Messages: 392
Registered: January 2012
Location: pakistan
Senior Member
sorry dear i couldn't see your post anyway here is simple solution to call java class

Oracle Forms 6i
JDK 1.6
With this I managed to create the hello world example:

Configure PATH environment variables:
C:\PATH_TO_JAVA\Java\jdk1.6.0\bin;
C:\PATH_TO_JAVA\Java\jdk1.6.0\jre\bin;
C:\PATH_TO_JAVA\Java\jdk1.6.0\jre\bin\client;
Ex: PATH_TO_JAVA = C:\Program Files

Add to CLASSPATH
FORMS_HOME\TOOLS\common60\JAVA\IMPORTER.JAR (In my case FORMS_HOME was C:\orant)
PATH_TO_YOUR_JAR\NAME_OF_JAR.jar

Create Java Program
1.Create with your IDE a simple java program, following is mine:
public class HolaMundo {
  private String hi= "Hey World!!!";

    public String GetHi(){

     return this.hola;
   }
   public String getMultiply(int a, int b){ 
     return ""+a*b; 
      }
    public static void main(String args[]){
    HiWorldhm = new HiWorld();
    System.out.println(hm.GetHi());
    System.out.println(hm.getMultiply(5,10));
     }
    } 


2.Export it to Jar file (Path has to be the one you put in CLASSPATH environment variable.

Import the classes to Forms
Create a new project in Oracle Forms and also create a Canvas, in the canvas use a Text and a Button. The name of the button:

TEXT_HI_WORLD.

Following click on the Menu: Program > Import Java Classes

If everything went Ok then there will be a new window that will show you the package where the Class is, you extend it until there is the HiWorld class. Import it.

In Program Unit now there will be two files:

HIWORLD (Specification)
HIWORLD (Body)
This are files generated automatically and needed to use the class.

Then go back to the canvas, right click on the Button and select the Thrigger WHEN-BUTTON-PRESSED, the programming of this will be:
  DECLARE 
      v_wb      ORA_JAVA.JOBJECT;
      v_hi      VARCHAR2(20);
  BEGIN v_wb := hiworld.new();
      v_hi:= hiworld.getHi(v_wb);
     :TEXT_HI_WORLD := v_hi
 END;

Now execute the program and click on the button! Smile

Hope this helps Java programmers with no much of knowledge on Forms to integrate with legacy systems! Very Happy

[Updated on: Wed, 22 February 2012 07:25]

Report message to a moderator

Previous Topic: validate-from-list propery
Next Topic: How to Disable Function key F4 in forms 6i
Goto Forum:
  


Current Time: Fri Sep 06 15:12:59 CDT 2024