API Åë½Å ¶óÀ̺귯¸® (comm Library)¸¦ »ç¿ëÇÑ
¾ÖÇø´ ¿¹

sampleApplet1.gif (1876 bytes)

ÀϹÝÀûÀ¸·Î À¥ ºê¶ó¿ìÀú¿¡¼­ ½ÇÇà½Ãų ¼ö ÀÖ´Â PLC Á¦¾î GUI ¾ÖÇø´À» ÀÚ¹Ù API ¶óÀ̺귯¸®¸¦ ÀÌ¿ëÇÏ¿© ¸¸µç´Ù´Â °ÍÀº °áÄÚ ½¬¿î ÀÏÀÌ ¾Æ´Õ´Ï´Ù. ÇÏÁö¸¸ ÁÂÃø ±×¸²¿¡ ÀÖ´Â ¿¹Á¦ ¾ÖÇø´Àº ¿ì¸®ÀÇ API¸¦ »ç¿ëÇÏ¿© ¸Å¿ì ½±°Ô ¸¸µé ¼ö°¡ ÀÖ½À´Ï´Ù. ÀÌ ¾ÖÇø´Àº ¿ø°Ý PLC·ÎºÎÅÍ ¸®¾óŸÀÓŬ·° µ¥ÀÌÅÍ ¹× ÀÔ·Â #1°ú Ãâ·Â #1ÀÇ ·ÎÁ÷ »óŸ¦ ¿ø°Ý ¼ö½ÅÇÏ¿© °è¼ÓÀûÀ¸·Î µð½ºÇ÷¹ÀÌÇÏ´Â °ÍÀÔ´Ï´Ù. "Input #1"ÀÇ ¶óº§Àº ÃÊ·Ï »öÀÇ ¹à±â Â÷À̸¦ ÀÌ¿ëÇÏ¿© PLCÀÇ ÀÔ·Â #1 (Input #1)ÀÇ ON/OFF»óŸ¦ Ç¥½ÃÇÕ´Ï´Ù. "Output #1" ¶óº§À» Ŭ¸¯ÇÒ ¶§ PLCÀÇ Ãâ·Â #1À» °­Á¦·Î Åä±Û½ÃÅ°´Â Ǫ½¬¹öÆ°ÀÔ´Ï´Ù. Ãâ·Â #1 (Output #1)ÀÇ »óÅ´ Àû»ö ¹öÆ°ÀÇ ¹à±â Â÷ÀÌ¿¡ ÀÇÇØ ±× »óŸ¦ Ç¥½ÃÇÕ´Ï´Ù.

ÀÌ ¿¹Á¦ ¾ÖÇø´ÀÇ ¿ÏÀüÇÑ ¼Ò½º ÄÚµå ¸®½ºÆ®¸¦ ÀÌ°÷ ¾Æ·¡¿¡ ¿Ã·Á ³õ¾Ò½À´Ï´Ù. ¾Æ·¡ ¸¹Àº ÇÁ·Î±×·¥ ¹®Àåµé Áß¿¡¼­ ±½Àº ÆĶõ»öÀÇ ¹®ÀÚµé ¸¸ÀÌ ½ÇÁ¦·Î API ¶óÀ̺귯¸®ÇÏ°í °ü°èµÈ °ÍÀÔ´Ï´Ù. ³ª¸ÓÁö ºÎºÐÀº ´ëºÎºÐÀÇ ÀÚ¹Ù ÇÁ·Î±×·¥¸Óµé¿¡°Ô ÀÌ¹Ì Àͼ÷ÇØÀÖ´Â Æò¹üÇÑ ÀÚ¹Ù AWTÀÔ´Ï´Ù. PLC ÀÚ¹Ù Åë½Å ¶óÀ̺귯¸® "PLCmon.jar"¿¡ ´ëÇÏ¿© ´õ °øºÎ¸¦ ÇÏ°í ½ÍÀ¸½Å ºÐÀº ¿©±â¸¦ Ŭ¸¯ÇϽñ⠹ٶø´Ï´Ù.

