Does any one know how to link java in serial with plc?

S

Thread Starter

sun919

Does anyone know about how to use java serial to communicate with plc? I needed to understand this for my project which is to with controling the output from the java .
thanks a lot
 
J

James Ingraham

Make sure you have the javax.comm package, which is not in the standard JDK download. This will allow you to do serial comm. However, you
will then need to know what kind of data the PLC is expecting. This is pretty easy if it's a Modbus capable PLC, since modbus.org gives you
all the info. DF1 is a little tougher. As for everybody else, you'd have to ask the respective manufacturers.

-James
Sage Automation, Inc.
 
S

Sandeep Shroff

Use the java Comm API library to solve your problem . It also contains several examples which can get you going.

All the best..

Sandeep Shroff
 
thanks james, i have download and written some code for the serialPoerEventListener. Now the problem is that my program is waiting for the
output from plc which can not send to pc at the moment. is there a way to go about it
many thanks
sun
 
M
A windows version of the API is available at the sun site. I think that some one has already given the link. It is quite easy to use, but uses
native methods, though this is largely transparent with the supplied .dll.

For information on the Linux API look here
"http://interstice.com/kevinh/linuxcomm.html":http://interstice.com/kevinh/linuxcomm.html .

Regards
Mark Hutton
Software Engineer
Tel:07092 032237
(telephone + voice and fax messaging www.yac.co.uk)
e-mail: [email protected]
internet: http://www.plcprogrammer.co.uk
 
hi there,
i've program in java already.. would it be ok for u to have a look at since i
get no input signal from plc at all (can u tell me how i can send signal from
plc to pc?) here is my program
public class ReadPorts implements SerialPortEventListener
{
private SerialPort serialp = null;
private static CommPortIdentifier comportiden ;
private InputStream inp ;
private CommPort comp ;
private Enumeration enum ;
private InputStream input = null;
private OutputStream output;
private int invalue, portnum, inputport ;
private DisplayPict2 display ;
private GetScan scan ;



// SerialPort serialPort = null;


public ReadPorts()
{
try
{
String portName = "COM2" ;

comportiden
=CommPortIdentifier.getPortIdentifier(portName);
// System.out.println(
comportiden.getCurrentOwner()) ;
serialp =
(SerialPort)comportiden.open("Download", 1000);
serialp.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,SerialPort.PARITY_NONE );

serialp.addEventListener(this) ;

//scan = new GetScan();
//before need to have getscan class ready
// display = new DisplayPict2("save.jpg") ;
portnum = display.getPortNumber() ;

System.out.println("Port number" + portnum);
System.out.println(serialp.getBaudRate());
System.out.println(serialp.isDSR());




}
catch (Exception e)
{
System.out.println("ERROR");
}
// testRead();

}

public void testRead()
{
try
{
input = serialp.getInputStream();
invalue = input.read() ;

checkDecision() ;
}

catch(Exception e)
{
System.out.println("ERROR WITH INPUT");
}


}

public void checkDecision()
{
if (invalue ==0 )
{
//break ;
}
else if (invalue ==1)
{
//display = new DisplayPict2("picture
name");
portnum = display.getPortNumber();
sendData(portnum) ;
}


}

public void sendData(int i)
{
try
{
output.write(i) ;
}
catch( IOException e)
{
System.out.println("Error writing");
}




}

public void closePorts()
{
try
{
input.close();
output.close();
}
catch( IOException e)
{
System.out.println(" Error closing
port");
}
}


public void serialEvent(SerialPortEvent event)
{

if(event.getEventType()==SerialPortEvent.DATA_AVAILABLE);//DSR)//DATA_AVAILABLE)
{
try
{System.out.println("In the serial");

inputport = input.read();
System.out.println("In the serial");
}
catch(IOException e)
{
System.out.println("error with input data");
}
}
}





public static void main(String args[])
{
ReadPorts e = new ReadPorts();
}
}
 
J

James Ingraham

I didn't really look at the code, because I think you've already figured out that problem is on the PLC side. I don't know which PLC you're using or what it expects or what it sends, so I can't really help with that. I would say that the PLC manufacturer should supply you with all the information you need. On a good day you might even get sample code.

Sorry I can't help more.

-James
Sage Automation, Inc.
 
the plc model is mitsubishi fx1s 20mr-ds
it is expect to send data from java in serial port to plc which is then determine the output channel to be sent ( ie y0-7). Also it suppose
to do the reverse also but this time plc will send the command which tell the program to start reading another input value from java
many thanks
 
Top