Reading custom data types from a OPC UA Server using EasyUaClnt

Hi, I’m a bit new to the usage of OPC UA to communicate with other devices, I’m trying to communicate a X20CP1684 PLC to a Keyence IV4 camera using OPC UA, in this case the camera is the OPC UA Server.

Currently I’m able to read primitive data types and execute methods using EasyUaClnt but the data I’m interested in is inside a custom data type, for testing I’m trying to read a more simple data type MachineInformation I’ve created a Structured Type inside Automation Studio with specifications given by Keyence.

But the actual information I want is inside a nested custom data type but before I try reading that I’m trying to read a more simple data type, somewhere I’ve read that I need a .nodeset file but I don’t know how to get it.

The Keyence camera exposes the types inside a folder called Types in its OPC UA server

Information, PLC X20CP1684 AS 6.5.3.11, Server is a Keyence IV4

image

easy_read.ServerEndpointUrl := 'opc.tcp://192.168.0.216:4840';
//easy_read.NamespaceUri := 'nsu=urn:KEYENCE:VisionSensor:IV4:OPCUaServer;i=16002:MachineInformation';
easy_read.NodeID.Identifier := '16002';
easy_read.NodeID.NamespaceIndex := 2;
//easy_read.NodeID.IdentifierType := UAIT_Numeric; // I've tried with Numeric, String, GUID and Opaque and didn't worked 
easy_read.Execute := exec_or;
easy_read.Variable := '::Program:machine_var';
easy_read();
machine_var; //this variable is of type MachineInformation

Hi @Jose_Veliz ,
Have you tried first to connect Keyence camera with OPC UA client freeware tool UaExpert?

I never used Keyence because we have our vision system but you can found these steps:
To connect a Keyence IV4 vision sensor to Unified Automation’s UaExpert, you must enable the built-in OPC UA server function on the IV4 via Keyence software and then target its unique endpoint URL from UaExpert.


Step 1: Configure the Keyence IV4 Sensor

Before using UaExpert, you must enable the OPC UA server and assign an IP address to the sensor.

  1. Open Keyence IV Smart Navigator software.

  2. Click Sensor Setup and connect to your IV4 sensor.

  3. Go to Sensor AdvancedUtility tab.

  4. Select FieldNet/Comm. Unit (DL) or Network Settings (depending on your firmware version).

  5. Locate the communication protocol options and change the selection to OPC UA.

  6. Set a Static IP address for the IV4 and note it down. Disable DHCP to ensure the IP does not change.

  7. Take note of the Port Number designated for OPC UA (the default is usually 4840).

  8. Click OK to transfer the settings. The IV4 sensor will automatically restart to apply the configuration.


Step 2: Establish the Connection in UaExpert

  1. Open the UaExpert client on your computer.

  2. Right-click on the Servers folder in the Project view panel and click Add….

  3. Expand the Advanced tab in the pop-up window.

  4. In the Endpoint URL field, type the address utilizing this syntax:
    opc.tcp://<IV4_IP_Address>:<Port>
    (Example: opc.tcp://192.168.0.10:4840)

  5. Choose your preferred Security Policy (start with None or Sign & Encrypt based on your company’s network security requirements).

  6. Click OK to register the server.

  7. Right-click the newly added Keyence server in your list and select Connect.


Step 3: Browse and Monitor IV4 Data Tags

  • Locate Variables: Once connected, expand the IV4 server tree inside the Address Space window. Navigate down into the objects folder to locate the sensor’s live data fields.

  • View Results: Drag and drop live items (like Tool_1_Matching_Rate, total OK/NG counts, or trigger bits) directly into the Data Access View window to watch the data update in real time.

    ======================
    As second step theoretically you can communicate with your camera without a line a code, Third-party systems

    Ciao
    Valerio

Hi, thank you for your answer sorry not clarifying this but I’ve already used UaExpert I used it for most of the development to get the NodeId and the structure the problem is that the variables I want to read from the Keyence camera doesn’t have individual NodeId and as far as I know OpcUa_any doesn’t support custom data types.

This is the structure, the data I want is OKCount, NGCount, etc. those variables don’t have individual NodeId but those variables are part of the ResultStandard data type which is part of the OperationResult data type and I only have NodeId for OperationResult

Hi @Jose_Veliz ,
I opened one prj where one of our customer is using OpcUa_any and below you see how He has configured the channels:

For the Identification He didn’t select the Default setting “NodeId” but “BrowsePath”, more details in the Help: Relative path names.
In your case I think you can configure 13 Channels with basic data type:
BOOL/USINT/SINT/UINT/INT/UDINT/DINT/REAL

Ciao
Valerio

Those numbers you see on the left side of each variable are the NamespaceIndex (ns) and as I said I don’t have those for the variables I want to read. I could try using the same ns I have for OperationResult but I don’t think that’s how it works

ok @Jose_Veliz ,
I made a search on Internet:

In AS we have the possibility to import that file (Imported models):
Importing an OPC UA NodeSet file

This is an idea, I didn’t use that in the past but we have all well documented steps in the help.

somewhere I’ve read that I need a .nodeset file but I don’t know how to get it.

Download that file from Keyence website, if you don’t see that call their support.
Ciao
Valerio

I have new information, I got the Machine Information variable to connect to the server and get the data, the thing is that I didn’t do anything different just turned on my pc try it and it worked even without the uanodeset file, so I made the data type in AS for the Operation Result (nested complex data type variable) information as specified in the manufacturer’s pdf but this variable doesn’t communicate with the server. I even modified the variable that worked (Machine Information) to see if it still works even if the data type doesn’t match the specification and it works the data is not correct but I get something, but with the Operation Result data I don’t get anything not even wrong data, so I don’t know exactly what’s happening.

Does anyone who has done something similar what is the correct way to do it maybe I’m missing a step, thanks

Machine Information variable

Hi @Jose_Veliz I see there is no response for while, what is status of your topic now?

Hi, sorry for responding late.

Basically my question was, what’s the way to communicate with a custom OPC UA, specifically I asked if creating a Data Type in Automation Studio was the only thing I had to do. The basic answer is yes for anyone who wants to do that, that’s it create a Data Type that matches the Data Type on the OPC UA server it will work, in my case I followed the Camera’s PDF specification and it didn’t work, but after modifying the Data Type in AS it is half working at least I can get the data I want still I haven’t had enough time to figured out where exactly is the mismatch but that’s the answer.