¿©·¯ºÐÀº ¶ÇÇÑ ´Ù¸¥ Ç÷§Æû »ó¿¡¼­ ½ÇÇà ½Ãų ¼ö ÀÖ´Â ¿©·¯ºÐ ÀڽŸ¸ÀÇ ÀÚ¹Ù ¾îÇø®ÄÉÀÌ¼Ç ÇÁ·Î±×·¥À» ¸¸µé ¼ö ÀÖ½À´Ï´Ù. ¿ÞÂÊ »çÁøÀº Personal Java JVM (Sun »çÀÌÆ®¿¡¼­ ¹«·á·Î ´Ù¿î·Îµå ¹ÞÀ» ¼ö ÀÖÀ½)À» ¼³Ä¡ÇÑ HP Jornada Pocket PC»ó¿¡¼­ ¶È°°Àº ÀÚ¹Ù ÇÁ·Î±×·¥À¸·Î ½ÇÇàµÇ°í ÀÖ´Â °ÍÀ» º¸¿©ÁÖ°í ÀÖ½À´Ï´Ù. PLCÀÇ ÀÔ·Â #1 (Input #1) ¹× Ãâ·Â #1 (Output #1)ÀÇ ·ÎÁ÷ »óÅÂ, ±×¸®°í PLC ¸®¾óŸÀÓŬ·°ÀÇ ½Ã°£À» ¿ø°ÝÀ¸·Î ÀÐÀ» ¼ö ÀÖÀ¸¸ç Ãâ·Â #1 (Output #1) ¶óº§À» Ŭ¸¯Çϸé PLC Ãâ·Â #1À» °­Á¦·Î Åä±Û½Ãų ¼ö ÀÖ½À´Ï´Ù.

API Åë½Å ¶óÀ̺귯¸®´Â PC»ó¿¡¼­ ÀڽŸ¸ÀÇ ÀÚ¹Ù ÇÁ·Î±×·¥À» ½±°Ô ÀÛ¼ºÇÏ°í Å×½ºÆ®¸¦ Çغ¼ ¼ö ÀÖµµ·Ï ÇÏ¿© ÁÝ´Ï´Ù. ¶ÇÇÑ ÀÛ¼ºµÈ ÇÁ·Î±×·¥À» °£´ÜÇÏ°Ô ´Ù¸¥ Ç÷§Æû ¶Ç´Â PDA¿¡ ¼³Ä¡ÇÏ°í ½ÇÇà ½Ãų ¼ö ÀÖ½À´Ï´Ù. PDA »çÁøÀ» Ŭ¸¯ÇϽøé Å« PDA »çÁøÀ» º¸½Ç ¼ö ÀÖ½À´Ï´Ù.

import PLCmon.*;
import java.awt.*;
import java.applet.*;

public class TestApplet extends Applet
{
    String URLString = "127.0.0.1:9080"; // a localhost connection
    String username = "samples";
    String password = "";

    int [] DM = new int[4000]; // place holder for the Data Memory DM[1] to DM[4000]
    ConnectTLServer ctlsvr;
    Color darkGreen = new java.awt.Color(0,128,0);
    Color darkRed = new java.awt.Color(128,0,0);
    public void init()
    {
        //{{INIT_CONTROLS
        setLayout(null);
        setSize(120,120);
        panel1.setLayout(null);
        add(panel1);
        panel1.setBackground(new java.awt.Color(255,255,128));
        panel1.setBounds(0,0,120,120);
        RTC.setEditable(false);
        RTC.setText("Hello");
        panel1.add(RTC);
        RTC.setBackground(java.awt.Color.black);
        RTC.setForeground(java.awt.Color.red);
        RTC.setFont(new Font("Dialog", Font.BOLD, 16));
        RTC.setBounds(20,20,87,24);
        clockLabel.setText("PLC\'s Clock");
        clockLabel.setAlignment(java.awt.Label.CENTER);
        panel1.add(clockLabel);
        clockLabel.setBounds(20,0,84,24);
        output1Button.setLabel("Output1");
        panel1.add(output1Button);
        output1Button.setBackground(new java.awt.Color(128,0,0));
        output1Button.setForeground(java.awt.Color.yellow);
        output1Button.setFont(new Font("Dialog", Font.BOLD, 12));
        output1Button.setBounds(20,80,84,22);
        input1Label.setText("Input #1");
        input1Label.setAlignment(java.awt.Label.CENTER);
        panel1.add(input1Label);
        input1Label.setBackground(new java.awt.Color(0,128,0));
        input1Label.setForeground(java.awt.Color.yellow);
        input1Label.setFont(new Font("Dialog", Font.BOLD, 12));
        input1Label.setBounds(20,48,84,22);
        //}}
       
        ctlsvr = new ConnectTLServer(URLString, username, password);
        MonitorThread mt = new MonitorThread();
        mt.start();
   
        //{{REGISTER_LISTENERS
        SymMouse aSymMouse = new SymMouse();
        output1Button.addMouseListener(aSymMouse);
        //}}
    }
   
