วันอาทิตย์ที่ 28 มกราคม พ.ศ. 2561

Tools -> Parameter VM Mapping (0BA7 and later versions only)

VM overview

LOGO! Base Module uses VM (Variable Memory) as a local data communication interface for data exchange by means of connections/data-transfer configuration.
You can use LOGO!Soft Comfort with the Ethernet connections menu command following instructions in the Tools -> Ethernet Connections (0BA7 and later versions only) section to construct the network topology.
LOGO!Soft Comofort performs data exchange process as follows:
  • The server stores the required data into the VM area specified by the data connection and data transfer. This is defined as a "share" action in the following section.
  • The client unit reads the server's VM area and then updates the corresponding local VM area in its network process step.
  • After the local update, the circuit program in the client can use the information in the local VM originated from the Server.               
Note LOGO! 8.FS4 supports two types of connection, S7 and Modbus. LOGO! 0BA7 and LOGO! 0BA8 only supports S7 connection.





วันพุธที่ 24 มกราคม พ.ศ. 2561

moka7 example read/write logo 8




****************  Read  ************************


package com.amjoey.moka7connectlogoplc;

import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import moka7.*;

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override    protected void onResume() {
        super.onResume();
        // we're going to simulate real time with thread that append data to the graph        new Thread(new Runnable() {

            @Override            public void run() {
                // we add 100 new entries                for (int i = 0; i < 100; i++) {
                    runOnUiThread(new Runnable() {

                        @Override                        public void run() {
                            new PlcReader().execute("");
                        }
                    });

                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
            }
        }).start();
    }

    S7Client client = new S7Client();

    public void readdb_val(View v){
        new PlcReader().execute("");
    }


    private class PlcReader extends AsyncTask<String, Void, String>{

        String ret = "";

        @Override        protected String doInBackground(String... params){

            try{
                client.SetConnectionType(S7.S7_BASIC);
                int res=client.ConnectTo("192.168.0.3",0,0);

                if(res==0){//connection OK
                    byte[] data = new byte[4];
                    res = client.ReadArea(S7.S7AreaDB,1,10,4,data);
                  //  ret = "value of DB1.DBD25: "+ S7.GetFloatAt(data,0);                  //  ret = "value of DB1.DBD10: "+ S7.GetWordAt(data,0);                    ret = "Value of DB1.DBD10: "+ S7.GetWordAt(data,0)+"/"+ S7.GetWordAt(data,2);
 /*                    byte[] dataWrite = new byte[2];                   // S7.SetBitAt(dataWrite, 0, 1, true);                   // S7.SetDIntAt(dataWrite,0,5);                    S7.SetWordAt(dataWrite,0,700);
                    client.WriteArea(S7.S7AreaDB, 1, 12, 2, dataWrite);                    ret = "WriteArea of DB1.DBD12: OK ";                    */

                }else{
                    ret = "ERR: "+ S7Client.ErrorText(res);
                }
                client.Disconnect();
            }catch (Exception e) {
                ret = "EXC: "+e.toString();
                Thread.interrupted();
            }
            return "executed";
        }

        @Override        protected void onPostExecute(String result){
            TextView txout = (TextView) findViewById(R.id.textView);
            txout.setText(ret);
        }
    }
}





****************  Write  ************************

package com.amjoey.mokawriteplc;

import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import Moka7.*;


public class MainActivity extends AppCompatActivity {

    int iMemoryAdd;
    int bMemoryVal;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }

    S7Client client = new S7Client();

    public void readdb_val(View v){
        EditText mwAdd = (EditText) findViewById(R.id.txtMWAddress);
        EditText mwVal = (EditText) findViewById(R.id.txtValue);

        if (!mwAdd.getText().toString().equals("")){
            iMemoryAdd = Integer.parseInt(mwAdd.getText().toString());
        }else{
            iMemoryAdd = 0;
        }

        if (!mwVal.getText().toString().equals("")){
            bMemoryVal = Integer.parseInt(mwVal.getText().toString());
        }else{
            bMemoryVal = 0;
        }


        new PlcReader().execute("");
    }

    private class PlcReader extends AsyncTask<String, Void, String>{

        String ret = "";



        @Override        protected String doInBackground(String... params){


            try{
                client.SetConnectionType(S7.S7_BASIC);
                int res=client.ConnectTo("192.168.0.3",0,0);

                if(res==0){//connection OK                     /*                    byte[] data = new byte[4];                    res = client.ReadArea(S7.S7AreaDB,1,10,2,data);                  //  ret = "value of DB1.DBD25: "+ S7.GetFloatAt(data,0);                    ret = "value of DB1.DBD10: "+ S7.GetWordAt(data,0);                    */
                    byte[] dataWrite = new byte[2];
                    // S7.SetBitAt(dataWrite, 0, 1, true);                    // S7.SetDIntAt(dataWrite,0,5);                    S7.SetWordAt(dataWrite,0,bMemoryVal);

                    client.WriteArea(S7.S7AreaDB, 1, iMemoryAdd, 2, dataWrite);
                    ret = "WriteArea of DB1.DBD" + iMemoryAdd + " : "+bMemoryVal;


                }else{
                    ret = "ERR: "+ S7Client.ErrorText(res);
                }
                client.Disconnect();
            }catch (Exception e) {
                ret = "EXC: "+e.toString();
                Thread.interrupted();
            }
            return "executed";
        }

        @Override        protected void onPostExecute(String result){


            TextView txout = (TextView) findViewById(R.id.textView);
            txout.setText(ret);
        }
    }

}

วันอาทิตย์ที่ 14 มกราคม พ.ศ. 2561