Matlab

This is not possible right now

Install Python

The Matlab client accesses the values on the OPC UA Server over python. Therefore you have to install python.

Download the Zip

The zip file should include the necessary python file. Download it and unpack it into your folder struct.

Install necessary libaries

Press the “Windows key” and Enter “CMD” to open the terminal and type in the the folder here you saved your scripts. In my case it’s.

cd C:\Users\knr\AppData\Local\Programs\Python\Python37\Scripts
pip install pandas
pip install cryptography
pip install https://github.com/FreeOpcUa/python-opcua/archive/master.zip#egg=opcua

Tipp: You find out he destination of your Python via entering “pyversion” into the Matlab Commando Window and at “\Scripts”

>>> pyversion

       version: '3.7'
    executable: 'C:\Users\knr\AppData\Local\Programs\Python\Python37\python.exe'
       library: 'C:\Users\knr\AppData\Local\Programs\Python\Python37\python37.dll'
          home: 'C:\Users\knr\AppData\Local\Programs\Python\Python37'
      isloaded: 0

Perfect, you installed the necessary libraries

Check credentials & nodes

Check the credentials and the nodes

% Initializer opc ua client
    opcua = py.opcuaclient_subscription.opcua();
    opcua.client.set_user('Aurelio');
    opcua.client.set_password('password');

% Define Read-Variables
    % Its important to use single quotation marks (') and not quotation marks
    % not (")
    struct_Read = struct('node',struct( 'x0','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.bAnlageEin'...
                                        ,'x1','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.bQuittierung'...
                                        ,'x2','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.bReqResearch'...
                                        ,'x3','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.bWdResearch'...
                                        ,'x4','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strRead.strEnergiemessung.strELM01_P801.rSumWirkleistung'...
                                        ,'x5','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.rSollWirkleistung'));


    if opcua.connect()
        opcua.subscribe(jsonencode(struct_Read)); 
    end

    while true
        % Define write struct
        struct_Write = struct(  'node',     struct( 'x0','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.bAnlageEin'...
                                                    ,'x1','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.bQuittierung'...
                                                    ,'x2','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.bReqResearch'...
                                                    ,'x3','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.bWdResearch'...
                                                    ,'x4','ns=2;s=Gateway.PLC1.65LK-06420-D001.PLC1.Batan.strWrite_L.strBatterienanlage.rSollWirkleistung')...
                                ,'value',   struct(   'x0','True'...
                                                     ,'x1','False'...
                                                     ,'x2','True'...
                                                     ,'x3',py.opcuaclient_subscription.toggle()....
                                                     ,'x4','2'));

        opcua.publish(jsonencode(struct_Write));
        % Read the feedback value
            test_Read = jsondecode(char(opcua.handler.json_Read));
            disp(test_Read.value)
            pause(0.1);
    end
    opcua.disconnect();