    //{{DECLARE_CONTROLS
    java.awt.Panel panel1 = new java.awt.Panel();
    java.awt.TextField RTC = new java.awt.TextField();
    java.awt.Label clockLabel = new java.awt.Label();
    java.awt.Button output1Button = new java.awt.Button();
    java.awt.Label input1Label = new java.awt.Label();
    //}}
   

    class MonitorThread extends Thread {
        private Action monAction[] = new Action[10]; // Don't make these monAction[] variable public
        public void run() { // to avoid writing action[] variables in other threds
            while (true) { // run forever (until program exits)
                readRTC(); // add the list of actions you wish to monitor here
                readIO();
                try {
                    Thread.sleep(200); // update every 0.2 second
                } catch (Exception e){}
            }
        }
   
        void readIO() { // Read the logic state of the inputs and outputs
            monAction[0] = new Action(1,ActionConstant.READSINGLE,ActionConstant.INPUT,1,0); // Read INPUT[1]
            monAction[1] = new Action(1,ActionConstant.READSINGLE,ActionConstant.OUTPUT,1,0); // Read OUTPUT[1]
            try {
                ctlsvr.commAction(monAction, 2); // Execute the two READ actions defined above
                if ((monAction[0].value & 0x0001)!=0) { // Test bit 0 of 16-bit variable INPUT[1]
                    input1Label.setBackground(Color.green); // it is ON, light up the label in GREEN
                }
                else {
                    input1Label.setBackground(darkGreen); // it is OFF, dim the label as dark green.
                }
                if ((monAction[1].value & 0x0001)!=0) { // Test bit 0 of 16-bit variable OUTPUT[1]
                    output1Button.setBackground(Color.red); // it is ON, light up the label in GREEN
                }
                else {
                    output1Button.setBackground(darkRed); // it is OFF, dim the label as dark green.
                }
            }
            catch (Exception e) {
                RTC.setText(e.toString()); // show the error message
                System.out.println(e);
            }
        }

        public void readRTC() { // Read the read time clock: Hours, Minutes and Seconds.
                            // the returned value for READSINGLE is contained in the integer variable "value".
            monAction[0] = new Action(1,ActionConstant.READSINGLE,ActionConstant.TIME ,1,0); // Read Hour
            monAction[1] = new Action(1,ActionConstant.READSINGLE,ActionConstant.TIME, 2,0); // Read Minute
            monAction[2] = new Action(1,ActionConstant.READSINGLE,ActionConstant.TIME, 3,0); // Read Second
   
            try {
                ctlsvr.commAction(monAction, 3); // Execute 3 actions defined above
                String RTCvalue = monAction[0].value +":"+ monAction[1].value+":"+ monAction[2].value;
                RTC.setText(RTCvalue);
            }
            catch (Exception e) {
                RTC.setText(e.toString()); // show the error message
                System.out.println(e);
            }
        }
    }

    class SymMouse extends java.awt.event.MouseAdapter
    {
        public void mouseReleased(java.awt.event.MouseEvent event)
        {
            Object object = event.getSource();
            if (object == output1Button)
                output1Button_MouseReleased(event);
        }

        public void mousePressed(java.awt.event.MouseEvent event)
        {
            Object object = event.getSource();
            if (object == output1Button)
                output1Button_MousePressed(event);
        }
    }
   

    void output1Button_MousePressed(java.awt.event.MouseEvent event) {
        Action writeAction[] = new Action[10];
            // to do: code goes here.
        writeAction[0] = new Action(1,ActionConstant.READSINGLE,ActionConstant.OUTPUT ,1,0); // Read OUTPUT[1]
        try {
            ctlsvr.commAction(writeAction, 1); // Execute 1 action defined above
            writeAction[0].actionType = ActionConstant.WRITESINGLE; // change to WRITESINGLE OUTPUT
            writeAction[0].value ^= 0x0001; // Toggle OUTPUT[1] bit 0
            ctlsvr.commAction(writeAction, 1); // Execute the action;
        }
        catch (Exception e) {
            RTC.setText(e.toString()); // show the error message
            System.out.println(e);
        }
    }

    void output1Button_MouseReleased(java.awt.event.MouseEvent event)
    {
        // to do: code goes here.
    }
}

¼­¿ïƯº°½Ã ¿µµîÆ÷±¸ ¿©Àǵµµ¿ 44-35 (Á¦ÀϺôµù 806È£)
TEL:
(02) 872-7447 FAX:(02) 761-6774