I have a UDINT value whitch represents PNIO_Status and i would like to convert it to 4 bytes so i can decode it by this website: https://content.helpme-codesys.com/en/CODESYS%20PROFINET/_pnio_diagnosis_pnio_state.html How can i convert the UDINT value to 4 BYTES so it would corespond to the page I have provided earlier ?
use UDINT_TO_DWORD and then use Library "SysMem.SysMemCopy" to copy your DWORD onto your Array of Bytes.
could you provide a screenshot solution of the block call ? i seem to get exceptions about access violation when running the program
Here you go
You could also create a DUT of the Type Union. In the Union add an array of 4 bytes and a UDINT.
Then create a variable of this type. Write to the UDINT of this union variable and read the array of bytes.
See https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_datatype_union.html
I have tried this approach, but it seems to be inconsistent. Here is the code i have come with:
TYPE uDINTBytes : UNION rValue: UDINT; abValue: ARRAY [0..3] OF BYTE; END_UNION END_TYPE
But here is the output whitch is wrong.
2172731138 = hex 81 81 3F 02 hex 02 = dec 2 hex 3F = dec 63 hex 81 = dec 129
So this seems okay to me.
nevermind, I did something wrong in the conversion, my bad. Thanks!
Log in to post a comment.
I have a UDINT value whitch represents PNIO_Status and i would like to convert it to 4 bytes so i can decode it by this website: https://content.helpme-codesys.com/en/CODESYS%20PROFINET/_pnio_diagnosis_pnio_state.html
How can i convert the UDINT value to 4 BYTES so it would corespond to the page I have provided earlier ?
use UDINT_TO_DWORD and then use Library "SysMem.SysMemCopy" to copy your DWORD onto your Array of Bytes.
could you provide a screenshot solution of the block call ? i seem to get exceptions about access violation when running the program
Here you go
Last edit: sedoerr 2023-03-06
You could also create a DUT of the Type Union.
In the Union add an array of 4 bytes and a UDINT.
Then create a variable of this type.
Write to the UDINT of this union variable and read the array of bytes.
See https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_datatype_union.html
I have tried this approach, but it seems to be inconsistent. Here is the code i have come with:
But here is the output whitch is wrong.
2172731138 = hex 81 81 3F 02
hex 02 = dec 2
hex 3F = dec 63
hex 81 = dec 129
So this seems okay to me.
nevermind, I did something wrong in the conversion, my bad. Thanks!