Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Connecting a Keyence Scanner via EtherNet/IP with CoDeSys PLC-App

Connecting a Keyence Scanner via EtherNet/IP with CoDeSys PLC-App

HaRo
Established Member

Hey all together,
our CoDeSys knowledge is very little - we're still learning. Maybe someone can give us a hint how it could work:

We're trying to connect a Keyence SR-X100 Scanner via Ethernet/IP with PLC-App. We're able to trigger the scanner and we recieve data from Scanner.
There's a code with 20 characters which is read. The scanner reads all the data and in datafield "Result Data Size" it shows the value "20". So we'll recieve 20 Byte of data (thats correct).

Now I like to watch the "Result Data". I'm able to see the first sign. Input %IB60 says "57". It's ASCII coded and it is the value "9" (thats also correct).
But how can I watch the following 19 characters? I can't find a opportunity for mapping the other inputs... I think there's a little setting which has to be changed..?

Thanks a lot!
-HaRo

Code:
HaRo_2-1663681907385.png

 

Assemblys:
HaRo_1-1663681873130.png

EtherNet/IP E/A-Abbild:
HaRo_0-1663681815491.png

 

5 REPLIES 5

bostroemc
Occasional Contributor

If the result data is expected to be a string, try defining a UNION type:

TYPE STRING_UNION_TYPE :
UNION
	_result: STRING(20);
	_byte: ARRAY[0..19] OF BYTE;
END_UNION
END_TYPE

 

and pointing an instance of it at the location of the result data:

ResultData AT %IB60: STRING_UNION_TYPE;

 

The result is then accessible as a string at ResultData._result:

Untitled.png 

Adjust the string length and the size of the byte array in the UNION as required, but be sure to not exceed the size of the total E/IP mapping (T->O).  Also, remember that the string in the UNION must be null terminated.

If this doesn't work, please share your code and the EDS file for the device you are using.

HaRo
Established Member

Hello @bostroemc, thanks for your reply!

Today I had the chance testing your suggestion.
Sadly I still recieve only one character. Here you can see the expected data:

HaRo_1-1665139466875.png

Hex-code 49 is the first sign ("1"):

HaRo_2-1665139516956.png

Attached you'll find the EDS-file which I'm using (please remove ".txt" at the end of file-name).

Here's the part of the code - the VAR "trigger" is forced manually.

HaRo_5-1665140258995.png

HaRo_6-1665140356656.png

 

regards,
HaRo

 

bostroemc
Occasional Contributor

It looks to me like the Keyence EDS file is not reserving memory necessary for mapping the ResultData string.

Can you try the following?

Under the assembly configuration, delete the Result Data entry:

Unbenannt_1.png

Next, add a new Result Data entry, this time with Bit length = 8, Count = 128 as shown below:

Unbenannt_2.png

The I/O mapping should then look as follows:

Unbenannt_3.png

I do not have a Keyence scanner and have not tested this configuration.  I have reached out to my local Keyence representative to try to get a loaner for testing, but do not yet have confirmation.  I will pursue this further with them if this recommendation is unsuccessful.

HaRo
Established Member

Thanks! That's the solution!

I'm able to receive data:

HaRo_0-1665728740514.png

 

bostroemc
Occasional Contributor

Great, thanks for the feedback.

Since the ResultData block has a fixed size of 128 bytes, it might make sense to increase the size of STRING_UNION_TYPE accordingly:

TYPE STRING_UNION_TYPE :
UNION
	_result: STRING(127);
	_byte: ARRAY[0..127] OF BYTE;
END_UNION
END_TYPE

Note that STRING(127) defines a 127-character string, but CODESYS reserves an extra byte automatically for the null termination.  See here for an explanation.  I forgot this when making my original recommendation for STRING_UNION_TYPE.

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist