Mapping Codesys with Sensor through Ethernet I/P

Hi all,
I am new to Ethernet I/P communication protocol. I have found the address of the sensor that I want to read inside the datasheet. The problem is, where do I put these address that I have found inside the Codesys in order to read the value of the sensor? I want to read value Out3 and Out6.

Where should i put the address for Out3 and Out6 inside the Codesys?

Best regards,

Hi umairyamin,

If the sensor OUT3 and OUT6 signals are Digital Inputs these should correlate to Input Bit2 and Bit5.

Below are the steps to map these values:

I prefer to create Global Variables for easy access across different programs/applications within Codesys.

Step 1: Define Global Variables: BOOL for Digital I/O

Step 2: Map the Global Variable

Step 3: Access Global Variable Ethernet/IP Input within a Program

Hope this helps!

Attached is the demo project.
umairyamin_demo.project (356.2 KB)

Jacob Ball

1 Like

Hi Jacob,

wow. I really appreciate your effort to help me. Thanks a lot! I will try. Hope it works.

Best regards,

Hi Jacob,

the sensor is a thickness measurement sensor. The data should be analog input. But after i uploaded the EDS file, the datatype is automatically is in BOOLEAN. This is the EDS file provided by the supplier. Is there any step i can do to read the thickness?

Best regards,

I have tried the method that you showed me. Its just, I do not know where I can read the sensor’s value.

Often times EDS files provide multiple connections. According to your screenshot of the output values bytes are paired r at o your sensor value will be read as an integer. The screenshot of the variable napping you shared only consist of one byte.
Can you confirm that your EDS connection is correct for your device so you can monitor the needed values?

1 Like

Hi Barron,

yes. I have made mistakes. The sensor need 4 Bytes to read 1 value.

I have asked new question regarding how to read these 4 bytes code. Still troubleshooting on how to read it.

Thanks for your concern!

Best regards,

The user made data type “Union” is excellent for this just as Michael had explained. You’ll right click on Application, add object, and select DUT.

Then you can create a variable for an array of four bytes and a variable for real within the DUT.

In your plc code you will then create a variable of the user made data type.

In your ethernetIP mapping, map this variable in its byte format sequentially:
Byte[0], byte[1], byte[2], and byte[3].

In your plc code, you can use the “real” portion of the union data type.

I followed exactly as he showed to me, and this is the result that I received. The value of the sensor should be at myValue.rOutputData right? I dont think I am getting the value that it supposed to be.

You may need to byte swap. Try reordering the array. [1], [0], [3], [2]

Like this?

Hi Umair,

Can you please share the screenshot of the sensor data sheet where it states it has 4byte (32bit) resolution?

Thank you,