andrei.apopei

Omron NJ501 - IFM IO-Link - Wenglor U1KT001

9 posts in this topic

Hi,

I am looking at reading an ultrasonic sensor value through IO-Link, using a Omron NJ501-1320 PLC connected through EtherCat to a IFM AL1332 master with a Wenglor U1KT001 Ultrasonic sensor.

I have managed to read the 2 outputs of the sensor using this:

Output_1 := TestABit(USINT_TO_BYTE(TxPDO_input_byte_1_6000_02),USINT#0);

Output_2 := TestABit(USINT_TO_BYTE(TxPDO_input_byte_1_6000_02),USINT#1);

But cannot read the ultrasonic sensor distance value, this is what page 2 in the manual says:

Measured Value in 1/10 mm 2…15 14 Bit 300…4500

Octet 1 Subindex 3 (LSB) 2 1 Bit Offset 7 6 5 4 3 2 1 0

I tried a couple of conversions but couldn`t get the distance reading.

Any ideas?

dgzk63T

9YdQX1f

Dfw9QLM

Help appreciated.

Edited by andrei.apopei

Share this post


Link to post
Share on other sites

Have you tried moving the 2 bytes into a Word data type then shifting the bits 2 places to the right with a SHR ?

Edited by chelton
Wrong direction

Share this post


Link to post
Share on other sites

Not sure I understand, the measured distance is 14 Bit, do you mean move them into a bit array?

I have tried moving them into a bit array and then using AryByteTo  into a Real number but it doesn`t really work because I can`t choose the array offset.

TempByteArray[2] := USINT_TO_BYTE( TxPDO_input_byte_1_6000_02);
TempByteArray[3] := USINT_TO_BYTE( TxPDO_input_byte_1_6000_02);
TempByteArray[0] := USINT_TO_BYTE( TxPDO_input_byte_1_6000_02);
TempByteArray[1] := USINT_TO_BYTE( TxPDO_input_byte_1_6000_02);
AryByteTo(In:=TempByteArray2[0], Size:=4, Order:=_HIGH_LOW, OutVal:=Ultrasonic_Measurement);

Share this post


Link to post
Share on other sites

Create a temp "WORD" variable

use AryByteTo to move the 2 bytes into your WORD variable.

shift the word bits to the right x 2 bits.

 

AryByteTo(byte_Array[4],UINT#2,_LOW_HIGH,tempword);
distance:= to_uint(SHR(tempword,UINT#2));

 

Share this post


Link to post
Share on other sites

Since your bytes aren't in an array you will use the packword function....

tempword := packword(TxPDO_input_byte_1_6000_02,TxPDO_input_byte_1_6000_03);
distance:= to_uint(SHR(tempword,UINT#2));

 

Share this post


Link to post
Share on other sites

Hi Chelton and thanks for replying.

I gave it a try with the second one and with a couple of mods I get the output in the picture, it is about half of the real measurement.

 

 

Share this post


Link to post
Share on other sites

Hi Andrei, Are you sure your not supposed to be using Tx_PDO_InputByte 0 & 1? Your link is showing input byte 1&2

Byte 1 will contain the digital status like you have shown, but I think the MSB byte should be byte 0

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now