Wednesday, February 1, 2023

Contoh Mengakses PLC Dengan Java - III

 


9. Get or set PLC time

import PLCCom.*;

import java.util.Calendar;

import javax.swing.JOptionPane;

 

public class NewClass {

 

    PLCcomDevice Device;

    //see section 'connect' for declare and connect a PLCcom-Device

 

    //read PLC time

    private void btnGetPLCTimeActionPerformed(java.awt.event.ActionEvent evt) {

 

        //execute function

        PLCClockTimeResult res = Device.GetPLCClockTime();

 

        //evaluate results

        if (res.Quality().equals(OperationResult.eQuality.GOOD)) {

            Calendar c = res.getPLCClockTime();

            JOptionPane.showMessageDialog(null, "OK", "", JOptionPane.INFORMATION_MESSAGE);

        } else {

            JOptionPane.showMessageDialog(null, res.Message(), "", JOptionPane.ERROR_MESSAGE);

        }

    }

     

    //set PLC time

    private void btnSetPLCTimeActionPerformed(java.awt.event.ActionEvent evt) {

        Calendar data = new GregorianCalendar();

        //adjust and set hour

        data.set(Calendar.HOUR_OF_DAY, data.get(Calendar.HOUR_OF_DAY) - 0);

        //execute function

        OperationResult res = Device.SetPLCClockTime(data);

 

        //evaluate results

        if (res.Quality().equals(OperationResult.eQuality.GOOD)) {

            JOptionPane.showMessageDialog(null, "OK", "", JOptionPane.INFORMATION_MESSAGE);

        } else {

            JOptionPane.showMessageDialog(null, res.Message(), "", JOptionPane.ERROR_MESSAGE);

        }

    }

     

}


10. Reading system status list SSL

import PLCCom.*;

import javax.swing.JOptionPane;

 

public class NewClass {

 

    PLCcomDevice Device;

    //see section 'connect' for declare and connect a PLCcom-Device

 

        private void btnReadSSL_SZLActionPerformed(java.awt.event.ActionEvent evt) {

 

        // important!!! please search the id and index information in the plc-documentation

        // You must convert the specified values hex in decimal

        int SSL_ID = 306; //ID 132 (Hex)

        int SSL_Index = 4; //Index 4 (Hex)

        //execute function

        SystemStatusListResult res = Device.GetSystemStatusList(SSL_ID, SSL_Index);

 

        //evaluate results

        if (res.Quality().equals(OperationResult.eQuality.GOOD)) {

            StringBuilder sb = new StringBuilder();

            for (SystemStatusListItemEntry ssle : res.getSZLItemEntrys()) {

                for (byte b : ssle.getBuffer()) {

                    sb.append(String.valueOf(b));

                    sb.append(" ");

                }

                sb.append(System.getProperty("line.separator"));

            }

        JOptionPane.showMessageDialog(null, "OK", "", JOptionPane.INFORMATION_MESSAGE);

        } else {

            JOptionPane.showMessageDialog(null, res.Message(), "", JOptionPane.ERROR_MESSAGE);

        }

    }

}


11. Get diagnostic data

import PLCCom.*;

import javax.swing.JOptionPane;

 

public class NewClass {

 

    PLCcomDevice Device;

    //see section 'connect' for declare and connect a PLCcom-Device

 

    private void btnDiagnoseBufferActionPerformed(java.awt.event.ActionEvent evt) {

 

        //read the diagnosticinfo into DiagnosticInfoResult-object

        //execute function

        DiagnosticInfoResult res = Device.GetDiagnosticInfo();

 

        //evaluate results

        if (res.Quality().equals(OperationResult.eQuality.GOOD)) {

            //step through the entries

            StringBuilder sb = new StringBuilder();

            for (DiagnosticInfoEntry myDiagnosticInfoEntry : res.getDiagnosticInfoEntrys()) {

                sb.append("Timestamp: ");

                sb.append(myDiagnosticInfoEntry.getDiagnosticTimestamp().toString());

                sb.append(" ");

                sb.append("ID: ");

                sb.append(String.valueOf(myDiagnosticInfoEntry.getDiagnosticID()));

                sb.append(" ");

                sb.append("Message: ");

                sb.append(myDiagnosticInfoEntry.getDiagnosticText());

                sb.append(System.getProperty("line.separator"));

            }

            JOptionPane.showMessageDialog(null, "OK", "", JOptionPane.INFORMATION_MESSAGE);

        } else {

            JOptionPane.showMessageDialog(null, res.Message(), "", JOptionPane.ERROR_MESSAGE);

        }

    }

}


12. Send password

import PLCCom.*;

import javax.swing.JOptionPane;

 

public class NewClass {

 

    PLCcomDevice Device;

    //see section 'connect' for declare and connect a PLCcom-Device

 

        private void btnsendPWActionPerformed(java.awt.event.ActionEvent evt) {

 

        OperationResult res = Device.sendPassWord("EnterPW");

        //evaluate results

        if (res.Quality().equals(OperationResult.eQuality.GOOD)) {

            JOptionPane.showMessageDialog(null, "OK", "", JOptionPane.INFORMATION_MESSAGE);

        } else {

            JOptionPane.showMessageDialog(null, res.Message(), "", JOptionPane.ERROR_MESSAGE);

        }

    }

}


Reference : https://www.plccom.net/en/plccom/for-s7/fors7-code-examples/

Memunculkan Simbol & Emoji Pada OS Mac

  Memunculkan Simbol & Emoji  1. Buka aplikasi Pages / Notes pada Macbook. 2. Klik pada Menubar Edit --> Pilih Emoji and Symbols a...