Sign in to follow this  
Followers 0
Pankaj Jangid

Java PLC communication over USB-to-RS232

2 posts in this topic

I am trying to communicate with Omron PLC CP1E-N40DR-A over USB-to-RS232 cable, using a Java program. Following is my basic code—


    public void startComm() {
        PrintStream os;
        
try {

            CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM4");
            SerialPort serialPort = (SerialPort) portId.open("MyApp", 2000);
            serialPort.setSerialPortParams(9600, SerialPort.DATABITS_7, SerialPort.STOPBITS_2, SerialPort.PARITY_EVEN);

            os = new PrintStream(serialPort.getOutputStream(), true);


            os.print("@00WD0620007050*");

            os.print("\r");

        } catch (IOException e) {

            e.printStackTrace();

        } catch (PortInUseException e) {
            e.printStackTrace();
        } finally {

            if (os != null) os.close();
        }
    }

This code produces no effect on the DM area. In this code I am trying write “0070” at location “0620”. The connector and its driver are alright because CX-Programmer is working fine using the same cable.

Any pointers for this would certainly help me.

Thanks

Screen Shot 2016-10-03 at 7.55.45 PM.png

Share this post


Link to post
Share on other sites

Are you getting any response from the code by serial port?  The response should tell you what the problem is.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0