FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
09-20-2022 03:54 PM
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:
Assemblys:
EtherNet/IP E/A-Abbild:
Solved! Go to Solution.
09-28-2022 12:47 AM
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:
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.
10-07-2022 12:59 PM
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:
Hex-code 49 is the first sign ("1"):
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.
regards,
HaRo
10-10-2022 05:14 PM
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:
Next, add a new Result Data entry, this time with Bit length = 8, Count = 128 as shown below:
The I/O mapping should then look as follows:
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.
10-14-2022 08:26 AM
Thanks! That's the solution!
I'm able to receive data:
10-14-2022 12:19 PM
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.