mitsubishi fx1s-20mr-ds newbies

S

Thread Starter

sun919

hi there,
is it possible to communicate this plc with java language? if it is possible how do i go about it? i know that i should use java comm but do i need to have a serial cable and connected to input terminal of plc in order to get data sending from the pc (in java) to plc cause it is not possible to send data from pc using the programming port. Or is it possible? if it is possible then how? here is my java code that use to recieve and transfering data
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();
}
}

many thanks
sun
 
Top