How to access a Codesys pointer via OPC UA

jagjag1

Member
Join Date
Jan 2012
Location
Codesys
Posts
17
I am trying to access the value of a pointer via OPC UA in Codesys. I can share it directly and in a struct but I cant access the value of it when its linked. I have tried to access it via UaExpert and python script but I cant go down the last level.

Trying to access this:
GVL.astItem[1].pIntPointer^

NodeID:
ns=4;s=|var|CODESYS Control Win V3 x64.Application.GVL.astItem[1].pIntPointer
 
Why not assign the value of the dereferenced pointer to another global variable and refer to that via OPC?
 
I think L D[AR2,P#0.0]'s suggestion is not only correct, but it is the only thing you can do to get such value from the CODESYS OPCUA server to your OPCUA client.
Your inquiry sparked my curiosity and tried to setup something to see if it was possible. But now I understand why and I may not be able to give you a proper explanation due to both English not being my first language and by virtue of not being an OPCUA developer, but rather I can give an explanation in a more colloquial way. OPCUA technology's purpose is to hide from the client low-level addressing issues in the server. Only process data can be exposed in the OPCUA address space. As you can see in the screenshot below, the OPCUA server is indicating that the data for the pointer is unavailable. Thus, as L D[AR2,P#0.0] says, you need to have in the CODESYS program a variable and assign to it the value in the pointer,

2023-03-30_CODESYS_OPCUA_Server.jpg
 
Thank you for the response I found a different way to to it but resulting to more or less the same function and I will share it if anyone will need it in the future.

I tried reading the pointer to various variables with UaExpert, Python and C#(opc.UaFx.Client) in all platforms i could see the variable but when trying to read the value all resulting in bad/invalid data because the opc ua client could not process the pointer. So instead I used REFRENCE TO and all the OPC ua platforms instantly found the variable since the reference does not add an new level to the variable, array or struct.

Simplified example:
VAR_GLOBAL
aiItem : ARRAY [0..50] OF INT;
refiTemp : REFERENCE TO INT;
iPointer : INT;
END_VAR

GVL.refiTemp REF=GVL.aiItem[GVL.iPointer];

Hope this helps someone.
 
jagjag1, this solution is so very interesting. Thanks for sharing this.

You have helped me remind myself that even though I "think" I know CODESYS, in fact I have so much to learn.
https://help.codesys.com/api-content/2/codesys/3.5.13.0/en/_cds_ref_assignment/
Did not know about the "Assignment operator ‘REF’"
And it works...
P.S. for a person like me it is easier to understand the issue with a little bit more detail.

2023-03-30_CODESYS_OPCUA_Server1.jpg
 
I like to tack {attribute 'no_assign'} on all FBs I want to REFERENCE TO them. Someone always uses := instead of REF= and this attribute fixes that.

Good find for solving the pointer/opcua problem!
 

Similar Topics

Hi there, We have a German machine with an Eaton XC-202 plc. I purchased the X-soft CoDeSys software and XT-SUB-D/RJ45 cable for programming...
Replies
3
Views
4,051
I have to provide remote access and control to a touch screen. I was thinking about using Weintek and the Weincloud. Does anyone know if this is...
Replies
11
Views
588
Greetings, I am working on a project and I would like to scale %AI to -10.0 to 10.0 VDC. The module Input data is stored as a 16 bit Integer and...
Replies
4
Views
65
Hi all Trying to remotely connect to a TIA Portal PLC. I can ping it without a problem but can't get my software to connect. I've opened port...
Replies
8
Views
314
Hi All, Can anyone advise me on how to determine the AN of a genie instance I writing to. I have created a genie to display a valve and some text...
Replies
0
Views
87
Back
Top Bottom